I use below code to add CommandLine in my .Net-Core 1.2 environment, I can use the command line like dotnet run --urls "http://a.cn.com:5000" --environment "Production"
.
public static void Main(string[] args)
{
var config = new ConfigurationBuilder()
.AddJsonFile("hosting.json", optional: true)
.AddCommandLine(args)
.Build();
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.UseConfiguration(config)
.Build();
host.Run();
}
And After migrate to .net core 2.0 it becomes like that
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args)
{
return WebHost.CreateDefaultBuilder(args)
.ConfigureLogging((context, logging) =>
{
logging.AddSerilog();
})
.UseStartup<Startup>()
.Build();
}
I use the same command line ,it fails.
How to add the Command in .net core 2.0 ?
Supply: 2017.08.17
launchsetting.json below :
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:5005/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Robert.Project.Web": {
"commandName": "Project",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:5006"
}
}
}
What I expect the listening is
Now listening on http://a.cn.com:5000
What I get is that:
And we should not add any other code in Program.cs
file, cause CreateDefaultBuilder is contain addCommandLine. for more detail, you can see WebHost.cs#L177
Supply 2017 0817 17:44 UTC+8
[::] is the IPv6 equivalent of IPv4 0.0.0.0.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…