Asp.NET Core WebAPI 设置环境变量值ASPNETCORE_ENVIRONMENT

默认情况下发布后的环境变量是Production

方式一:

在文件夹PublishProfiles下的FolderProfile.pubxml文件增加配置

<Project>
  <PropertyGroup>
    <EnvironmentName>Development</EnvironmentName>
  </PropertyGroup>
</Project>

表示发布后通过builder.Environment.EnvironmentName获取到的环境变量是Development

注:这种方式会在发布后web.config文件中自动增加配置节environmentVariables

 

方式二:在直接在web.config文件中增加配置节environmentVariables

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet" arguments=".\MonitorSystem.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess">
        <environmentVariables>
          <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
        </environmentVariables>
      </aspNetCore>
    </system.webServer>
  </location>
</configuration>

 

posted @ 2024-07-09 15:46  流年sugar  阅读(1)  评论(0编辑  收藏  举报