如何将ASPNETCORE_ENVIRONMENT设置为发布asp.net核心应用程序? [英] how to set ASPNETCORE_ENVIRONMENT to be considered for publishing an asp.net core application?
问题描述
如何和在哪里设置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屋!