无法从命令行更改隼监听端口

无法从命令行更改隼监听端口

问题描述:

我有以下入口点:无法从命令行更改隼监听端口

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为paramete R,应用程序侦听默认端口5000:

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

你使用的是什么确切版本的dotnet? –

+0

@DirkVollmar dotnet --version返回1.0.0-preview2-003121 – Set

+0

请尝试更新到最新版本,然后(如果Oleg的答案尚未解决您的问题)。 –

正确的语法是

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

,而不是

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

详情请参阅the old answer

+2

仍在监听默认端口 – Set

+1

@Set你确定你通过了'--server.urls = http://0.0.0.0:5002'吗?在你更新的问题中,你使用'--server.url'(用's'')。 –

+0

是错误打印(谢谢,问题已解决) – Set