it:ad:xdt:howto:transform_web.config_every_time_we_run

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).

And then I found:

  • 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.config and make a web.template.config from it.
  • Copy one of the XDT documents (eg: web.dev.config) as a starting point, and name it web.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

  • Set your Toolbar/Build/Configuration Manager… to Dev
  • Edit the web.template.config – not the web.config which will get erased/replaced every run time.

Consider mixing and matching the concepts behind IT:AD:ConnectionStrings:HowTo:Strategies To Share Among Developers

  • /home/skysigal/public_html/data/pages/it/ad/xdt/howto/transform_web.config_every_time_we_run.txt
  • Last modified: 2023/11/04 02:03
  • by 127.0.0.1