Web.config中变换上运行两次发布 [英] Web.config transform is running twice on publish
问题描述
我有一个解决方案,它包括三个Web项目(以及大量的类库项目)。该网站的项目都使用Web.config文件转换为指定每个环境配置。
我的Web.config转换为多个版本的配置文件,命名为Web.UAT.config,Web.Staging.config和Web.Release.config
我建立并从我的CI服务器使用的MSBuild以下参数部署该项目:
/吨:清洁,构建/号码:配置= UAT; DeployOnBuild = TRUE; PublishProfile = UAT
有关完全相同的三个项目之一,在web.config转变似乎得到应用两次,标记元素 XDT:转换=插入
出现两次。展望生成输出,似乎所有三个项目运行以下目标:
preTransformWebConfig
TransformWebConfigCore
PostTransformWebConfig
preProfileTransformWebConfig
但有问题的项目也运行这些目标(后立即上面列出的那些):
ProfileTransformWebConfigCore
PostProfileTransformWebConfig
在 .csproj的
文件的Web项目包括在默认情况下以下内容:
<导入项目=$(VSToolsPath)\ web应用\ Microsoft.WebApplication.targets条件='$(VSToolsPath)'=''!/>
依次导入此文件 \网络\ Microsoft.Web.Publishing.targets
,还根据VSToolsPath(我开发的机器,这相当于 C:\ Program Files文件(x86)的\的MSBuild \ VisualStudio中\ 12.0
)
该文件的有趣片段如下所示:
&LT;'!='ProjectProfileTransformFileName条件='$(ProjectProfileTransformFileName)'==''和'$(PublishProfileName)' ">$(_ProjectConfigFile$p$pfix).$(PublishProfileName)$(_ProjectConfigFileExtension)</ProjectProfileTransformFileName>
&LT;! - 如果$(TransformWebConfigEnabled)也被激活和ConfigTransform和ProfileTransform碰巧有相同的文件名,我们默认$(ProfilefileTransformWebCofnigEnabled)为false,以便它不会做双变换 - &GT;
&LT; ProfileTransformWebConfigEnabled条件='$(ProfileTransformWebConfigEnabled)'==''和'$(TransformWebConfigEnabled)==真与('$(ProjectProfileTransformFileName)'=='$(ProjectConfigTransformFileName)')&GT;假&LT; / ProfileTransformWebConfigEnabled&GT;
双变换发生的事情为 ProfileTransformWebConfigCore
运行,这是有条件的, ProfileTransformWebConfigEnabled
,其中只有默认的结果为false如果 ProjectProfileTransformFileName
和 ProjectConfigTransformFileName
都是平等的。
我增加了以下目标我的三个项目:
&lt;目标名称=DebugWebConfigTransformAfterTargets =preProfileTransformWebConfig&GT;
&LT;消息文本=ProjectProfileTransformFileName:$(ProjectProfileTransformFileName)/&GT;
&LT;消息文本=ProjectConfigTransformFileName:$(ProjectConfigTransformFileName)/&GT;
&LT; /目标&GT;
有关问题的项目,这个目标输出如下:
DebugWebConfigTransform:
ProjectProfileTransformFileName:Web.UAT.config
ProjectConfigTransformFileName:Web.Release.config
由于这两个值均不同,则双变换是存在的对上述理由
在ProjectConfigTransformFilename设置为Web.Release.config的原因是, ProjectConfigurationPlatforms
在我的的.sln
文件是不正确的。该的.sln
文件的配置|平台对 UAT的|任何CPU
被映射到发布|任何CPU
此项目
我认为这是实际应用中的不可用时间的和的释放转变为结果(由于我转换的确切性质和它们被应用的顺序,这是由应用UAT变换区分两次)。
更新 ProjectConfigurationPlatforms
映射解决方案文件为我解决了问题。
I have a solution that includes three web projects (as well as a lot of class library projects). The web projects all use Web.config transforms to specify per-environment configuration.
I have Web.config transforms for multiple build profiles, named Web.UAT.config, Web.Staging.config and Web.Release.config
I am building and deploying the project from my CI server using MSBuild with the following arguments:
/t:Clean,Build /p:Configuration=UAT;DeployOnBuild=True;PublishProfile=UAT
For exactly one of the three projects, the web.config transforms appear to get applied twice, with elements marked xdt:Transform="Insert"
appearing twice. Looking in the build output, it seems that all three projects run the following targets:
PreTransformWebConfig
TransformWebConfigCore
PostTransformWebConfig
PreProfileTransformWebConfig
But the problematic project also runs these targets (immediately after those listed above):
ProfileTransformWebConfigCore
PostProfileTransformWebConfig
The .csproj
files for web projects include the following by default:
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
This file in turn imports \Web\Microsoft.Web.Publishing.targets
, also under the VSToolsPath (on my dev machine, this corresponds to C:\Program Files (x86)\MSBuild\VisualStudio\v12.0
).
The interesting segment of this file looks like the following:
<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>
The double transform was happening as a result of ProfileTransformWebConfigCore
running, which is conditional on ProfileTransformWebConfigEnabled
, which only defaults to false if the ProjectProfileTransformFileName
and ProjectConfigTransformFileName
are equal.
I added the following target to all three of my projects:
<Target Name="DebugWebConfigTransform" AfterTargets="PreProfileTransformWebConfig">
<Message Text="ProjectProfileTransformFileName: $(ProjectProfileTransformFileName)"/>
<Message Text="ProjectConfigTransformFileName: $(ProjectConfigTransformFileName)"/>
</Target>
For the problematic project, this target output the following:
DebugWebConfigTransform:
ProjectProfileTransformFileName: Web.UAT.config
ProjectConfigTransformFileName: Web.Release.config
Since these two values were different, the double transform was occuring for the reasons described above.
The reason the ProjectConfigTransformFilename was set to Web.Release.config was that the ProjectConfigurationPlatforms
in my .sln
file was incorrect. The .sln
file's Configuration|Platform pair of UAT|Any CPU
was being mapped to Release|Any CPU
for this project.
I think it was actually applying the UAT and Release transforms as a result (due to the exact nature of my transforms and the order in which they were applied, this was indistinguishable from applying the UAT transform twice).
Updating the ProjectConfigurationPlatforms
mapping in the solution file resolved the issue for me.
这篇关于Web.config中变换上运行两次发布的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!