Monday, August 20, 2012

Transforming web.config


  • Make sure the a build option exists for the build you want (Eg. Release, Deployment)
  • All xml changes below happen in ProjectName.csproj
  • Add Web.Base.Config, by adding
    • <Content Include="Web.Base.config">
    •     <SubType>Designer</SubType>
    •  </Content>
  • Make all Configs point to it
    • <Content Include="Web.Debug.config">
    •      <DependentUpon>Web.Base.config</DependentUpon>
    •     </Content>
  • Leave the original Web.Config
    • <Content Include="Web.config" />  
  • Add the transform step
    • <Target Name="BeforeBuild">
    •   <TransformXml Source="Web.Base.config" Transform="Web.$(Configuration).config" Destination="Web.config" />
    • </Target>
  • Add Web.Release.Config (for a Release deployment)
    • <?xml version="1.0"?>
    •   <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    •     <connectionStrings>
    •       <add name="DbConn"  xdt:Transform="Remove" xdt:Locator="Match(name)"/>
    •     </connectionStrings>
    •   <system.web>
    •     <compilation xdt:Transform="RemoveAttributes(debug)" />
    •   </system.web>
    •  </configuration>
References:

No comments: