Skip to content

DNET_ASPNETCoreInstallDeploy

nishi_74322014 edited this page Sep 11, 2026 · 1 revision

ASP.NET Coreのインストールとデプロイ

概要

全容

ASP.NET Coreのデプロイ - マイクロソフト系技術情報 Wiki

仕組

.NET Coreのインストールとデプロイの該当節を参照。

サンプル

dotnet new mvc

Linux上でdotnet new mvcで生成。

Visual Studioのテンプレート

テンプレートを以下のように最小化。

  • 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からサポート

ASP.NET Core 2.0 で自己完結型の展開 (SCD) を実行する場合、
現時点では Razor ビューのプリコンパイルを使用できません。
この機能は 2.1 のリリース時に SCD で使用可能になります。

CentOS

CentOS上でビルドして動かす(FDD & SCD)。

dotnet new mvcで生成したものをビルド・実行(CentOS)

  • 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からサポート

Visual Studioで生成したものをビルド・実行(CentOS)

(元 Wiki では見出しのみで本文が無い。)

Windows上でビルドしたものを動かす。(CentOS)

FDD(CentOS)

  • 実行

    [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__">[&quot;aaa&quot;,&quot;bbb&quot;,&quot;ccc&quot;]</label>;
            <hr />
            <footer>
                <p>&copy; 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(CentOS)

ASP.NET CoreのSCDは2.1からサポート

Ubuntu

Ubuntu上でビルドして動かす(FDD & SCD)。

dotnet new mvcで生成したものをビルド・実行(Ubuntu)

  • 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からサポート

Visual Studioで生成したものをビルド・実行(Ubuntu)

(元 Wiki では見出しのみで本文が無い。)

Windows上でビルドしたものを動かす。(Ubuntu)

FDD(Ubuntu)

  • 実行

    :~/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__">[&quot;aaa&quot;,&quot;bbb&quot;,&quot;ccc&quot;]</label>;
            <hr />
            <footer>
                <p>&copy; 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(Ubuntu)

ASP.NET CoreのSCDは2.1からサポート

...で動作させる。

Webサーバ上で動作させる。

Apache

Apache

nginx

nginx

nginxでASP.NET Coreをホストするを参照。

WindowsのIIS上で動作させる。

ASP.NET Coreのデプロイの該当節を参照。

デバッグ

(ローカルで)デバッグ

  • 全部Linux上でやる。
  • 機会があったら調べる。
  • k8s上でトラブルシュートとか?

リモート・デバッグ

WSL上での.NET Core開発の該当節を参照。

参考

athome-developer's blog

osscons.jp

マイクロソフト系技術情報 Wiki

移行メモ

  • 元 Wiki では「Webサーバ上で動作させる。」と 「WindowsのIIS上で動作させる。」の見出しに同じアンカ(#z2a7b525)が 振られていた(PukiWiki 側の重複)。
  • 元 Wiki では見出しそのものが他ページへのリンクになっていた箇所 (「nginx」「WindowsのIIS上で動作させる。」「nginxのインストール」 「.NET Coreのインストールとデプロイ」「Red Hat Customer Portal > Chapter 1.」)は、 GitHub Wiki では見出しからアンカが生成されるため、 見出しをプレーン・テキストとし、リンクは直下の本文(箇条書き)に置いた。
  • 同名の見出し(「dotnet new mvcで生成したものをビルド・実行」 「Visual Studioで生成したものをビルド・実行」「Windows上でビルドしたものを動かす。」 「FDD」「SCD」)が CentOS 節と Ubuntu 節で重複し GitHub Wiki でアンカが衝突するため、括弧で文脈を補って一意にした。
  • マイクロソフト系技術情報 Wiki(techinfoofmicrosofttech.osscons.jp)への URL リンクは、移行済みの ASP.NET Coreのデプロイ / .NET Coreのデプロイ / WSL上での.NET Core開発 に張り替えた。
  • PukiWiki のページ内アンカ(#xxxxxxxx)は GitHub Wiki では再現できないため、 同一ページ内のアンカは見出しから生成されるアンカに張り替え、 他ページのアンカを指すリンクは「〜(ページ名 の該当節を参照)」の形に置き換えた。

Tags: 移行, ASP.NET Core, .NET Core, Linux, CentOS, Ubuntu, FDD, SCD, nginx, デプロイ

NetDevInfraWiki

マイクロソフト系技術情報 Wiki
Open 棟梁 Wiki

(未着手)

開発基盤部会 Wiki

移行管理: DONETODO

Clone this wiki locally