-
Notifications
You must be signed in to change notification settings - Fork 1
/
Website.TransformXml.targets
46 lines (34 loc) · 2.18 KB
/
Website.TransformXml.targets
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<!--
***********************************************************************************************
Website.TransformXml.targets
Transform any xml files located in publish root folder using xdt.
[Naming convention]
[filename].[extension].{Configuration}|Any].{XmlTransformFilePostfix}
Ex.
web.config.any.xdt
web.config.debug.xdt
somefile.xml.any.xdt
web.config.release.xdt
[Anders Laub // Laub+Co]
***********************************************************************************************
-->
<Project>
<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(MSBuildToolsVersion)\Web\Microsoft.Web.Publishing.Tasks.dll" />
<Target Name="RunTransforms" AfterTargets="WebPublish">
<PropertyGroup>
<PublishRootDirectory Condition="!HasTrailingSlash('$(PublishRootDirectory)')">$(PublishRootDirectory)\</PublishRootDirectory>
</PropertyGroup>
<ItemGroup>
<SourceTransformFiles Include="**\*.$(Configuration).$(XmlTransformFilePostfix);**\*.Any.$(XmlTransformFilePostfix)" />
<TransformFiles Include="%(SourceTransformFiles.Identity)">
<DestinationFile Condition="'@(SourceTransformFiles)'!=''">$(PublishRootDirectory)%(RelativeDir)$([System.Text.RegularExpressions.Regex]::Match(%(Filename), `.*?\.config`))</DestinationFile>
</TransformFiles>
</ItemGroup>
<Message Importance="High" Text="Transforming %(TransformFiles.RelativeDir)%(TransformFiles.Identity) into %(TransformFiles.DestinationFile)" Condition="'@(SourceTransformFiles)'!=''" />
<Warning Text="Could not find destination file %(TransformFiles.DestinationFile) for %(TransformFiles.Identity)" Condition="'@(SourceTransformFiles)'!='' And !Exists(%(TransformFiles.DestinationFile))" />
<TransformXml Source="%(DestinationFile)"
Transform="%(FullPath)"
Destination="%(DestinationFile)"
Condition="'@(TransformFiles)'!='' And Exists(%(DestinationFile))" />
</Target>
</Project>