ASPNETCORE_ENVIRONMENT在部署时被覆盖

时间:2017-05-18 17:56:27

标签: iis asp.net-core-1.1

我有一个dotnet核心应用程序,我在测试服务器上远程部署。 ASPNETCORE_ENVIRONMENT变量应设置为"开发"在远程机器上。每次部署时,ASPNETCORE_ENVIRONMENT变量都被" Develop"覆盖。每次部署时,我都必须进入IIS Admin Configuration Editor并替换错误的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>

1 个答案:

答案 0 :(得分:0)

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

在IIS Admin中编辑环境变量之前,部署的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>