「[[マイクロソフト系技術情報 Wiki>http://techinfoofmicrosofttech.osscons.jp/]]」は、「[[Open棟梁Project>https://github.com/OpenTouryoProject/]]」,「[[OSSコンソーシアム .NET開発基盤部会>https://www.osscons.jp/dotNetDevelopmentInfrastructure/]]」によって運営されています。

-戻る
--[[Windows Subsystem for Linux]]
--[[.NET Coreの開発]]
--[[ASP.NET Coreの開発]]

* 目次 [#rdb7338f]
#contents

*概要 [#ua00ab1b]
-Windows Subsystem for Linux (WSL)を使用した、[[.NET Core]], [[ASP.NET Core]]開発が可能。
-[[WSL>Windows Subsystem for Linux]]を使用した、[[.NET Core]], [[ASP.NET Core]]開発が可能。

-手軽に動作確認を行うなどの用途では、WSLは非常に便利だと思う。

-ただし、所詮、エミュレーションなので、実機確認を行う場合は、[[Docker>https://dotnetdevelopmentinfrastructure.osscons.jp/index.php?Docker]]などを使用すべきと考える。

**[[.NET Coreの開発]] [#d6efbd4a]
-WSLをインストールし、
-[[Windows上で開発して>.NET Coreの開発]]
-[[検証手順>.NET Coreのデプロイ#fbabb769]]と同様に、WSL上にデプロイする。
*準備 [#iba2e597]

***dotnet new [#v014f0f4]
dotnet new コマンドを使用した、テンプレート準備とビルド・実行。
**WSL [#y54441e3]

***インストール [#r78a3a71]
[[コチラ>Windows Subsystem for Linux#o393cbb1]]を参照。

***設定 [#kacd3cc0]
-hostname : nishino
-username : seigi
-username@hostname : seigi@nishino

 Installing, this may take a few minutes...
 Installation successful!
 Please create a default UNIX user account. The username does not need to match your Windows username.
 For more information visit: https://aka.ms/wslusers
 Enter new UNIX username: seigi
 Enter new UNIX password:
 Retype new UNIX password:
 passwd: password updated successfully
 Default UNIX user set to: seigi
 To run a command as administrator (user "root"), use "sudo <command>".
 See "man sudo_root" for details.

**dotnet [#hcb1de96]

***2.n [#vb66787e]
 sudo apt-get update
 sudo apt-get install openssh-server unzip curl
 curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
 sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
 sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod xenial main" > /etc/apt/sources.list.d/dotnetdev.list'
 sudo apt-get update
 sudo apt-get install dotnet-sdk-2.n
 dotnet --version

***3.n [#o319f285]
...

**[[.NET Coreの開発]] [#d6efbd4a]
-[[Windows上で開発して>.NET Coreの開発]]
-[[検証手順>.NET Coreのデプロイ#fbabb769]]と同様に、WSL上にデプロイする。

***dotnet new [#v014f0f4]
dotnet new コマンドを使用した、テンプレート準備とビルド・実行。
 
 seigi@nishino:~$ curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                  Dload  Upload   Total   Spent    Left  Speed
 100   983  100   983    0     0    319      0  0:00:03  0:00:03 --:--:--   319
 seigi@nishino:~$ sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
 [sudo] password for seigi:
 seigi@nishino:~$ sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod xenial main" > /etc/apt/sources.list.d/dotnetdev.list'
 seigi@nishino:~$ sudo apt-get update
 Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [107 kB]
 Hit:2 http://archive.ubuntu.com/ubuntu xenial InRelease
 Get:3 https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod xenial InRelease [2,845 B]
 Get:4 http://archive.ubuntu.com/ubuntu xenial-updates InRelease [109 kB]
 Get:5 http://archive.ubuntu.com/ubuntu xenial-backports InRelease [107 kB]
 Get:6 http://archive.ubuntu.com/ubuntu xenial/universe amd64 Packages [7,532 kB]
 Get:7 https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod xenial/main amd64 Packages [38.1 kB]
 Get:8 http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages [484 kB]
 Get:9 http://security.ubuntu.com/ubuntu xenial-security/main Translation-en [209 kB]
 Get:10 http://security.ubuntu.com/ubuntu xenial-security/restricted amd64 Packages [7,224 B]
 Get:11 http://security.ubuntu.com/ubuntu xenial-security/restricted Translation-en [2,152 B]
 Get:12 http://security.ubuntu.com/ubuntu xenial-security/universe amd64 Packages [344 kB]
 Get:13 http://archive.ubuntu.com/ubuntu xenial/universe Translation-en [4,354 kB]
 Get:14 http://security.ubuntu.com/ubuntu xenial-security/universe Translation-en [129 kB]
 Get:15 http://security.ubuntu.com/ubuntu xenial-security/multiverse amd64 Packages [3,464 B]
 Get:16 http://security.ubuntu.com/ubuntu xenial-security/multiverse Translation-en [1,744 B]
 Get:17 http://archive.ubuntu.com/ubuntu xenial/multiverse amd64 Packages [144 kB]
 Get:18 http://archive.ubuntu.com/ubuntu xenial/multiverse Translation-en [106 kB]
 Get:19 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages [769 kB]
 Get:20 http://archive.ubuntu.com/ubuntu xenial-updates/main Translation-en [319 kB]
 Get:21 http://archive.ubuntu.com/ubuntu xenial-updates/restricted amd64 Packages [7,560 B]
 Get:22 http://archive.ubuntu.com/ubuntu xenial-updates/restricted Translation-en [2,272 B]
 Get:23 http://archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages [624 kB]
 Get:24 http://archive.ubuntu.com/ubuntu xenial-updates/universe Translation-en [252 kB]
 Get:25 http://archive.ubuntu.com/ubuntu xenial-updates/multiverse amd64 Packages [16.4 kB]
 Get:26 http://archive.ubuntu.com/ubuntu xenial-updates/multiverse Translation-en [8,344 B]
 Get:27 http://archive.ubuntu.com/ubuntu xenial-backports/main amd64 Packages [4,844 B]
 Get:28 http://archive.ubuntu.com/ubuntu xenial-backports/main Translation-en [3,220 B]
 Get:29 http://archive.ubuntu.com/ubuntu xenial-backports/universe amd64 Packages [7,400 B]
 Get:30 http://archive.ubuntu.com/ubuntu xenial-backports/universe Translation-en [3,996 B]
 Fetched 15.7 MB in 16s (944 kB/s)
 Reading package lists... Done
 seigi@nishino:~$ sudo apt-get install dotnet-sdk-2.0.0
 Reading package lists... Done
 Building dependency tree
 Reading state information... Done
 The following package was automatically installed and is no longer required:
   libfreetype6
 Use 'sudo apt autoremove' to remove it.
 The following additional packages will be installed:
   aspnetcore-store-2.0.0 dotnet-host dotnet-hostfxr-2.0.0 dotnet-runtime-2.0.0 dotnet-runtime-deps-2.1.0-rc1 libcurl3
   liblttng-ust-ctl2 liblttng-ust0 libunwind8 liburcu4
 The following NEW packages will be installed:
   aspnetcore-store-2.0.0 dotnet-host dotnet-hostfxr-2.0.0 dotnet-runtime-2.0.0 dotnet-runtime-deps-2.1.0-rc1
   dotnet-sdk-2.0.0 libcurl3 liblttng-ust-ctl2 liblttng-ust0 libunwind8 liburcu4
 0 upgraded, 11 newly installed, 0 to remove and 135 not upgraded.
 Need to get 108 MB of archives.
 After this operation, 309 MB of additional disk space will be used.
 Do you want to continue? [Y/n] Y
 Get:1 http://archive.ubuntu.com/ubuntu xenial/universe amd64 liburcu4 amd64 0.9.1-3 [47.3 kB]
 Get:2 https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod xenial/main amd64 aspnetcore-store-2.0.0 amd64 2.0.0-1 [18.1 MB]
 Get:3 http://archive.ubuntu.com/ubuntu xenial/universe amd64 liblttng-ust-ctl2 amd64 2.7.1-1 [72.2 kB]
 Get:4 http://archive.ubuntu.com/ubuntu xenial/universe amd64 liblttng-ust0 amd64 2.7.1-1 [127 kB]
 Get:5 http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 libcurl3 amd64 7.47.0-1ubuntu2.7 [187 kB]
 Get:6 http://archive.ubuntu.com/ubuntu xenial/main amd64 libunwind8 amd64 1.1-4.1 [46.5 kB]
 Get:7 https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod xenial/main amd64 dotnet-runtime-deps-2.1.0-rc1 amd64 2.1.0-rc1-1 [2,622 B]
 Get:8 https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod xenial/main amd64 dotnet-host amd64 2.1.0-rc1-1 [34.4 kB]
 Get:9 https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod xenial/main amd64 dotnet-hostfxr-2.0.0 amd64 2.0.0-1 [135 kB]
 Get:10 https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod xenial/main amd64 dotnet-runtime-2.0.0 amd64 2.0.0-1 [18.6 MB]
 Get:11 https://packages.microsoft.com/repos/microsoft-ubuntu-xenial-prod xenial/main amd64 dotnet-sdk-2.0.0 amd64 2.0.0-1 [70.3 MB]
 Fetched 108 MB in 1min 39s (1,078 kB/s)
 Selecting previously unselected package aspnetcore-store-2.0.0.
 (Reading database ... 25532 files and directories currently installed.)
 Preparing to unpack .../aspnetcore-store-2.0.0_2.0.0-1_amd64.deb ...
 Unpacking aspnetcore-store-2.0.0 (2.0.0-1) ...
 Selecting previously unselected package liburcu4:amd64.
 Preparing to unpack .../liburcu4_0.9.1-3_amd64.deb ...
 Unpacking liburcu4:amd64 (0.9.1-3) ...
 Selecting previously unselected package liblttng-ust-ctl2:amd64.
 Preparing to unpack .../liblttng-ust-ctl2_2.7.1-1_amd64.deb ...
 Unpacking liblttng-ust-ctl2:amd64 (2.7.1-1) ...
 Selecting previously unselected package liblttng-ust0:amd64.
 Preparing to unpack .../liblttng-ust0_2.7.1-1_amd64.deb ...
 Unpacking liblttng-ust0:amd64 (2.7.1-1) ...
 Selecting previously unselected package dotnet-runtime-deps-2.1.0-rc1.
 Preparing to unpack .../dotnet-runtime-deps-2.1.0-rc1_2.1.0-rc1-1_amd64.deb ...
 Unpacking dotnet-runtime-deps-2.1.0-rc1 (2.1.0-rc1-1) ...
 Selecting previously unselected package dotnet-host.
 Preparing to unpack .../dotnet-host_2.1.0-rc1-1_amd64.deb ...
 Unpacking dotnet-host (2.1.0-rc1-1) ...
 Selecting previously unselected package dotnet-hostfxr-2.0.0.
 Preparing to unpack .../dotnet-hostfxr-2.0.0_2.0.0-1_amd64.deb ...
 Unpacking dotnet-hostfxr-2.0.0 (2.0.0-1) ...
 Selecting previously unselected package libcurl3:amd64.
 Preparing to unpack .../libcurl3_7.47.0-1ubuntu2.7_amd64.deb ...
 Unpacking libcurl3:amd64 (7.47.0-1ubuntu2.7) ...
 Selecting previously unselected package libunwind8.
 Preparing to unpack .../libunwind8_1.1-4.1_amd64.deb ...
 Unpacking libunwind8 (1.1-4.1) ...
 Selecting previously unselected package dotnet-runtime-2.0.0.
 Preparing to unpack .../dotnet-runtime-2.0.0_2.0.0-1_amd64.deb ...
 Unpacking dotnet-runtime-2.0.0 (2.0.0-1) ...
 Selecting previously unselected package dotnet-sdk-2.0.0.
 Preparing to unpack .../dotnet-sdk-2.0.0_2.0.0-1_amd64.deb ...
 Unpacking dotnet-sdk-2.0.0 (2.0.0-1) ...
 Processing triggers for libc-bin (2.23-0ubuntu9) ...
 Processing triggers for man-db (2.7.5-1) ...
 Setting up aspnetcore-store-2.0.0 (2.0.0-1) ...
 Setting up liburcu4:amd64 (0.9.1-3) ...
 Setting up liblttng-ust-ctl2:amd64 (2.7.1-1) ...
 Setting up liblttng-ust0:amd64 (2.7.1-1) ...
 Setting up dotnet-runtime-deps-2.1.0-rc1 (2.1.0-rc1-1) ...
 Setting up dotnet-host (2.1.0-rc1-1) ...
 Setting up dotnet-hostfxr-2.0.0 (2.0.0-1) ...
 Setting up libcurl3:amd64 (7.47.0-1ubuntu2.7) ...
 Setting up libunwind8 (1.1-4.1) ...
 Setting up dotnet-runtime-2.0.0 (2.0.0-1) ...
 Setting up dotnet-sdk-2.0.0 (2.0.0-1) ...
 This software may collect information about you and your use of the software, and send that to Microsoft.
 Please visit http://aka.ms/dotnet-cli-eula for more information.
 Welcome to .NET Core!
 ---------------------
 Learn more about .NET Core @ https://aka.ms/dotnet-docs. Use dotnet --help to see available commands or go to https://aka.ms/dotnet-cli-docs.
 
 .NET Core Tools Telemetry
 --------------
 The .NET Core Tools include a telemetry feature that collects usage information. It is important that the .NET Team understands how the tools are being used so that we can improve them.
 
 The data collected is anonymous and will be published in an aggregated form for use by both Microsoft and community engineers under the Creative Commons Attribution License.
 
 The .NET Core Tools telemetry feature is enabled by default. You can opt-out of the telemetry feature by setting an environment variable DOTNET_CLI_TELEMETRY_OPTOUT (for example, 'export' on macOS/Linux, 'set' on Windows) to true (for example, 'true', 1). You can read more about .NET Core tools telemetry at https://aka.ms/dotnet-cli-telemetry.
 
 Installation Note
 --------------
 A command will be run during the install process that will improve project restore speed and enable offline access. It will take up to a minute to complete.
 Processing triggers for libc-bin (2.23-0ubuntu9) ...
 seigi@nishino:~$ dotnet --version
 2.0.0
 seigi@nishino:~$ which dotnet
 /usr/bin/dotnet
 seigi@nishino:~$ dotnet new console
 
 Welcome to .NET Core!
 ---------------------
 Learn more about .NET Core @ https://aka.ms/dotnet-docs. Use dotnet --help to see available commands or go to https://aka.ms/dotnet-cli-docs.
 
 Telemetry
 --------------
 The .NET Core tools collect usage data in order to improve your experience. The data is anonymous and does not include command-line arguments. The data is collected by Microsoft and shared with the community.
 You can opt out of telemetry by setting a DOTNET_CLI_TELEMETRY_OPTOUT environment variable to 1 using your favorite shell.
 You can read more about .NET Core tools telemetry @ https://aka.ms/dotnet-cli-telemetry.
 Getting ready...
 The template "Console Application" was created successfully.
 
 Processing post-creation actions...
 Running 'dotnet restore' on /home/seigi/seigi.csproj...
   Restoring packages for /home/seigi/seigi.csproj...
   Generating MSBuild file /home/seigi/obj/seigi.csproj.nuget.g.props.
   Generating MSBuild file /home/seigi/obj/seigi.csproj.nuget.g.targets.
   Restore completed in 236.36 ms for /home/seigi/seigi.csproj.
 
 
 Restore succeeded.
 
 seigi@nishino:~$ dotnet publish -f netcoreapp2.0
 Microsoft (R) Build Engine version 15.3.409.57025 for .NET Core
 Copyright (C) Microsoft Corporation. All rights reserved.
 
   seigi -> /home/seigi/bin/Debug/netcoreapp2.0/seigi.dll
   seigi -> /home/seigi/bin/Debug/netcoreapp2.0/publish/
 seigi@nishino:~$ dotnet /home/seigi/bin/Debug/netcoreapp2.0/seigi.dll
 Hello World!
 seigi@nishino:~$

***dotnet publish [#zc5721da]
[[Visual Studio]]で作成したものを「/mnt/c」[[※ 1>#eefd5e3f]] を経由で、
-ビルド(dotnet publish)
-実行([[dotnet>#ob2ac8a7]])
-実行([[dotnet *.dll>#ob2ac8a7]])

 cd /mnt/c/ConsoleApp1/ConsoleApp1
 dotnet publish -c Release -r ubuntu.16.04-x64 --self-contained
 cd bin/Release/netcoreapp2.0/ubuntu.16.04-x64
 dotnet ConsoleApp1.dll
 Hello World!

※ [[SCD>.NET Coreのデプロイ#w88a1ee1]]

***dotnet [#ob2ac8a7]
***dotnet *.dll [#ob2ac8a7]
[[Visual Studio]]で作成・ビルドしたものを「/mnt/c」[[※ 1>#eefd5e3f]] を経由して実行~
 dotnet /mnt/c/ConsoleApp1/ConsoleApp1/bin/Debug/netcoreapp2.0/ConsoleApp1.dll
 Hello World!

※ [[FDD>.NET Coreのデプロイ#yfb796bd1]]

**[[ASP.NET Coreの開発]] [#r6a90b09]
-WSLをインストールし、
-[[Windows上で開発して>ASP.NET Coreの開発]]
-[[検証手順>ASP.NET Coreのデプロイ#ac95e514]]と同様に、WSL上にデプロイする。

***dotnet new [#ea9494e7]
dotnet new コマンドを使用した、準備と確認。
 seigi@nishino:~$ dotnet new mvc
 Creating this template will make changes to existing files:
   Overwrite   seigi.csproj
   Overwrite   Program.cs
 
 Rerun the command and pass --force to accept and create.
 seigi@nishino:~$
 seigi@nishino:~$ dotnet new mvc --force
 The template "ASP.NET Core Web App (Model-View-Controller)" was created successfully.
 This template contains technologies from parties other than Microsoft, see https://aka.ms/template-3pn for details.
 
 Processing post-creation actions...
 Running 'dotnet restore' on /home/seigi/seigi.csproj...
   Restoring packages for /home/seigi/seigi.csproj...
   Restoring packages for /home/seigi/seigi.csproj...
   Restore completed in 2.09 sec for /home/seigi/seigi.csproj.
   Generating MSBuild file /home/seigi/obj/seigi.csproj.nuget.g.targets.
   Restore completed in 3.83 sec for /home/seigi/seigi.csproj.
 
 
 Restore succeeded.
 
 seigi@nishino:~$ dotnet run
 warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35]
       No XML encryptor configured. Key {89022286-2fdf-47e0-85d2-0047907c89b1} may be persisted to storage in unencrypted form.
 
 Hosting environment: Production
 Content root path: /home/seigi
 Now listening on: http://localhost:5000
 Application started. Press Ctrl+C to shut down.
 ^CApplication is shutting down...
 
 seigi@nishino:~$
#ref(mvc1.png,left,nowrap,mvcの実行1,60%)

***dotnet publish [#v85949da]
...。
[[同上>#zc5721da]]

***dotnet run [#y62ae3c4]
[[Visual Studio]]で作成・ビルドしたものを「/mnt/c」[[※ 1>#eefd5e3f]] を経由して実行~
 seigi@nishino:~$ cd /mnt/c/WebApplication1/WebApplication1/
 seigi@nishino:/mnt/c/WebApplication1/WebApplication1$ dotnet run
 Using launch settings from /mnt/c/WebApplication1/WebApplication1/Properties/launchSettings.json...
 info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0]
       User profile is available. Using '/home/seigi/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest.
 Hosting environment: Development
 Content root path: /mnt/c/WebApplication1/WebApplication1
 Now listening on: http://localhost:53336
 Application started. Press Ctrl+C to shut down.
 info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
       Request starting HTTP/1.1 GET http://localhost:53336/
 info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[1]
       Executing action method WebApplication1.Controllers.HomeController.Index (WebApplication1) with arguments ((null)) - ModelState is Valid
 info: Microsoft.AspNetCore.Mvc.ViewFeatures.Internal.ViewResultExecutor[1]
       Executing ViewResult, running view at path /Views/Home/Index.cshtml.
 info: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
       Executed action WebApplication1.Controllers.HomeController.Index (WebApplication1) in 6636.097ms
 info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
       Request starting HTTP/1.1 GET http://localhost:53336/css/site.css
 info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
       Request starting HTTP/1.1 GET http://localhost:53336/lib/bootstrap/dist/css/bootstrap.css
 info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
       Request starting HTTP/1.1 GET http://localhost:53336/lib/jquery/dist/jquery.js
 info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
       Request finished in 7032.349ms 200 text/html; charset=utf-8
 info: Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware[2]
       Sending file. Request path: '/lib/jquery/dist/jquery.js'. Physical path: '/mnt/c/WebApplication1/WebApplication1/wwwroot/lib/jquery/dist/jquery.js'
 info: Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware[2]
       Sending file. Request path: '/css/site.css'. Physical path: '/mnt/c/WebApplication1/WebApplication1/wwwroot/css/site.css'
 info: Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware[2]
       Sending file. Request path: '/lib/bootstrap/dist/css/bootstrap.css'. Physical path: '/mnt/c/WebApplication1/WebApplication1/wwwroot/lib/bootstrap/dist/css/bootstrap.css'
 info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
       Request finished in 544.652ms 200 text/css
 info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
       Request finished in 551.471ms 200 text/css
 info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
       Request finished in 554.874ms 200 application/javascript
 info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
       Request starting HTTP/1.1 GET http://localhost:53336/lib/bootstrap/dist/js/bootstrap.js
 info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
       Request starting HTTP/1.1 GET http://localhost:53336/js/site.js?v=ji3-IxbEzYWjzzLCGkF1KDjrT2jLbbrSYXw-AhMPNIA
 info: Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware[2]
       Sending file. Request path: '/lib/bootstrap/dist/js/bootstrap.js'. Physical path: '/mnt/c/WebApplication1/WebApplication1/wwwroot/lib/bootstrap/dist/js/bootstrap.js'
 info: Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware[2]
       Sending file. Request path: '/js/site.js'. Physical path: '/mnt/c/WebApplication1/WebApplication1/wwwroot/js/site.js'
 info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
       Request starting HTTP/1.1 GET http://localhost:53336/images/banner1.svg
 info: Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware[2]
       Sending file. Request path: '/images/banner1.svg'. Physical path: '/mnt/c/WebApplication1/WebApplication1/wwwroot/images/banner1.svg'
 info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
       Request finished in 0.714ms 200 image/svg+xml
 info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
       Request starting HTTP/1.1 GET http://localhost:53336/images/banner2.svg
 info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
       Request finished in 3.301ms 200 application/javascript
 info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
       Request starting HTTP/1.1 GET http://localhost:53336/images/banner3.svg
 info: Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware[2]
       Sending file. Request path: '/images/banner2.svg'. Physical path: '/mnt/c/WebApplication1/WebApplication1/wwwroot/images/banner2.svg'
 info: Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware[2]
       Sending file. Request path: '/images/banner3.svg'. Physical path: '/mnt/c/WebApplication1/WebApplication1/wwwroot/images/banner3.svg'
 info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
       Request finished in 0.348ms 200 image/svg+xml
 info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
       Request finished in 0.485ms 200 image/svg+xml
 info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
       Request starting HTTP/1.1 GET http://localhost:53336/images/banner4.svg
 info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
       Request finished in 6.833ms 200 application/javascript
 info: Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware[2]
       Sending file. Request path: '/images/banner4.svg'. Physical path: '/mnt/c/WebApplication1/WebApplication1/wwwroot/images/banner4.svg'
 info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
       Request finished in 1.35ms 200 image/svg+xml
 info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
       Request starting HTTP/1.1 GET http://localhost:53336/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2
 info: Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware[2]
       Sending file. Request path: '/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2'. Physical path: '/mnt/c/WebApplication1/WebApplication1/wwwroot/lib/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2'
 info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
       Request finished in 0.757ms 200 font/woff2
 info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1]
       Request starting HTTP/1.1 GET http://localhost:53336/favicon.ico
 info: Microsoft.AspNetCore.StaticFiles.StaticFileMiddleware[2]
       Sending file. Request path: '/favicon.ico'. Physical path: '/mnt/c/WebApplication1/WebApplication1/wwwroot/favicon.ico'
 info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2]
       Request finished in 1.081ms 200 image/x-icon
#ref(mvc2.png,left,nowrap,mvcの実行2,60%)

**[[OSバージョンの確認>Visual Studio Tools for Docker#u6c27f49]] [#j5258403]
**OSバージョンの確認 [#j5258403]
以下のような感じ。

 OperatingSystem os = Environment.OSVersion;
 if (os.Platform == PlatformID.Win32NT)
 {
     ・・・

*詳細 [#fd286380]
Open棟梁を動かしてみる。
*リモートデバッグ [#fd286380]

**C/C++ [#d81d6983]

***WSLのリモートデバッグ設定 [#o5abb403]
以下は、すべて、WSL(Ubuntu)上の設定。

-パッケージリストが古いと404になるので、以下を実行してから、
 sudo apt-get update

-コンパイラー、リモートデバッガ、sshサーバーのインストールを実施する。
-コンパイラー、リモートデバッガ、SSHサーバのインストールを実施する。
 sudo apt install -y build-essential
 sudo apt install -y gdbserver
 sudo apt install -y openssh-server

-/etc/ssh/sshd_configファイルを編集

--「[[vi>https://dotnetdevelopmentinfrastructure.osscons.jp/index.php?vi]]」エディタで開く
 sudo vi /etc/ssh/sshd_config
--パスワード認証を有効にする。
 # Change to no to disable tunnelled clear text passwords
 PasswordAuthentication yes

-SSHの鍵を作成する
 sudo ssh-keygen -A

-SSHサーバーを起動する
-SSHサーバを起動する
 sudo service ssh start

***Visual Studioの設定 [#jb072390]
-SSHサーバの状態を確認する。
 sudo service ssh status

-Visual Studio 2017のインストーラーで[C++ による Linux 開発]コンポーネントにチェック
***[[Visual Studio]]の設定 [#jb072390]
以下は、すべて、Windows上の設定。

-[[Visual Studio]] 2017のインストーラーで、~
[C++ による Linux 開発]コンポーネントにチェック

-[Visual C++]-[クロス プラットフォーム]-[Linux]を選択し、~
中央のテンプレート一覧から「コンソール アプリケーション (Linux)」を選択する。
テンプレート一覧から「コンソール アプリケーション (Linux)」を選択。

-コンパイルを実行すると、WSLへの接続ダイアログが表示される
-F5でデバッグ実行すると、WSLへの接続ダイアログが表示され、接続が確立する。
--[Host name:]欄には「localhost」
--[User name:]欄と[Password]欄に(Ubuntuの)ユーザ / パスワード
--[Connect]ボタンをクリックしてWSLに接続。

-「gdbを起動できませんでした」と言うエラーが発生する場合、~
プロジェクトのプロパティの[デバッグ]→[デバッグ モード]を、~
gdb モードから、gdbserver モードへ、変更する。

**.NET Core [#hc8a9948]
仕組みとしては、

><Windows>~
[[Visual Studio]] → DebugAdapterHost → [[PuTTY]]~
~
↓ ↓ ↓(SSH)↑ ↑ ↑~
~
<Linux>~
openssh-server → vsdbg → dotnet (XXXX.dll) 

みたいな感じで、

-debuggerをattachした~
remote processと

-client IDEが

通信してdebugする感じ。

***WSLのリモートデバッグ設定 [#s03bb12c]
-WSL(Ubuntu)上の設定。

-次のコマンドを実行してVSDBGをインストールする。~
「~/vsdbg」の「~」部分は、任意のパスを指定する。
--[[前述の手順>#o5abb403]]と同様に、~
SSHサーバのインストールと設定を実施しておく。

--unzipをインストールする(vsdbgのインストールで必要だったため)。
 sudo apt-get install unzip

--次のコマンドを実行してvsdbgをインストールする。~
「-l」には、任意のインストール・パスを指定する。
 curl -sSL https://aka.ms/getvsdbgsh | bash /dev/stdin -v vs2017u5 -l ~/vsdbg

-トランスポートには、[[前述>#o5abb403]]と同様にSSHを使用できる。
--トランスポートには、[[前述>#o5abb403]]と同様にSSHを使用できる。

***Visual Studioの設定 [#jdf58d89]
-Windows上の設定。

--[[PuTTY]]をインストールして、
--[[PuTTY]]でSSHサーバを接続する。

***[[Visual Studio]]の設定 [#jdf58d89]

-デバッグ対象のプロジェクトはポータブルPDBを指定。

-Windows上でビルドが通ったら、Linux上でdotnet publishする。
-Windows上でビルドが通ったら、
--そのまま次のステップに進む(FDD)
--Linux上で[[dotnet publish>#zc5721da]]する(SCD)~
ファイルを共有については、「/mnt/c」[[※ 1>#eefd5e3f]] を経由で、

-ファイルを共有については、「/mnt/c」[[※ 1>#eefd5e3f]] を経由で、
>※ [[FDDがイイのか?SCDがイイのか?>.NET Coreのデプロイ#o6acb6b5]]

-起動構成ファイル(launch.json)を作成する。
--Visual Studioにデバッグ方法を指示する
--[[Visual Studio]]にデバッグ方法を指示する
--プロジェクトを起動するlaunch.jsonファイルの例を次に示す。
 {
   "version": "n.n.n",
   "adapter": "c:\\...\\plink.exe",
   "adapterArgs": "-i c:\\...\\ssh-key.ppk xxxx@yyyy -batch -T ~/vsdbg/vsdbg --interpreter=vscode",
   "version": "1.0.0",
   "adapter": "C:\\Program Files\\PuTTY\\plink.exe",
   "adapterArgs": "-i c:\\private.ppk seigi@nishino -batch -T ~/vsdbg/vsdbg --interpreter=vscode",
   "configurations": [
     {
       "name": ".NET Core Launch",
       "type": "coreclr",
       "cwd": "~/xxxx",
       "program": "bin/Debug/netcoreappn.n/xxxx.dll",
       "cwd": "/mnt/c/xxxx",
       "program": "bin/Debug/netcoreappn.n/.../xxxx.dll",
       "request": "launch"
     }
   ]
 }
※ コレは、SCDのパターンか。

--adapter~
トランスポートとしてSSHを使用
---SSHクライアントはPuTTY(plink.exe)を使用する。
---SSHクライアントは[[PuTTY]](plink.exe)を使用する。
---SSHサーバーを経由してvsdbgに接続する。

--adapterArgs~
PuTTY(plink.exe)のコマンドライン引数
[[PuTTY]](plink.exe)のコマンドライン引数
---プライベートSSHキーへのパス
---SSH Linuxボックスに接続するように指示
---vsdbgディレクトリから実行可能vsdbgを実行
---vsdbgインストール・ディレクトリから、~
vsdbg実行可能ファイルを実行

--program
---Linux上の、実行可能ファイルへのパスを指定。
---(vsdbgはdotnetコマンドで実行可能ファイルを実行)
--configurations~
vsdbgに渡す設定値

---cwd~
・Linux上の、プロジェクトのルート・ディレクトリ~
・若しくは、実行可能ファイルの配置先ディレクトリ

---program~
・Linux上の、実行可能ファイルへのパス~
・若しくは、実行可能ファイル名~
・(vsdbgはdotnetコマンドで実行可能ファイルを実行)

***デバッグ実行を開始 [#j88e5db1]
-冒頭に書いた通り、DebugAdapterHost経由で、デバッグ実行を開始。
--[表示] メニュー > [その他のウィンドウ] > [コマンド ウィンドウ]
--以下のコマンドを、[[Visual Studio]]のコマンドウィンドウに打ち込む。~
 DebugAdapterHost.Launch /LaunchJson:"launch.jsonファイルのフルパス"

>※ ファイル名は「launch.json」でなくてもイイもよう。

-以下の様に、リモートデバッグが実行される。~
https://twitter.com/openhishopjpo/status/1163729300383682561

**ASP.NET Core [#neb6d639]

***WSLのリモートデバッグ設定 [#v0f5c559]
-WSL(Ubuntu)上の設定。
--以下を除き、[[.NET Core>#s03bb12c]]と同じ。
--dotnet2.1以上。

-Windows上の設定。
--以下を除き、[[.NET Core>#s03bb12c]]と同じ。
--dotnet2.1以上。

***[[Visual Studio]]の設定 [#r82ae9c8]
以下を除き、[[.NET Core>#jdf58d89]]と同じ。

-以下をProgram.Mainメソッドに追加する。~
(リモートデバッグではブラウザが自動起動しないのでポートを明示)
 CreateWebHostBuilder(args).UseUrls("http://*:5000").Build().Run();

***デバッグ実行を開始 [#g3a8eddb]
以下を除き、[[.NET Core>#j88e5db1]]と同じ。

-上記のUseUrlsで指定したポート(5000)のリスニングを許可する。

-WWWブラウザから「http://localhost:5000/」にアクセスする。

-以下の様に、リモートデバッグが実行される。~
https://twitter.com/openhishopjpo/status/1167284051515887618

**[[Visual Studio]]からデバッガをアタッチする方法 [#b8ef542f]

***WSLのリモートデバッグ設定 [#v01311f3]
-以下を除き、[[.NET Core>#hc8a9948]]、[[ASP.NET Core>#neb6d639]]と同じ。

-事前に、アプリケーションを起動しておく(自動でLaunchしないので)。
 dotnet /.../xxxx.dll

-ConsoleAppでは、アプリケーションが瞬時に終了してしまうため、~
必要に応じて、Console.ReadKeyなどで止める必要はある。

***[[Visual Studio]]の設定 [#l10cd6cd]
-以下を除き、[[ASP.NET Core>#r82ae9c8]]と同じ。
--launch.jsonを自作する必要はない。
--SSHクライアントの[[PuTTY]]も不要(OS組込のモノを使用する)

-[[Visual Studio]]のメニューから~
[ツール] → [オプション] → [オプション]ダイアログ~
→ [クロスプラットフォーム] → [接続マネージャー] → [追加]~
→ [リモートシステムへの接続]ダイアログにて下記の情報を入力。
--ホスト名 : localhost (任意)
--ポート : 22
--ユーザー名 : seigi
--認証の種類 : パスワード or 秘密鍵

***デバッグ実行を開始 [#j84bacd5]
-事前に、アプリケーションを起動しておく。

-[[Visual Studio]]のメニューから~
[デバッグ] → [プロセスにアタッチ] → [プロセスにアタッチ]ダイアログ
--接続の種類 : SSH
--接続先 : seigi@localhost (検索して選択)
--アタッチ先 : [Maneged(.NET Core for Unix) コード]

-[使用可能なプロセス]から選択し、[アタッチ]ボタンを押下
--プロセスが dotnet
--タイトルが dotnet /.../xxxx.dll

-デバッグ対象ファイルを開いて、ブレークポイントを指定する。

-起動したアプリケーションを実行する。
--ConsoleApp~
キーを押下し、Console.ReadKeyを通過させる。
--MvcApplication~
WWWブラウザから「http://localhost:5000/」にアクセスする。

-以下の様に、リモートデバッグが実行される。~
https://twitter.com/openhishopjpo/status/1167284051515887618

**[[WSL2では何がどう変わったのか?>WSL → WSL2#t061a41a]] [#nd935739]

*参考 [#ida97117]

-OSのバージョンを取得する、OSの種類を判別する - .NET Tips (VB.NET,C#...)~
https://dobon.net/vb/dotnet/system/osversion.html

**C/C++ [#b8823428]
**※ 1 [#eefd5e3f]
[[DrvFsのVFSファイルシステムプラグイン。>WSLでのWindowsとLinuxの相互運用#jc2d54b9]]

**[[トレースによるデバッグ>dotnetコマンド#b7716dc9]] [#yce48fff]
リモートデバッグが難しい場合はコチラ。

**リモートデバッグ [#gb2063cd]

***C/C++ [#b8823428]
-Windows Subsystem for Linuxを使って「開発」をしてみよう - Build Insider~
http://www.buildinsider.net/enterprise/wsl/02
-WSL その75 - Visual Studio + Ubuntu on WindowsでUbuntuのソフトウェアが開発可能に - kledgeb~
https://kledgeb.blogspot.com/2017/02/wsl-75-visual-studio-ubuntu-on.html

**.NET Core [#w6692b65]
-VisualStudio 2017 RC3 から .NET Core on RHEL にリモートデバッグする - 銀の光と碧い空~
***.NET Core [#w6692b65]
-Visual Studio 2017 RC3 から .NET Core on RHEL にリモートデバッグする - 銀の光と碧い空~
https://tech.tanaka733.net/entry/remote-debug-dotnetcore-on-rhel-from-vs2017rc3

-RaspberryPi(Raspbian)上で動く.NET Core2.1アプリをリモートデバッグする - Qiita~
https://qiita.com/HiroyukiSakoh/items/ec947802dd2f69a38e8b

-Offroad Debugging of .NET Core on Linux OSX from Visual Studio · microsoft/MIEngine Wiki~
https://github.com/Microsoft/MIEngine/wiki/Offroad-Debugging-of-.NET-Core-on-Linux---OSX-from-Visual-Studio

**※ 1 [#eefd5e3f]
[[DrvFsのVFSファイルシステムプラグイン。>Windows Subsystem for Linux#ve679160]]
**OSSコンソーシアム [#he6e9ac0]
***開発基盤部会 Blog [#u2616003]
-ASP.NET CoreのLinux開発環境についての考察(WSL or Docker)~
https://www.osscons.jp/jotmuz8dq-537/

-WSL開発環境、大方、出来上がった感。最新の開発環境についての考察
--① : https://www.osscons.jp/joroqfht0-537/
--② : https://www.osscons.jp/jo1ocsdgb-537/

----
Tags: [[:.NET開発]], [[:.NET Core]], [[:Windows]], [[:Linux]], [[:Linuxサブシステム]], [[:仮想化]]


トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS