问题
how can I start the ASP.NET Core with the dotnet CLI samples so that they don't listen to the localhost?
This command doesn't work:
dotnet run --server.urls=http://*:5000
回答1:
What you're trying to do requires you to add command-line args to your configuration in the Main
method of your application. Add something like this before you create your WebHostBuilder
object:
var config = new ConfigurationBuilder()
.AddCommandLine(args)
.Build();
And then add this to the WebHostBuilder
object before calling .Build()
on it:
.UseConfiguration(config)
You'll also need to add a dependency to project.json:
"Microsoft.Extensions.Configuration.CommandLine": "1.0.0-rc2-final",
And finally, add a using statement to the file that your Main
method is in:
using Microsoft.Extensions.Configuration;
Example Main
method:
public static void Main(string[] args)
{
var config = new ConfigurationBuilder()
.AddCommandLine(args)
.Build();
var host = new WebHostBuilder()
.UseKestrel()
.UseConfiguration(config)
.UseStartup<Startup>()
.Build();
host.Run();
}
来源:https://stackoverflow.com/questions/37289816/how-to-start-a-asp-net-core-1-0-rc2-app-that-doesnt-listen-to-the-localhost