Skip to content

Instantly share code, notes, and snippets.

@jonezy
Last active August 29, 2015 14:07
Show Gist options
  • Save jonezy/904b72a3c34bb01b6463 to your computer and use it in GitHub Desktop.
Save jonezy/904b72a3c34bb01b6463 to your computer and use it in GitHub Desktop.
Web Config Transform Snippets
----
This portion goes closer to the top, again valid for web.config based projects
----
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Trunk-Release|AnyCPU'">
<OutputPath>bin\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Test-Release|AnyCPU'">
<OutputPath>bin\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Dev-Debug|AnyCPU'">
<OutputPath>bin\</OutputPath>
</PropertyGroup>
----
This portion goes about half way down in the project definitely, valid for web.config based projects
----
<Content Include="Web.Base.config">
<SubType>Designer</SubType>
</Content>
<Content Include="Web.Dev.config">
<SubType>Designer</SubType>
<DependentUpon>Web.Base.config</DependentUpon>
<IsTransformFile>True</IsTransformFile>
</Content>
<Content Include="Web.Trunk.config">
<SubType>Designer</SubType>
<DependentUpon>Web.Base.config</DependentUpon>
<IsTransformFile>True</IsTransformFile>
</Content>
<Content Include="Web.Test.config">
<SubType>Designer</SubType>
<DependentUpon>Web.Base.config</DependentUpon>
<IsTransformFile>True</IsTransformFile>
</Content>
-----
This block goes at the end of the .csproj file, it's valid for web projects with web.configs
-----
<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v11.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
<PropertyGroup>
<ConfigFileName>Web.$(Configuration.Replace('-Release','').Replace('-Debug','')).config</ConfigFileName>
</PropertyGroup>
<Target Name="AfterCompile" Condition="$(Configuration.Contains('-')) And exists($(ConfigFileName))">
<!-- Generate transformed web config in the intermediate directory -->
<TransformXml Source="Web.Base.config" Destination="Web.config" Transform="$(ConfigFileName)" />
</Target>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment