无法从命令行更改 Kestrel 侦听端口

Cannot change Kestrel listening port from command line

我有以下入口点:

public static void Main(string[] args)
{
    var config = new ConfigurationBuilder()
        .SetBasePath(Directory.GetCurrentDirectory())
        .AddJsonFile("hosting.json", optional: true)
        .AddCommandLine(args)
        .AddEnvironmentVariables()
        .Build();

    var host = new WebHostBuilder()
        .UseConfiguration(config)
        .UseKestrel()
        .UseContentRoot(Directory.GetCurrentDirectory())
        .UseIISIntegration()
        .UseStartup<Startup>()
        .Build();

    host.Run();
}

如果我添加 hosting.json 文件,如

,它会起作用
{
  "server.urls": "http://0.0.0.0:5001"
}

或者如果我定义环境变量(已找到名称 here

SET ASPNETCORE_URLS=https://0.0.0.0:5001

但是如果我将 --server.urls http://0.0.0.0:5001 作为参数传递,应用程序监听默认的 5000 端口:

> dotnet run --server.urls http://0.0.0.0:5001
...
Now listening on: http://localhost:5000

正确的语法是

dotnet run --server.urls=http://0.0.0.0:5001

而不是

dotnet run --server.urls http://0.0.0.0:5001

有关详细信息,请参阅