iis ASPNETCORE_ENVIRONMENT在部署时被覆盖

cu6pst1q  于 2022-11-12  发布在  其他
关注(0)|答案(1)|浏览(120)

我在测试服务器上远程部署了一个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>
mqkwyuun

mqkwyuun1#

我相信我已经为其他有这个问题的人找到了问题/解决方案。

  • 在我编辑IISAdmin中的环境变量之前,部署的web.config文件没有environmentVariable条目。
  • 我修改了部署中的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>

相关问题