Add Command Support
To create a new ASP. NET Core project, open Program.cs Add the following code:
public class Program{ public static void Main(string[] args) { BuildWebHost(args).Run(); } public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args) .UseConfiguration(new ConfigurationBuilder().AddCommandLine(args).Build()) .UseStartup<Startup>() .Build();}
The main thing is this code:UseConfiguration(new ConfigurationBuilder().AddCommandLine(args).Build())
Publish Project
Publish a dotnet publish -c Release project by command
Specifying the listening address and environment variables
We're going to start running.dotnet WebApplication1.dll
We can see that the default listener address is http://localhost:5000 , the default environment variable isProduction
We can --server.urls 监听地址 create a listening address by --environment 环境变量 specifying the environment variable
Like what:dotnet WebApplication1.dll --server.urls http://*:8080 --environment Staging
Reference: https://www.cnblogs.com/linezero/p/aspnetcorekestrelurls.html
Command-controlled listening address and environment variables after ASP.