aspnet / MetaPackages

[Archived] NuGet meta packages. Project moved to https://github.com/aspnet/AspNetCore
Apache License 2.0
211 stars 109 forks source link

WebHost.CreateDefaultBuilder(args) should populate WebHost config from args #221

Closed halter73 closed 6 years ago

halter73 commented 7 years ago

aspnet/KestrelHttpServer#1998 brought this issue to my attention. I posted a fairly simple workaround there.

It would be more intuitive to populate the WebHostBuilder config/settings in addition to the app config with the args passed into WebHost.CreateDefaultBuilder(args).

This would make dotnet run --urls "http://localhost:5001" work out of the box.

leak commented 6 years ago

Does this include populating urls from the appconfig.json?

As mentioned here https://github.com/aspnet/Hosting/issues/1230

halter73 commented 6 years ago

@leak This issue is proposing a smaller change. In our templates, appsettings.json isn't read until after the WebHost is built, so it would take a pretty significant change to our templates to make your suggestion work.

Populating endpoints from config is a known pain point, and we're tracking progress on that front in aspnet/KestrelHttpServer#1290.

halter73 commented 6 years ago

@leak In the meantime, I recommend using the workaround suggested in https://stackoverflow.com/a/44118610/719967.

dasMulli commented 6 years ago

I'm assuming this is the reason why --environment Development and similar also doesn't do much? this would be great to have when deploying windows services for different environments where setting env vars is hard.

Tratcher commented 6 years ago

@dasMulli yes. Here's the workaround from the linked issue:

public static IWebHost BuildWebHost(string[] args)
{
    var configuration = new ConfigurationBuilder().AddCommandLine(args).Build();

    return WebHost.CreateDefaultBuilder(args)
        .UseConfiguration(configuration)
        .UseStartup<Startup>()
        .Build();
}