Why my web app doesn't use Web.Debug.config in debug running?

15,820

EDIT: Much more refined approach can be found on SO: Use Visual Studio web.config transform for debugging

I had commented that I too would like this feature but hadn't found a way to do it yet. Then decided to have a quick google.

A discussion here has lead me to one possible solution provided by cmac3095:

I don't mess with MSBUILD that much but my solution was to add a custom target to the XXX.Web.csproj that did the transform and then add a custom "Post build" event to the XXX.Web.csproj that invoked MSBUILD (to perform the transform) and an XCOPY to copy the transformed web.config over the original. One side effect is that, as we have TFS, it always contains the last web.config that was transformed which can be a bit usettling (you keep thinking one of your other developers has overwritten your settings - which, in a sense, they have ;-)....but, of course, your settings are in the web.xxxxxx.config you use in the transform. Okay, enough explanation.
Here's what you do: Copy and paste this into you XXXX.Web.csproj just above the commented out "Target Name="BeforeBuild" element...

<UsingTask TaskName="TransformXml"
 AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll"
 />    <Target Name="Transform"> 
     <MakeDir Directories="obj\$(Configuration)"
 Condition="!Exists('obj\$(Configuration)')"
 /> 
     <TransformXml Source="Web.Config" Transform="Web.$(Configuration).config"
 Destination="obj\$(Configuration)\Web.config"
 StackTrace="true" />    </Target>   
 <Target Name="AfterBuild">   
 </Target>

That's it. On the next build of your xxx.web.config, the post build will run the custom target and generate transformed web.config. The XCOPY will overwrite the existing.

Share:
15,820
bAN
Author by

bAN

Software developer interested in everything that can bring a solution to a problem :-)

Updated on July 20, 2022

Comments

  • bAN
    bAN almost 2 years

    Possible Duplicate:
    Use Visual Studio web.config transform for debugging

    I have an asp.net application with three web.config transformations.

    enter image description here

    I was thinking when I launch debug running (F5 with Debug mode selected) the transformations written in the Web.Debug.config will apply.. But it doesn't work.. the Web.config used is the "Base" one.

    You will tell me : "The transformation aren't right".. But they are because when I make a deploy (right click/publish) with debug release config : enter image description here

    The rendered web.config have modifications! So it works, but the debug running is using the base web.config.. Is there a place I can configure that?

  • bAN
    bAN almost 13 years
    Thanks for answer... I was thinking it'll be more simple. Like a visual studio menu.. ;-)
  • Smudge202
    Smudge202 almost 13 years
    In MS's defense, there are plenty of counter arguments to this process. I did see mention of it being included as a feature in a future VS build, but not on an official post so don't quote me.