IT:AD:XDT:HowTo:Transform Web.Config every time we run
Summary
XDT is so magnificent that one wants to use it everywhere – even during Developement.
If one could do that, one could have more than one scenario (Dev, Dev2, Dev3).
- SlowCheetah can do it…but only for
app.config– notweb.config- The explanation as to why not: http://stackoverflow.com/q/16225304/1052767
- There was also (but too complex): http://sedodream.com/2010/11/18/XDTWebconfigTransformsInNonwebProjects.aspx
And then I found:
Process
- Create a new Build Environment, called
Dev(case-sensitive) - Open the web application's
*.csproj - Add:
<PropertyGroup>
<PrepareForRunDependsOn>
$(PrepareForRunDependsOn);
WebConfigTransform;
</PrepareForRunDependsOn>
</PropertyGroup>
<Target Name="WebConfigTransform" Condition="Exists('web.template.$(Configuration).config)">
<Message Text="Configuration: $(Configuration): Web.template.$(Configuration).config" />
<TransformXml Source="Web.template.config" Transform="Web.template.$(Configuration).config" Destination="Web.config" />
</Target>
- Copy the current
web.configand make aweb.template.configfrom it. - Copy one of the XDT documents (eg:
web.dev.config) as a starting point, and name itweb.dev.config - Modify the web.config a little further to tidy things up and make both templates subsets of web.config:
<ItemGroup>
<None Include="Web.Template.config">
<DependentUpon>Web.config</DependentUpon>
</None>
<None Include="Web.Template.Dev.config">
<DependentUpon>Web.config</DependentUpon>
</None>
<None Include="Web.Debug.config">
<DependentUpon>Web.config</DependentUpon>
</None>
<None Include="Web.Release.config">
<DependentUpon>Web.config</DependentUpon>
</None>
</ItemGroup>
- Save the .csproj. At this point you should have
Transforming
- Set your Toolbar/Build/Configuration Manager… to
Dev - Edit the
web.template.config– not theweb.configwhich will get erased/replaced every run time.
Team Considerations
Consider mixing and matching the concepts behind IT:AD:ConnectionStrings:HowTo:Strategies To Share Among Developers
