@manhng

Welcome to my blog!

Dotnet cli

July 25, 2021 21:42

Dotnet cli (edit)

Kestrel web server implementation in ASP.NET Core

Kestrel web server implementation in ASP.NET Core | Microsoft Docs

Kestrel is a cross-platform web server for ASP.NET Core. Kestrel is the web server that's included and enabled by default in ASP.NET Core project templates.

Kestrel supports the following scenarios:

  • HTTPS
  • HTTP/2 (except on macOS†)
  • Opaque upgrade used to enable WebSockets
  • Unix sockets for high performance behind Nginx

†HTTP/2 will be supported on macOS in a future release.

Kestrel is supported on all platforms and versions that .NET Core supports.

Host and deploy ASP.NET Core | Microsoft Docs

Set up a process manager

An ASP.NET Core app is a console app that must be started when a server boots and restarted if it crashes. To automate starts and restarts, a process manager is required. The most common process managers for ASP.NET Core are:

Set up a reverse proxy

If the app uses the Kestrel server, Nginx, Apache, or IIS can be used as a reverse proxy server. A reverse proxy server receives HTTP requests from the Internet and forwards them to Kestrel.

Either configuration—with or without a reverse proxy server—is a supported hosting configuration. For more information, see When to use Kestrel with a reverse proxy.

Proxy server and load balancer scenarios

Additional configuration might be required for apps hosted behind proxy servers and load balancers. Without additional configuration, an app might not have access to the scheme (HTTP/HTTPS) and the remote IP address where a request originated. For more information, see Configure ASP.NET Core to work with proxy servers and load balancers.

Dotnet CLI:

dotnet --version

dotnet --info

dotnet --list-sdks

dotnet --list-runtimes

dotnet new webapi --output src/ShopApi

dotnet new webapi --output src/ManageApi

dotnet new webapi --output src/MobileApi

dotnet new classlib --output src/Common

dotnet new mstest --output src/Tests --name ShopApi.Test

dotnet new mstest --output src/Tests --name ManageApi.Test

dotnet new mstest --output src/Tests --name MobileApi.Test

dotnet new sln --output src --name Api

dotnet sln src/Api.sln add src/ShopApi/ShopApi.csproj

dotnet sln src/Api.sln add src/ManageApi/ManageApi.csproj

dotnet sln src/Api.sln add src/MobileApi/MobileApi.csproj

dotnet sln src/Api.sln add src/Common/Common.csproj

dotnet sln src/Api.sln add src/Tests/ShopApi.Test.csproj --solution-folder Tests

dotnet sln src/Api.sln add src/Tests/ManageApi.Test.csproj --solution-folder Tests

dotnet sln src/Api.sln add src/Tests/MobileApi.Test.csproj --solution-folder Tests

C:\Users\manhn\dotnet-core>explorer .

C:\Users\manhn\dotnet-core>devenv src/Api.sln

C:\Users\manhn\dotnet-core>dotnet build src/Api.sln

C:\Users\manhn\dotnet-core>dotnet restore src/Api.sln

C:\Users\manhn\dotnet-core>dotnet publish src/Api.sln

C:\Users\manhn\dotnet-core>dotnet clean src/Api.sln

C:\Users\manhn\dotnet-core>dotnet run --project src/ShopApi/ShopApi.csproj

C:\Users\manhn\dotnet-core>dotnet dev-certs https --clean

C:\Users\manhn\dotnet-core>dotnet dev-certs https --trust

C:\Users\manhn\dotnet-core>setx ASPNETCORE_ENVIRONMENT "Development"

C:\Users\manhn\dotnet-core>start iexplorer https://localhost:5001/swagger/index.html

Dotnet Command Line

C:\Users\manhn\dotnet-core>dotnet --version
5.0.302

C:\Users\manhn\dotnet-core>dotnet --info
.NET SDK (reflecting any global.json):
Version: 5.0.302
Commit: c005824e35

Runtime Environment:
OS Name: Windows
OS Version: 10.0.19042
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\5.0.302\

Host (useful for support):
Version: 5.0.8
Commit: 35964c9215

.NET SDKs installed:
3.1.411 [C:\Program Files\dotnet\sdk]
5.0.202 [C:\Program Files\dotnet\sdk]
5.0.205 [C:\Program Files\dotnet\sdk]
5.0.301 [C:\Program Files\dotnet\sdk]
5.0.302 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.All 2.1.28 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.28 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.28 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs:
https://aka.ms/dotnet-download

C:\Users\manhn\dotnet-core>dotnet --list-runtimes
Microsoft.AspNetCore.All 2.1.28 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.28 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.7 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.28 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.7 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

C:\Users\manhn\dotnet-core>dotnet --list-sdks
3.1.411 [C:\Program Files\dotnet\sdk]
5.0.202 [C:\Program Files\dotnet\sdk]
5.0.205 [C:\Program Files\dotnet\sdk]
5.0.301 [C:\Program Files\dotnet\sdk]
5.0.302 [C:\Program Files\dotnet\sdk]

C:\Users\manhn\dotnet-core>dotnet new --list
Getting ready...
Template Name Short Name Language Tags
-------------------------------------------- ------------------- ---------- ----------------------
Console Application console [C#],F#,VB Common/Console
Class library classlib [C#],F#,VB Common/Library
WPF Application wpf [C#],VB Common/WPF
WPF Class library wpflib [C#],VB Common/WPF
WPF Custom Control Library wpfcustomcontrollib [C#],VB Common/WPF
WPF User Control Library wpfusercontrollib [C#],VB Common/WPF
Windows Forms App winforms [C#],VB Common/WinForms
Windows Forms Control Library winformscontrollib [C#],VB Common/WinForms
Windows Forms Class Library winformslib [C#],VB Common/WinForms
Worker Service worker [C#],F# Common/Worker/Web
MSTest Test Project mstest [C#],F#,VB Test/MSTest
NUnit 3 Test Project nunit [C#],F#,VB Test/NUnit
NUnit 3 Test Item nunit-test [C#],F#,VB Test/NUnit
xUnit Test Project xunit [C#],F#,VB Test/xUnit
Razor Component razorcomponent [C#] Web/ASP.NET
Razor Page page [C#] Web/ASP.NET
MVC ViewImports viewimports [C#] Web/ASP.NET
MVC ViewStart viewstart [C#] Web/ASP.NET
Blazor Server App blazorserver [C#] Web/Blazor
Blazor WebAssembly App blazorwasm [C#] Web/Blazor/WebAssembly
ASP.NET Core Empty web [C#],F# Web/Empty
ASP.NET Core Web App (Model-View-Controller) mvc [C#],F# Web/MVC
ASP.NET Core Web App webapp [C#] Web/MVC/Razor Pages
ASP.NET Core with Angular angular [C#] Web/MVC/SPA
ASP.NET Core with React.js react [C#] Web/MVC/SPA
ASP.NET Core with React.js and Redux reactredux [C#] Web/MVC/SPA
Razor Class Library razorclasslib [C#] Web/Razor/Library
ASP.NET Core Web API webapi [C#],F# Web/WebAPI
ASP.NET Core gRPC Service grpc [C#] Web/gRPC
dotnet gitignore file gitignore Config
global.json file globaljson Config
NuGet Config nugetconfig Config
Dotnet local tool manifest file tool-manifest Config
Web Config webconfig Config
Solution File sln Solution
Protocol Buffer File proto Web/gRPC

C:\Users\manhn\dotnet-core>dotnet new webapi --output src/ShopApi

C:\Users\manhn\dotnet-core>dotnet new webapi --output src/ManageApi

C:\Users\manhn\dotnet-core>dotnet new webapi --output src/MobileApi

C:\Users\manhn\dotnet-core>dotnet new classlib --output src/Common

C:\Users\manhn\dotnet-core>dotnet new sln --help

C:\Users\manhn\dotnet-core>dotnet new sln --output src --name Api

C:\Users\manhn\dotnet-core>dotnet sln add --help

C:\Users\manhn\dotnet-core>dotnet sln src/Api.sln add src/ShopApi/ShopApi.csproj

C:\Users\manhn\dotnet-core>dotnet sln src/Api.sln add src/ManageApi/ManageApi.csproj

C:\Users\manhn\dotnet-core>dotnet sln src/Api.sln add src/MobileApi/MobileApi.csproj

C:\Users\manhn\dotnet-core>dotnet sln src/Api.sln add src/Common/Common.csproj

C:\Users\manhn\dotnet-core>explorer .

C:\Users\manhn\dotnet-core>devenv src/Api.sln
C:\Users\manhn\dotnet-core>dotnet build src/Api.sln
C:\Users\manhn\dotnet-core>dotnet restore src/Api.sln
C:\Users\manhn\dotnet-core>dotnet publish src/Api.sln
C:\Users\manhn\dotnet-core>dotnet clean src/Api.sln
C:\Users\manhn\dotnet-core>dotnet run --project src/ShopApi/ShopApi.csproj
C:\Users\manhn\dotnet-core>dotnet dev-certs https --clean
C:\Users\manhn\dotnet-core>dotnet dev-certs https --trust
C:\Users\manhn\dotnet-core>setx ASPNETCORE_ENVIRONMENT "Development"
C:\Users\manhn\dotnet-core>start iexplorer https://localhost:5001/swagger/index.html

DotNet Templates

Install template

dotnet new --list
dotnet new -i IdentityServer4.Templates
dotnet new -i Skoruba.IdentityServer4.Admin.Templates
dotnet new -i Ardalis.CleanArchitecture.Template

Using template

dotnet new is4aspid --force
dotnet new is4admin --force
dotnet new is4empty --force
dotnet new is4ef --force
dotnet new is4inmem --force
dotnet new is4ui --force
dotnet new skoruba.is4admin --name MyProject --title MyProject --adminemail "admin@example.com" --adminpassword "Pa$$word123" --adminrole MyRole --adminclientid MyClientId --adminclientsecret MyClientSecret --dockersupport true
dotnet new clean-arch

Using the dotnet CLI template

Examples:
dotnet new mvc --auth Individual
dotnet new xunit
dotnet new --help
dotnet new clean-arch --help
dotnet new -i Ardalis.CleanArchitecture.Template

Using the dotnet CLI template

Abc

abc
dotnet new -i Ardalis.CleanArchitecture.Template

Using the dotnet CLI template

Abc

abc
dotnet new -i Ardalis.CleanArchitecture.Template

Using the dotnet CLI template

Abc

abc
dotnet new -i Ardalis.CleanArchitecture.Template

Categories

Recent posts