ASPNETCORE_ENVIRONMENT 在部署时覆盖

ASPNETCORE_ENVIRONMENT overwritten on deploy

我有一个要在测试服务器上远程部署的 dotnet 核心应用程序。 ASPNETCORE_ENVIRONMENT 变量应在远程计算机上设置为 "Development"。每次部署时,ASPNETCORE_ENVIRONMENT 变量都会被 "Develop" 覆盖。每次部署时,我都必须进入 IIS 管理配置编辑器并替换不正确的 ASPNETCORE_ENVIRONMENT 变量。

谁能帮我理解为什么每次部署时都会覆盖这个变量?

这是我的 web.config 文件:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.web>
    <compilation>
      <buildProviders>
        <remove extension=".xml" />
        <add extension=".xml" type="System.Web.Compilation.ForceCopyBuildProvider" />
      </buildProviders>
    </compilation>
  </system.web>
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath="dotnet" arguments=".\WorkersCompensation.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="true">
            <environmentVariables>
                <clear />
                <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
            </environmentVariables>
        </aspNetCore>
  </system.webServer>
</configuration>

这是我的 Dev.pubxml 文件:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <LastUsedBuildConfiguration>Debug</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <SiteUrlToLaunchAfterPublish />
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <PublishFramework>netcoreapp1.0</PublishFramework>
    <UsePowerShell>True</UsePowerShell>

     <publishUrl>\esdev2.elwood.local\D$\Core\WorkersCompensation </publishUrl>
     <DeleteExistingFiles>False</DeleteExistingFiles>
     <ExcludeFoldersFromDeployment>wwwroot\node_modules </ExcludeFoldersFromDeployment>
    <UseMsDeployExe>true</UseMsDeployExe>
  </PropertyGroup>
    <ItemGroup>
      <MsDeploySkipRules Include="SkipNodeModules">
        <AbsolutePath>wwwroot\node_modules</AbsolutePath>
      </MsDeploySkipRules>
    </ItemGroup>
</Project>

我相信我已经为遇到此问题的其他人找到了 issue/solution。

部署的 web.config 文件没有 environmentVariable 条目,直到我在 IIS Admin 中编辑了环境变量。我在我的部署中更改了 web.config 和 web.Debug.config 文件,现在我在 IIS 服务器上获得了正确的环境变量。 web.config 文件应该与我上面问题中的文件匹配,但是 web.Debug.Config 现在看起来像这样:

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <aspNetCore>
    <environmentVariables>
      <clear />
      <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development"  xdt:Locator="Match(name)" />
    </environmentVariables>
  </aspNetCore>
</configuration>