Search code examples
asp.net-core.net-coredotnet-cli.net-core-rc2

dotnet run OR dotnet watch with development environment from command line?


I am using dotnet watch command to run asp.net core project. However, by default, it is picking up the Production as an environment.

I have tried both options using:

1) > dotnet watch ASPNETCORE_ENVIRONMENT=Development

2) > dotnet run ASPNETCORE_ENVIRONMENT=Development

But it still picks up production as an environment.

Note: In visual studio environment variable is set in project properties as Development by default and running from visual studio picks that variable.

Question is: How to run dotnet core project in development from command line using either?:

1) dotnet run
2) dotnet watch

Solution

  • ASPNETCORE_ENVIRONMENT is an environment variable (and AFAIK) not a switch to the dotnet cli.

    So what you would do is set it prior to using the tool:

    rem Windows
    C:\> set ASPNETCORE_ENVIRONMENT=Development
    C:\> dotnet ...
    
    rem Unix
    $ export ASPNETCORE_ENVIRONMENT=Development
    $ dotnet ...