Web.Config Transformations with Web Setup Project - Visual Studio


Web Setup Projects don't normally apply web.config transformations properly. Instead, it simply copies the web.config file(s) as content files. This article details a workaround.

This article was adapted from http://stackoverflow.com/questions/2992778/asp-net-web-config-transformation-wont-work-in-installer.


1. Create the needed web.config transformation files (e.g., web.Debug.config, web.Release.config, etc.).

2. Manually edit web application project file (.CSPROJ file), adding the following code near the end. (You should see comments near the end of the file regarding this.)

<Target Name="AfterBuild">
  <TransformXml Source="Web.config" Transform="$(ProjectConfigTransformFileName)" Destination="Web.Transformed.config" />

3. In the web setup project, select Content files > Exclude filter > add web.config and each web.*.config file.

4. In the web setup project, select File System > Web Application folder > Add file > select web.Transformed.config in the root of your web application project folder

5. In the same screen, rename web.transformed.config to web.config.