Skip to content

Instantly share code, notes, and snippets.

@VladoMS
Forked from EdCharbeneau/Enable-Transformations.md
Created January 12, 2017 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VladoMS/779bae9d911ffe2ac615cc9c7c4bfc1a to your computer and use it in GitHub Desktop.
Save VladoMS/779bae9d911ffe2ac615cc9c7c4bfc1a to your computer and use it in GitHub Desktop.
How to enable transformations on build with Visual Studio

#Transform web.config on build

  1. Unload the project
  2. Edit .csproj
  3. Append figure 1 to the end of the file just before </Project>; v12.0 my change depending on your version of Visual Studio
  4. Save .csproj and reload
  5. Open configuration manager
  6. Add a new Configuration Name: Base. Copy settings from: Release
  7. Copy the contents of your web.config
  8. Right click Web.Config > Add Config Transformation
  9. Overwrite the web.base.config with the contents of your clipboard
  10. From now on Web.Config will be overwritten using transformations.

For settings that apply to all cofigurations use Base
For settings that apply only to Release use Release
For settings that apply only to Debug use Debug

A helpful note to add to your projects [base|debug|release].config

<!-- WEB CONFIG IN THIS PROJECT SHOULD ONLY BE MODIFIED BY -->
<!-- web.base.config -->
<!-- web.debug.config -->
<!-- web.release.config -->
<!-- CHANGES MADE DIRECTLY TO THE web.config WILL BE OVERWRITTEN -->

####Figure 1 Copy and paste:

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v12.0\WebApplications\Microsoft.WebApplication.targets" />
<Target Name="BeforeBuild">
    <TransformXml Source="Web.Base.config" Transform="Web.$(Configuration).config" Destination="Web.config" />
</Target>     
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment