Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp net change hosting environment to Development

I'm trying to change my asp.net core hosting environment to development. What I already did is :

  1. Run this command:

    set ASPNETCORE_ENVIRONMENT=Development
    
  2. Change the environment variables in system:

    enter image description here

  3. Run these commands:

    dotnet restore
    
    dotnet watch run 
    

I just see in the projectName.csproj file there is comment that say that it run the production, maybe that's the problem.

<Target Name="RunWebpack" AfterTargets="ComputeFilesToPublish">
<!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
<Exec Command="npm install" />
<Exec Command="node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js --env.prod" />
<Exec Command="node node_modules/webpack/bin/webpack.js --env.prod" />

But for now what I see in my project is Hosting environment : Production and I want to change it to environment because I can't see the changes in live when I change client side changes like HTML, CSS.

like image 985
Manspof Avatar asked Aug 10 '17 19:08

Manspof


People also ask

How do you check if current environment is development or not?

If you need to check whether the application is running in a particular environment, use env. IsEnvironment("environmentname") since it will correctly ignore case (instead of checking if env. EnvironmentName == "Development" for example).


2 Answers

To set the ASPNETCORE_ENVIRONMENT environment variable in windows, run this command in cmd:

setx ASPNETCORE_ENVIRONMENT "Development"

Or

Use try in web.config like:

<configuration>
<!--
Configure your application settings in appsettings.json. Learn more at http://go.microsoft.com/fwlink/?LinkId=786380
 -->
<system.webServer>
    <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath=".\MyApplication.exe" arguments="" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false">
        <environmentVariables>
            <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
        </environmentVariables>
    </aspNetCore>
</system.webServer>
</configuration>
like image 95
stefan Avatar answered Sep 27 '22 20:09

stefan


After setting the ASPNETCORE_ENVIRONMENT variable for your system you must open a new command window before running dotnet run.

Environment variables are cached for the lifetime of the shell, so an existing window won't pick up changes to the environment variable

I wrote a post on how to achieve this here: https://andrewlock.net/how-to-set-the-hosting-environment-in-asp-net-core/#atthecommandline

like image 32
Sock Avatar answered Sep 27 '22 20:09

Sock