-
Notifications
You must be signed in to change notification settings - Fork 528
Any new steps to take before dotnet run --urls "http://localhost:5001" would work? #1998
Comments
Thanks for the report. To use the --urls command line args, you can change the public static IWebHost BuildWebHost(string[] args)
{
var configuration = new ConfigurationBuilder().AddCommandLine(args).Build();
return WebHost.CreateDefaultBuilder(args)
.UseConfiguration(configuration)
.UseStartup<Startup>()
.Build();
} The args passed to public Startup(IConfiguration configuration)
{
Console.WriteLine(@"Configuration[""urls""] = ""{0}""", configuration["urls"]);
} The above would print We're looking into having |
I'm closing this since I created aspnet/MetaPackages#221 to track progress on making this work out of the box in future versions. |
Is the IConfiguration service already available in Program.cs after the „.CreateDefaultBuilder(args)“ line, so we can directly do a „.UseUrls(configuration[„urls“])“ in Program.cs ? |
No, you'd have to create your own configuration instance to do that. However, it's circular as UseUrls just writes to config. |
i think public static IWebHost BuildWebHost(string[] args) would also do the trick. i think it doesnt matter if you use the above mentioned variant (by adding .UseConfiguration()) or this one. in the end its all the same. hopefully the development process of .net core stays fast, and next step is fixing all that tiny things like this one, and all the many other small edges and flaws, to raise overall quality of .net core, BEFORE they move on to next big changes and adding new stuff. |
side question: is there a simple layer in .net core, a developer can use here, to get the —urls param value out of args[] without handling the whole thing by yourself, string splitting etc ? to just do a .UseUrls(MagicLayer(args, „urls“)) without writing MagicLayer completely by hand (even when it isnt that much) ? |
AddCommandLine is the only provided API for processing args[]. |
Ah, ok. Thx a lot. Wasnt sure about that. Every day i still face some methods or classes i never realized they exist in .NET Core or EF Core. |
So docs and a lot of places reference this
dotnet run --urls "http://localhost:5001"
as the way to be able to change the listening address via command line. However it does not seem to work at all.We're using
WebHost.CreateDefaultBuilder(args)
so we do include the commandline configuration provider. It should just work then right?The text was updated successfully, but these errors were encountered: