1

I know I can configure some settings in Visual Studio or Visual Studio Code to launch my asp .net core application in development mode. But I've had a horrible experience with all the build tools, and so far running from the command line is the only one working for me.

The big problem I have with the command line is getting it to run in Development mode. If I understand, this can only be done by typing set ASPNETCORE_ENVIRONMENT=Development before dotnet watch run or by setting system wide environment variables. There's gotta be another way, like through a file or something.

How can I run in Development mode from the command line, so I can include this in say a package.json of an Aurelia project?

Matthew James Davis
  • 12,134
  • 7
  • 61
  • 90

1 Answers1

8

You may use --environment argument with dotnet run to specify hosting environment:

 dotnet run --environment "Development"

But this will work only after you modify host building to use configuration with command line arguments as config source.

  • add dependency to Microsoft.Extensions.Configuration.CommandLine package
  • add to main method the config creation based on arguments by adding AddCommandLine extension method for ConfigurationBuilder :

    var config = new ConfigurationBuilder()  
       .AddCommandLine(args)
       .Build();
    
  • use configuration by adding .UseConfiguration(config) step during host setup.

    var host = new WebHostBuilder()  
       .UseConfiguration(config)
       .UseKestrel()
       .UseContentRoot(Directory.GetCurrentDirectory())
       .UseIISIntegration()
       .UseStartup<Startup>()
       .Build();
    
Set
  • 47,577
  • 22
  • 132
  • 150
  • thansk for the response, i like the solution, but i can't get it to work. i added the Microsoft.Extensions.Configuration.CommandLine reference: " " but AddCommandLine is not a valid method. Any ideas? – Matthew James Davis Apr 20 '17 at 11:25
  • @MatthewJamesDavis don't forget to do package restore and add `using Microsoft.Extensions.Configuration;` – Set Apr 20 '17 at 11:31