Mental Jetsam

By Peter Finch

Archive for the ‘.Net Core 2.0’ Category

.Net Core 2.0 Command Line Configuration

Posted by pcfinch on November 24, 2017

To configure a .Net Core 2.0 MVC application from the command line you need to add the following “UseConfiguration()” line to the “BuildWebHost()” function. You can then configure the app using the command line option.

public class Program
{
  public static void Main(string[] args) {
    BuildWebHost(args).Run();
  }
  public static IWebHost BuildWebHost(string[] args) => WebHost
    .CreateDefaultBuilder(args)
    .UseConfiguration(new ConfigurationBuilder().AddCommandLine(args).Build())
    .UseStartup()
    .Build();
  }
}
Some example command line options are :

--server.urls http://*:80
--urls http://localhost:500;http://localhost:501

References

Posted in .Net Core 2.0, Uncategorized | Leave a Comment »