「[[.NET 開発基盤部会 Wiki>http://dotnetdevelopmentinfrastructure.osscons.jp]]」は、「[[Open棟梁Project>https://github.com/OpenTouryoProject/]]」,「[[OSSコンソーシアム .NET開発基盤部会>https://www.osscons.jp/dotNetDevelopmentInfrastructure/]]」によって運営されています。 -[[戻る>Linuxの各種 手順]] *目次 [#i59b8952] #contents *概要 [#q562e876] -.NET CoreをLinux上にインストールして、 -ASP.NET Coreアプリをビルド、デプロイ、実行する。 -事前に、以下のインストールを行っておく。 --[[Linux>Linuxの各種 手順#n7a5cd78]] ---[[nginx>nginxのインストール]] ---[[.NET Core>.NET Coreのインストールとデプロイ]] **全容 [#hca66cec] [[ASP.NET Coreのデプロイ - マイクロソフト系技術情報 Wiki>https://techinfoofmicrosofttech.osscons.jp/index.php?ASP.NET%20Core%E3%81%AE%E3%83%87%E3%83%97%E3%83%AD%E3%82%A4]] **仕組 [#i106acbc] [[コチラ>.NET Coreのインストールとデプロイ#p1125a78]]を参照。 **サンプル [#z95fab4f] ***dotnet new mvc [#t4636ccf] Linux上でdotnet new mvcで生成。 ***Visual Studioのテンプレート [#wf07c39c] テンプレートを以下のように最小化。 -HomeController.cs public class HomeController : Controller { public IActionResult Index() { string[] str_ary = new string[] { "aaa", "bbb", "ccc" }; ViewBag.Ret = JsonConvert.SerializeObject(str_ary); return View(); } -Index.cshtml @{ ViewData["Title"] = "Home Page"; } @Html.Label((string)ViewBag.Ret); **ASP.NET CoreのSCDは2.1からサポート [#x0064748] ASP.NET Core 2.0 で自己完結型の展開 (SCD) を実行する場合、~ 現時点では Razor ビューのプリコンパイルを使用できません。~ この機能は 2.1 のリリース時に SCD で使用可能になります。 -Razor ビューのコンパイルとプリコンパイル | Microsoft Docs~ https://docs.microsoft.com/ja-jp/aspnet/core/mvc/views/view-compilation?tabs=aspnetcore2x --View compilation fails when cross-compiling for Linux on Windows · Issue #102 · aspnet/MvcPrecompilation~ https://github.com/aspnet/MvcPrecompilation/issues/102 *CentOS [#ra2ca0dd] **CentOS上でビルドして動かす(FDD & SCD)。 [#s886317b] ***dotnet new mvcで生成したものをビルド・実行 [#qb615732] -FDD --生成・ビルド $ dotnet new mvc Getting ready... 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 ・・・/mvc/mvc.csproj... Restoring packages for ・・・/mvc/mvc.csproj... Restoring packages for ・・・/mvc/mvc.csproj... Restore completed in 1.3 min for ・・・/mvc/mvc.csproj. Generating MSBuild file ・・・/mvc/obj/mvc.csproj.nuget.g.props. Generating MSBuild file ・・・/mvc/obj/mvc.csproj.nuget.g.targets. Restore completed in 1.52 min for ・・・/mvc/mvc.csproj. Restore succeeded. --実行 $ dotnet run warn: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[35] No XML encryptor configured. Key {・・・} may be persisted to storage in unencrypted form. Hosting environment: Production Content root path: ・・・/mvc Now listening on: http://localhost:5000 Application started. Press Ctrl+C to shut down. --確認 $ curl http://localhost:5000 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Home Page - mvc</title> -SCD~ [[ASP.NET CoreのSCDは2.1からサポート>#x0064748]] ***Visual Studioで生成したものをビルド・実行 [#m02d1594] **Windows上でビルドしたものを動かす。 [#tdbd6f86] ***FDD [#cd9b8f51] -実行 [xxxxx WebApplication1]$ dotnet run ・・・・・・ASP.NET アプリ起動 Using launch settings from ・・・/WebApplication1/WebApplication1/Properties/launchSettings.json... info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0] User profile is available. Using '/・・・.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest. Hosting environment: Development Content root path: ・・・/WebApplication1/WebApplication1 Now listening on: http://localhost:52013 Application started. Press Ctrl+C to shut down. info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1] Request starting HTTP/1.1 GET http://localhost:52013/ 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 10159.7952ms info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2] Request finished in 10942.7977ms 200 text/html; charset=utf-8 -確認 [xxxxx ~]$ curl http://localhost:52013 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Home Page - WebApplication1</title> <link rel="stylesheet" href="/lib/bootstrap/dist/css/bootstrap.css" /> <link rel="stylesheet" href="/css/site.css" /> </head> <body> <div class="container body-content"> <label for="z_aaa___bbb___ccc__">["aaa","bbb","ccc"]</label>; <hr /> <footer> <p>© 2018 - WebApplication1</p> </footer> </div> <script src="/lib/jquery/dist/jquery.js"></script> <script src="/lib/bootstrap/dist/js/bootstrap.js"></script> <script src="/js/site.js?v=ji3-IxbEzYWjzzLCGkF1KDjrT2jLbbrSYXw-AhMPNIA"></script> </body> </html> ***SCD [#r1969db4] [[ASP.NET CoreのSCDは2.1からサポート>#x0064748]] *Ubuntu [#gca834b3] **Ubuntu上でビルドして動かす(FDD & SCD)。 [#p1c8fe53] ***dotnet new mvcで生成したものをビルド・実行 [#m2cfa5e3] -FDD --生成・ビルド :~$ mkdir mvc :~$ cd mvc :~/mvc$ dotnet new mvc 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 ・・・/mvc/mvc.csproj... Restoring packages for ・・・/mvc/mvc.csproj... Restore completed in 9.08 sec for ・・・/mvc/mvc.csproj. Generating MSBuild file ・・・/mvc/obj/mvc.csproj.nuget.g.props. Generating MSBuild file ・・・/mvc/obj/mvc.csproj.nuget.g.targets. Restore completed in 29.34 sec for ・・・/mvc/mvc.csproj. Restore succeeded. --実行 :~/mvc$ dotnet run Hosting environment: Production Content root path: ・・・/mvc Now listening on: http://localhost:5000 Application started. Press Ctrl+C to shut down. --確認 :$ curl http://localhost:5000 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Home Page - mvc</title> -SCD~ [[ASP.NET CoreのSCDは2.1からサポート>#x0064748]] ***Visual Studioで生成したものをビルド・実行 [#b637f67d] **Windows上でビルドしたものを動かす。 [#bf331725] ***FDD [#q14d49e2] -実行 :~/WebApplication1/WebApplication1$ dotnet run Using launch settings from ・・・/WebApplication1/WebApplication1/Properties/launchSettings.json... info: Microsoft.AspNetCore.DataProtection.KeyManagement.XmlKeyManager[0] User profile is available. Using '・・・.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest. Hosting environment: Development Content root path: ・・・/WebApplication1/WebApplication1 Now listening on: http://localhost:52013 Application started. Press Ctrl+C to shut down. info: Microsoft.AspNetCore.Hosting.Internal.WebHost[1] Request starting HTTP/1.1 GET http://localhost:52013/ 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 12571.0289ms info: Microsoft.AspNetCore.Hosting.Internal.WebHost[2] Request finished in 13754.7828ms 200 text/html; charset=utf-8 -確認 :~$ curl http://localhost:52013 <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Home Page - WebApplication1</title> <link rel="stylesheet" href="/lib/bootstrap/dist/css/bootstrap.css" /> <link rel="stylesheet" href="/css/site.css" /> </head> <body> <div class="container body-content"> <label for="z_aaa___bbb___ccc__">["aaa","bbb","ccc"]</label>; <hr /> <footer> <p>© 2018 - WebApplication1</p> </footer> </div> <script src="/lib/jquery/dist/jquery.js"></script> <script src="/lib/bootstrap/dist/js/bootstrap.js"></script> <script src="/js/site.js?v=ji3-IxbEzYWjzzLCGkF1KDjrT2jLbbrSYXw-AhMPNIA"></script> </body> </html> :~$ ***SCD [#g21c9f5a] [[ASP.NET CoreのSCDは2.1からサポート>#x0064748]] *Webサーバ上で動作させる。 [#z2a7b525] **Apache [#d495abfb] **[[nginx]] [#i30e0f43] [[コチラ>nginxでASP.NET Coreをホストする]]を参照。 *参考 [#ed43e9af] **athome-developer's blog [#uca564e9] -CentOS7でASP.NET Coreを動かす~ http://dblog.athome.co.jp/entry/2016/11/21/120000 -RHEL7.4でASP.NET Coreを動かす~ http://dblog.athome.co.jp/entry/2017/10/10/120000 **osscons.jp [#l898ae76] ***[[nginxのインストール]] [#v7b6c237] ***[[.NET Coreのインストールとデプロイ]] [#kad708cd] ***マイクロソフト系技術情報 Wiki [#ue70298c] -[[.NET Coreのデプロイ>https://techinfoofmicrosofttech.osscons.jp/index.php?.NET%20Core%E3%81%AE%E3%83%87%E3%83%97%E3%83%AD%E3%82%A4]] -[[ASP.NET Coreのデプロイ>https://techinfoofmicrosofttech.osscons.jp/index.php?ASP.NET%20Core%E3%81%AE%E3%83%87%E3%83%97%E3%83%AD%E3%82%A4]]