Skip to content

Instantly share code, notes, and snippets.

@M-Yankov
Created September 8, 2017 12:16
Show Gist options
  • Select an option

  • Save M-Yankov/895c7d19ffefa04b4472d43be58098bd to your computer and use it in GitHub Desktop.

Select an option

Save M-Yankov/895c7d19ffefa04b4472d43be58098bd to your computer and use it in GitHub Desktop.
Web Config Transformation

To set the transformation to work

This document describes how to set transform config XML on Build in Visual Studio without using any Extensions

  • The .csproj file will be modified.
  • WebProject.csproj to see which modifications are required.
  1. It could begin from the web.config
  2. Right click on it and select Add Config Transforms
  3. This will make web.Config parent of web.Debug.Config and web.Release.Config
  4. Unload .csproj file and edit it.
  5. Add <UsingTask TaskName="TransformXML" /> with the correct Assembly file (check WebProject.csproj in this gist)
  6. Then you need to define which files to tansform: Example:
<Target Name="AfterBuild">
  <TransformXml Source="web.config" Destination="web.config" Transform="web.$(Configuration).config" />
</Target>
Resources:
<!-- Use this to make file configuration groupped in the Solution Explorer in Visual studio -->
<!-- The result of this will be that DataConfig.Release.config will became a child of DataConfig.config. But they are on same level in the file system -->
<Content Include="App_Data\Sitefinity\Configuration\DataConfig.Release.config">
<DependentUpon>DataConfig.config</DependentUpon>
</Content>
<!-- This was archivied like this: right click with mouse on Web.Config > Add Config Transforms -->
<None Include="web.Debug.config">
<DependentUpon>web.config</DependentUpon>
</None>
<None Include="web.Release Pro.config">
<DependentUpon>web.config</DependentUpon>
</None>
<None Include="web.Release.config">
<DependentUpon>web.config</DependentUpon>
</None>
<!-- To use the transform functionallity -->
<!-- VisualStudioVersion is declared or defined earlier in the .csproj file -->
<UsingTask TaskName="TransformXML" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Web\Microsoft.Web.Publishing.Tasks.dll"></UsingTask>
<!-- Set which files to transform -->
<Target Name="AfterBuild">
<TransformXml Source="web.config" Destination="web.config" Transform="web.$(Configuration).config" />
</Target>
<!-- This is required too -->
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
@M-Yankov
Copy link
Author

To set attribute debug="true":

<compilation xdt:Transform="SetAttributes(debug)" debug="true" />

This allows you to debug the application

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment