2015-07-21 18 views
5

我有一個包含三個Web項目(以及許多類庫項目)的解決方案。 Web項目都使用Web.config轉換來指定每個環境的配置。Web.config轉換在發佈上運行兩次

我有Web.config文件轉換爲多個生成配置文件,命名爲Web.UAT.config,Web.Staging.config和Web.Release.config

我建立和使用的MSBuild我的CI服務器部署的項目具有下列參數:

/t:Clean,Build /p:Configuration=UAT;DeployOnBuild=True;PublishProfile=UAT 

了整整三個項目之一,在web.config變換似乎得到應用兩次,元素標記xdt:Transform="Insert"出現兩次。展望構建輸出,似乎所有三個項目運行以下目標:

PreTransformWebConfig 
TransformWebConfigCore 
PostTransformWebConfig 
PreProfileTransformWebConfig 

但有問題的項目也運行這些目標(後立即上面列出的那些):

ProfileTransformWebConfigCore 
PostProfileTransformWebConfig 

回答

5

.csproj文件對於Web項目默認包括以下內容:

<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" /> 

該文件反過來進口\Web\Microsoft.Web.Publishing.targets,也VSToolsPath下(在我的開發機器上,這對應於C:\Program Files (x86)\MSBuild\VisualStudio\v12.0)。

此文件的有趣片段如下所示:

<ProjectProfileTransformFileName Condition="'$(ProjectProfileTransformFileName)'=='' And '$(PublishProfileName)' != '' ">$(_ProjectConfigFilePrefix).$(PublishProfileName)$(_ProjectConfigFileExtension)</ProjectProfileTransformFileName> 

<!--if $(TransformWebConfigEnabled) is also enabled and the ConfigTransform and ProfileTransform happen to have same filename, we default $(ProfilefileTransformWebCofnigEnabled) to false so it doesn't do double transform--> 
<ProfileTransformWebConfigEnabled Condition="'$(ProfileTransformWebConfigEnabled)'=='' And '$(TransformWebConfigEnabled)' == 'true' And ('$(ProjectProfileTransformFileName)' == '$(ProjectConfigTransformFileName)')">False</ProfileTransformWebConfigEnabled> 

雙變換髮生的事情爲ProfileTransformWebConfigCore運行,這是有條件的ProfileTransformWebConfigEnabled,只默認爲false的結果,如果ProjectProfileTransformFileNameProjectConfigTransformFileName是平等的。

我增加了以下目標我的三個項目:

<Target Name="DebugWebConfigTransform" AfterTargets="PreProfileTransformWebConfig"> 
    <Message Text="ProjectProfileTransformFileName: $(ProjectProfileTransformFileName)"/> 
    <Message Text="ProjectConfigTransformFileName: $(ProjectConfigTransformFileName)"/> 
    </Target> 

對於有問題的項目,這個目標輸出如下:

DebugWebConfigTransform: 
    ProjectProfileTransformFileName: Web.UAT.config 
    ProjectConfigTransformFileName: Web.Release.config 

由於這兩個值是不同的,雙出於上述原因發生轉變。

ProjectConfigTransformFilename設置爲Web.Release.config的原因是我的.sln文件中的ProjectConfigurationPlatforms錯誤。該項目的.sln文件的配置|平臺對UAT|Any CPU映射到Release|Any CPU。我認爲它實際上是應用UAT 因此發佈變換(由於我的變換的確切性質以及它們的應用順序,這與應用UAT變換兩次是無法區分的)。

更新解決方案文件中的ProjectConfigurationPlatforms映射爲我解決了問題。

0

這個問題發生在我身上,因爲我的解決方案配置中有多個項目使用不同的配置。

它運行一個以上的web.config文件轉換因爲這個結構:

Configuration Manager

切換項目中使用我不再收到我的web.config的問題上有着相同的配置之後。