开发者

How to use MSbuild property in TransformXml task?

I'm using MsBuild and the TransformXml task to set up some web.config files. That's all working completely fine, but now I want to expand a MSBuild property within the xml transformation.

To be more clear, I batch the TransformXml task using an itemgroup to do several transformations for multiple web sites that just differ in configuration:

<PropertyGroup>
  <WebsiteTargetDirectory>$(MSBuildProjectDirectory)\BUILD\</WebsiteTargetDirectory>
</PropertyGroup>

<ItemGroup>
  <WebsitesToBeCopied Include="CH;DE;EN">
    <InProject>false</InProject>开发者_C百科;
  </WebsitesToBeCopied>
</ItemGroup>

<target name="CreateWebConfigs">
  <TransformXml
    Source="$(MSBuildProjectDirectory)\Web.Template.config"
    Transform="$(MSBuildProjectDirectory)\Web.%(WebsitesToBeCopied.Identity).config"
    Destination="$(WebsiteTargetDirectory)\%WebsitesToBeCopied.Identity)\Web.config"
  />
</target>

This is working totally fine, but I could spare several lines and transformations if there was a possibility to get some MSBuild properties in transformation. For example I need to get the 'DE', 'EN' or 'CH' appended to an attribute value, and it would be nice to simply use a placeholder in the template instead of writing an transformation for every web.config.

Is there a way to achieve this and if yes, how would that work?


I found a workaround solution by myself.

Right after the TransformXml task I can use the Detokenise task from the MSBuildExtensionPack to put my variables into the transformed file in a second step. I just have to use the original $(PropertyName) syntax as placeholders in the file and the additional tasks automatically replaces them.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜