简体   繁体   中英

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:

    在此处输入图片说明

  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.

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

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM