Skip to content

Instantly share code, notes, and snippets.

@jmelosegui
Created June 16, 2017 13:04
Show Gist options
  • Save jmelosegui/8307e09eae9d96a894c65c823b41db88 to your computer and use it in GitHub Desktop.
Save jmelosegui/8307e09eae9d96a894c65c823b41db88 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Web\Microsoft.Web.Publishing.Tasks.dll" />
<!-- This will allow the config file to be copied to any project referencing the project that need the config transformation -->
<PropertyGroup>
<AllowedReferenceRelatedFileExtensions>
$(AllowedReferenceRelatedFileExtensions);
.dll.config
</AllowedReferenceRelatedFileExtensions>
</PropertyGroup>
<!-- This is needed to apply the transformation before the target that resolves project references -->
<PropertyGroup>
<ResolveReferencesDependsOn>
TransformConfig;
$(ResolveReferencesDependsOn)
</ResolveReferencesDependsOn>
</PropertyGroup>
<Target Name="TransformConfig" BeforeTargets="_CopyAppConfigFile" Condition="Exists('App.Publish.config') AND '$(BuildingInsideVisualStudio)' != 'true' ">
<!--Generate transformed app config in the intermediate directory-->
<TransformXml Source="App.config" Destination="$(IntermediateOutputPath)$(TargetFileName).config" Transform="App.Publish.config" />
<!--Force build process to use the transformed configuration file from now on.-->
<ItemGroup>
<AppConfigWithTargetPath Remove="App.config" />
<AppConfigWithTargetPath Include="$(IntermediateOutputPath)$(TargetFileName).config">
<TargetPath>$(TargetFileName).config</TargetPath>
</AppConfigWithTargetPath>
</ItemGroup>
</Target>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment