Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 555
bAN Avatar asked Jul 05 '11 07:07

bAN


People also ask

How do I add web debug config to Visual Studio?

If you have a web application project, Right-click on web. config and choose Add Config Transform. This will add any config transforms that are missing from your project based on build configurations (i.e. if you have Production and Staging build configs, both will get a transform added).

What is Web debug config and web release config?

The Web. debug. config file stores changes that Microsoft Visual Studio applies to the Web. config file, when you compile the application in the Debug mode. Before you publish the application using release configuration, you need to remove the debug attribute from the <compilation> element in the Web.config file.

How do I debug a config file?

In Solution Explorer, right-click the project and choose Properties. In the side pane, choose Build (or Compile in Visual Basic). In the Configuration list at the top, choose Debug or Release. Select the Advanced button (or the Advanced Compile Options button in Visual Basic).


1 Answers

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.

like image 149
Smudge202 Avatar answered Sep 21 '22 08:09

Smudge202