public
Last active

VS 2010 RTM - MSBuild Project file for App.config XML transformations.

  • Download Gist
AppConfig.Transformation.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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- 20110224 : Ryan Milligan : Created OverrideAppConfigWithTargetPath target to fix ClickOnce deploy bug -->
<!-- 20100827 : João Angelo : Fixed bug when using Publish command within Visual Studio -->
<PropertyGroup>
<!-- Prevent circular dependency on Build target -->
<PipelineDependsOnBuild>false</PipelineDependsOnBuild>
<!-- Override project config file name (By default is set to Web.config) -->
<ProjectConfigFileName>App.Config</ProjectConfigFileName>
</PropertyGroup>
 
<!-- The transformation target (TransformWebConfig) in this targets file-->
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.targets" />
 
<!-- Removes the need to set config files Build Action as Content -->
<ItemGroup>
<FilesForPackagingFromProject Include="$(ProjectConfigFileName)">
<DestinationRelativePath>$(ProjectConfigFileName)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
 
<!-- Insert transformation targets in the build process -->
<PropertyGroup>
<BuildDependsOn>
TransformWebConfig;
OverrideAppConfigWithTargetPath;
$(BuildDependsOn);
CopyTransformedConfig
</BuildDependsOn>
</PropertyGroup>
<PropertyGroup>
<TransformedConfig>$(TransformWebConfigIntermediateLocation)\transformed\App.config</TransformedConfig>
</PropertyGroup>
 
<!-- Overrides AppConfigWithTargetPath allowing the transformed config to be used for manifest generation -->
<Target Name="OverrideAppConfigWithTargetPath">
<ItemGroup>
<AppConfigWithTargetPath Remove="@(AppConfigWithTargetPath)" />
<AppConfigWithTargetPath Include="$(TransformedConfig)" Condition="'$(TransformedConfig)'!=''">
<TargetPath>$(TargetFileName).config</TargetPath>
</AppConfigWithTargetPath>
</ItemGroup>
</Target>
 
<!-- Copy transformed file to output directory -->
<Target Name="CopyTransformedConfig" Condition="'$(TargetName)' != ''">
<Copy Condition="Exists('$(TransformedConfig)')"
SourceFiles="$(TransformedConfig)"
DestinationFiles="$(OutputPath)$(TargetName)$(TargetExt).config" />
<Copy Condition="Exists('$(TransformedConfig)') And '$(TargetExt)' == '.exe'"
SourceFiles="$(TransformedConfig)"
DestinationFiles="$(OutputPath)$(TargetName).vshost.exe.config" />
</Target>
 
<!--
Override After Publish to support ClickOnce
AfterPublish target replaces the untransformed config file copied to the
deployment directory with the transformed one
-->
<Target Name="AfterPublish">
<PropertyGroup>
<DeployedConfig>$(_DeploymentApplicationDir)$(TargetName)$(TargetExt).config$(_DeploymentFileMappingExtension)</DeployedConfig>
</PropertyGroup>
<!-- Publish copies the unstransformed App.config to deployment directory so overwrite it -->
<Copy Condition="Exists('$(DeployedConfig)')"
SourceFiles="$(TransformedConfig)"
DestinationFiles="$(DeployedConfig)" />
</Target>
</Project>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.