#Transform web.config on build
- Unload the project
- Edit .csproj
- Append figure 1 to the end of the file just before
</Project>
; v12.0 my change depending on your version of Visual Studio - Save .csproj and reload
- Open configuration manager
- Add a new Configuration Name: Base. Copy settings from: Release
- Copy the contents of your web.config
- Right click Web.Config > Add Config Transformation
- Overwrite the web.base.config with the contents of your clipboard
- 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>
@nordquist yeah it's a nifty trick, but i'd ditch the web.base.config too -- it's abnormal, obtuse, and a solves a pebkac problem by introducing something abnormal, obtuse.. "be a rebel, conform;" i say. the existing industry convention is to have a default, and then transform the default for a particular environment/config/purpose. the default configs live in source control, don't require a build step to exist or be valid, and typically meet the needs of local hosting/debugging (e.g. valid for all developers that would need to punch F5 "out of the box" and expect everything to work.)