如何将ASPNETCORE_ENVIRONMENT设置为发布asp.net核心应用程序? [英] how to set ASPNETCORE_ENVIRONMENT to be considered for publishing an asp.net core application?

查看:808
本文介绍了如何将ASPNETCORE_ENVIRONMENT设置为发布asp.net核心应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我将我的asp.net核心Web应用程序发布到我的本地文件系统时,它总是需要使用production = config和ASPNETCORE_ENVIRONMENT变量,值为Production。



如何和在哪里设置ASPNETCORE_ENVIRONMENT变量的值,以便它不仅被认为是调试,而且也被用于发布?我已经尝试以下选项没有成功:




  • 在Windows设置

  • 在.pubxml文件

  • 在project.json中的launchSettings.json



解决方案

Option1:



要在Windows中设置ASPNETCORE_ENVIRONMENT环境变量, b
$ b

命令行 - setx ASPNETCORE_ENVIRONMENT开发



PowerShell - $ Env:ASPNETCORE_ENVIRONMENT =开发



对于其他操作系统,请参阅 - https://docs.microsoft.com/en-us/aspnet/core/fundamentals/environments



Option2:



如果要使用设置ASPNETCORE_ENVIRONMENT web.config 然后添加 aspNetCore 这样 -

 <结构> 
<! -
在appsettings.json中配置您的应用程序设置。了解更多信息,请访问http://go.microsoft.com/fwlink/?LinkId=786380
- >
< system.webServer>
<处理程序>
< add name =aspNetCorepath =*verb =*modules =AspNetCoreModuleresourceType =未指定/>
< / handlers>
< aspNetCore processPath =。\MyApplication.exearguments =stdoutLogEnabled =falsestdoutLogFile =。\logs\stdoutforwardWindowsAuthToken =false>
< environmentVariables>
< environmentVariable name =ASPNETCORE_ENVIRONMENTvalue =开发/>
< / environmentVariables>
< / aspNetCore>
< /system.webServer>
< / configuration>


when i publish my asp.net core web application to my local file system, it always takes the production-config and the ASPNETCORE_ENVIRONMENT variable with the value = "Production".

how and where do i have to set the value of the ASPNETCORE_ENVIRONMENT variable so that it will be considered not only for debugging, but also for the publishing? i already tried the following options without success:

  • in windows settings
  • in .pubxml file
  • in launchSettings.json
  • in project.json

解决方案

Option1:

To set the ASPNETCORE_ENVIRONMENT environment variable in windows,

Command line - setx ASPNETCORE_ENVIRONMENT "Development"

PowerShell - $Env:ASPNETCORE_ENVIRONMENT = "Development"

For other OS refer this - https://docs.microsoft.com/en-us/aspnet/core/fundamentals/environments

Option2:

If you want to set ASPNETCORE_ENVIRONMENT using web.config then add aspNetCore like this-

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

这篇关于如何将ASPNETCORE_ENVIRONMENT设置为发布asp.net核心应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆