简体   繁体   English

ASP.NET更改托管环境以进行开发

[英]Asp net change hosting environment to Development

I'm trying to change my asp.net core hosting environment to development. 我正在尝试将我的asp.net核心托管环境更改为开发。 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. 我只是在projectName.csproj文件中看到注释,说它运行生产 ,也许就是问题所在。

<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. 但是现在我在项目中看到的是Hosting environment:生产环境 ,我想将其更改为环境,因为当我更改HTML,CSS等客户端更改时,我看不到实时更改。

After setting the ASPNETCORE_ENVIRONMENT variable for your system you must open a new command window before running dotnet run . 在为系统设置ASPNETCORE_ENVIRONMENT变量之后,必须在运行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 环境变量在Shell的生命周期内被缓存,因此现有窗口不会接收对环境变量的更改

I wrote a post on how to achieve this here: https://andrewlock.net/how-to-set-the-hosting-environment-in-asp-net-core/#atthecommandline 我在这里写了一篇有关如何实现这一目标的文章: 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: 要在Windows中设置ASPNETCORE_ENVIRONMENT环境变量,请在cmd中运行以下命令:

setx ASPNETCORE_ENVIRONMENT "Development"

Or 要么

Use try in web.config like: web.config使用try,例如:

<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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