「.NET 開発基盤部会 Wiki」は、「Open棟梁Project」,「OSSコンソーシアム .NET開発基盤部会」によって運営されています。
ASP.NET CoreをLinux上にデプロイ
事前に、以下のインストールを行っておく。
xxxxx@xxxxx:~/test_project$ dotnet new web The template "ASP.NET Core Empty" 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/xxxxx/test_project/test_project.csproj... Restoring packages for /home/xxxxx/test_project/test_project.csproj... Generating MSBuild file /home/xxxxx/test_project/obj/test_project.csproj.nuget.g.props. Generating MSBuild file /home/xxxxx/test_project/obj/test_project.csproj.nuget.g.targets. Restore completed in 30.51 sec for /home/xxxxx/test_project/test_project.csproj. Restore succeeded. xxxxx@xxxxx:~/test_project$ ls obj Program.cs Startup.cs test_project.csproj wwwroot xxxxx@xxxxx:~/test_project$ xxxxx@xxxxx:~/test_project$ dotnet run Hosting environment: Production Content root path: /home/xxxxx/test_project Now listening on: http://localhost:5000 Application started. Press Ctrl+C to shut down. xxxxx@xxxxx:~$ curl http://localhost:5000/ Hello World!xxxxx@xxxxx:~$
上記は古い.NET Core 1.0 の手順なので、
.NET Core 2.0 環境ではエラーになる。
手順を以下のとおり改善すると実行できる。
- dotnet new
→ dotnet new web- project.json を編集。
dotnet new で自動生成された project.json というファイルを編集し、dependencies 内に Kestrel を追加します。
→ やらなくていい。(・・・)- Startup.cs を作成。
以下のようなコードを Project.cs と同じ階層に作成します。
→やらなくていい。(・・・)- Program.cs を編集。
次に Program.cs ファイルを以下のように修正します。
→やらなくていい。(・・・)- dotnet restore
→ やらなくていい。(dotnet new webのなかで restorが自動実行される)