Using Kestrel, you can specify the port using the hosting.json file.
Add .json hosting with the following content to the project:
{
"server.urls": "http://0.0.0.0:5002"
}
publishOptions project.json
"publishOptions": {
"include": [
"hosting.json"
]
}
".UseConfiguration(config)" WebHostBuilder:
public static void Main(string[] args)
{
var config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("hosting.json", optional: true)
.Build();
var host = new WebHostBuilder()
.UseConfiguration(config)
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
}