问题
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?
回答1:
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 addingAddCommandLine
extension method forConfigurationBuilder
: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();
来源:https://stackoverflow.com/questions/43412065/run-net-core-application-in-development-from-the-command-line