Debug and Release Builds in ASP.NET 2.0

Tuesday, November 15, 2005

One of the adjustments to make when moving from ASP.NET 1.1 to 2.0 is how to produce debug and release builds.

1.1

In 1.1 we had the Build -> Configuration Manager menu option. This command launched a dialog box to let you choose from the available build configurations. Visual Studio provided Debug and Release configurations by default. The configuration selected in the Configuration Manager would tell Visual Studio how to compile the code-behind files. A successful compilation would produce a single assembly (.dll) in the bin directory, with a debugging symbol file (.pdb) appearing if the configuration asked for debugging symbols

Sometime later, the application would receive a web request and begin to execute. At this point, the ASP.NET runtime would generate code for the web forms and user controls in the application, then compile the generated code. The compilation at runtime would use the debug setting in the compilation section of web.config to determine if it should compile optimized code, or debug code (with symbols). ASP.NET would place the results underneath the Temporary ASP.NET Files directory. It is important to select the Release configuration in VS.NET 2003 and set debug=”false” in web.config to produce a true production build in 1.1.

2.0

Here is the most important concept to come to terms with in 2.0: Visual Studio 2005 knows nothing about compiling a web application. In 1.1 VS built the code-behind and ASP.NET built the web forms. In 2.0 Visual Studio 2005 delegates all compilation responsibilities to the ASP.NET platform.

With that in mind, there are two scenarios to talk about: building a web application without a Web Site Deployment project, and building a web application with the Web Site Deployment project. Let’s start with “without”.

When you ask Visual Studio to build a web project, nothing seems to happen. You don’t get the comforting feeling of having a bin directory with a .dll file inside. This is because ASP.NET, not Visual Studio, performs the build. ASP.NET builds everything, including .cs and .vb code files. ASP.NET places all the resulting assemblies in a folder underneath the Temporary ASP.NET files directory. You’ll see the results of the build if you poke around in the directory.

Because ASP.NET does all of the compilation, the debug setting in the compilation section of web.config controls debug or release mode. Compile with debug=”true” and you’ll find the .pdb debugging symbol files alongside each assembly.

This new compilation model makes the Configuration Manager for a web site obsolete. The only option appearing in a Visual Studio 2005 web site “project” is a Debug configuration. Don’t fret – it means nothing. The web.config file now rules the school.

When you are ready to deploy, you can publish the web site. The Publish command (Build -> Publish) will precompile a web application and place the results into a directory of your choosing. You can also publish to an IIS or FTP location. When you select the Publish command you’ll see a dialog box to choose a destination, and options for strong naming, fixed naming, etc. These options map directly to switches for the command line aspnet_compiler tool (see my article for more details). The aspnet_compiler tool also provides a switch to produce debugging symbols, but this option is not available from the Publish dialog. Publish will always precompile a release build without debugging symbols.

Note: the Publish command does not change the debug setting in web.config. The Publish command always compiles for “release”, however, if you precompile to an updateable web site, and then update the web site in place (which results in dynamic compilations), those dynamic compilations will produce debug code and pdb files.

The new Web Site Deployment (WSD) project changes the above scenario slightly. The WSD adds Release and Debug configurations to the Visual Studio 2005 configuration manger. This does not mean that Visual Studio knows how to compile a web site. Instead, Visual Studio knows how to use the MSBuild file provided by WSD to ask for Debug and Release builds. You can now select Debug or Release from the Configuration Manager in Visual Studio. The build request ultimately arrives at the same aspnet_compiler tool described above, and used by the Publish command.

Unlike the Publish command, a WSD Release build will change the debug setting of web.config to false. The WSD also defaults to placing release builds in a Release directory and debug builds in a Debug directory, which is familiar to anyone using .NET outside of web forms. WSD is an awesome tool and I'm sure will be covered in more detail here (eventually).

In conclusion, you control debug and release builds using the debug attribute of the compilation section in web.config – unless you are precompiling the website with the Publish command or the Web Site Deployment tool. The WSD will let you select Debug or Release builds, precompiles the site, and modifies web.config appropriately.


Comments
Bill Thursday, November 17, 2005
Nice buddy ;-)
JasonBSteele Friday, November 18, 2005
At last... its all starting to make sense! Cheers for this :)
scott Friday, November 18, 2005
You are quite welcome, Jason!
Jim Friday, November 18, 2005
Thank You!!

I have been wondering why I only see a Debug build. And I have been wondering if when I published if I was getting a debug or release build.

Thanks again for clearing that up (and saving me some time figuring it out! <grin>)
William Robertson Saturday, November 19, 2005
I used to use a lot of this code in my web development.

#if DEBUG
#else
#endif

This keep emails and other functionality reduced when in development. Should I find something else, or is there a way to define compiler variables like the old days?
Steve Saturday, November 19, 2005
Good stuff. The shame is that MS requires Team System for TDD programming. Hello, MS, wake up. I should have TDD capability out of my VS 2005 Pro version without a need for Team System.
scottgu@microsoft.com Sunday, November 20, 2005
Hi William,

You can continue to use #if DEBUG in your pages and classes. These are driven by the value of your <compilation debug="true"/> setting now.

Hope this helps,

Scott
Felix Monday, December 5, 2005
How can I switch between connectionstrings ( stored in web.config ) depending on the fact that the site is in Debug or Release build ?
Scott Allen Tuesday, December 6, 2005
Felix:

First I'd check out how to use the configSource attribute, that let's you break out settings into distinct files (say one for release, one for debug). I have some examples here: http://odetocode.com/Articles/418.aspx

I'd also check out the web deployment projects. They let you do web.config replacements at build time:
msdn.microsoft.com/.../default.aspx
Tim Wednesday, December 7, 2005
Thanks for the info Scott! This is especially important to realize Publish does not give debug symbols for remote debugging of code-behind files. Very helpful.
Zerosleep Wednesday, December 7, 2005
Great stuff Scott. Saved me lots of time today.
anselme Sunday, December 11, 2005
thank you but in my C:\Inetpub\wwwroot\Anselme\bin

i get :
App_global.asax.dll
App_Web_flt_jsha.dll
App_Code.dll

in bin/en-us iget :
App_GlobalResources.resources.dll
Anselme.resources.dll


how can i get a dll with my application name ? Anseme.dll

I must distribuate an intranet and i need the application name

thank you
scott Thursday, December 15, 2005
Anselme:

You want to use the web site deployment tool - it will let you merge the assemblies into a single assembly (although not the resource assemblies, I don't think).
Bill Tuesday, January 17, 2006
In my ASP.NET 1.1 application, I had setup multiple configuration blocks like so..

<DevConfigurationSettings>
<add key="Environment" value="Dev" />
....
</DevConfigurationSettings>

<BetaConfigurationSettings>
<add key="Environment" value="Beta" />
....
</BetaConfigurationSettings>

<LiveConfigurationSettings>
<add key="Environment" value="Live" />
....
</LiveConfigurationSettings>

All the key names are the same in each section, I determine which settings to load with a key name under <appSettings> like so..

<appSettings>
<add key="EnvironmentConfigurationSettings" value="DevConfigurationSettings" />
</appSettings>

This value is read from within the Global.asax

How can I achieve the same thing in ASP.NET 2.0 using external config files?

thanks,

Bill

scott Sunday, January 22, 2006
Bill: yes, you can do that. Also see the web deployment projects I linked in the post, as these can do config section replacements at build time.
Jack Tuesday, January 24, 2006
How do you get the PDB files to publish to the web server so that line numbers show up in the stack dumps? (we use publish web site)
scott Tuesday, February 7, 2006
Jack: I'd use the web deployment project I link to in the post. It gives you a lot more control over what happens compared to the publish command.
Swati Wednesday, February 8, 2006
Nice to read your article.
I would like to know how to use this dll created from the Web deployment project in another project.

Thanks
scott Wednesday, February 8, 2006
Swati:

Just add a Project Reference like you would to another class library in your solution.
Pallab Gupta Monday, February 27, 2006
How do I use the d:DEBUG switch with the WSD?
carl Friday, April 7, 2006
This is an important article and it's cited all over the place, but in one area I found it a little confusing. The key sentence for me is this: "Note: the Publish command does not change the debug setting in web.config. The Publish command always compiles for “release”, however, if you precompile to an updateable web site, and then update the web site in place (which results in dynamic compilations), those dynamic compilations will produce debug code and pdb files."

If I understand correctly, the comma after "release" could be a semicolon, thus:

"Note: the Publish command does not change the debug setting in web.config. The Publish command always compiles for “release”; however, if you precompile to an updateable web site, and then update the web site in place (which results in dynamic compilations), those dynamic compilations will produce debug code and pdb files."

Is that right? Or have I misunderstood the sentence?

Thanks v. much.
scott Friday, April 7, 2006
You are 100% correct, Carl.
Ed Saturday, April 8, 2006
Thanks for your work on this. However, there seems to be an inaccuracy or I'm just not doing things right:

"The WSD will let you select Debug or Release builds, precompiles the site, and modifies web.config appropriately."

The VS UI did change to include a Release option, but, a WSD does not pre-compile the web site. It seems to just package everything for, well, deployment - in other words, source files (.vb, .cs) and your folders (App_Code) are packaged. If you install it, it just copies things...no dll, source code exposed.

It likewise does not change the web.config debub setting (to false).

The above is just my experience. I've fiddled with settings so unless I'm missing something, only "Publish" mimics the VS 2003 process of creating a "real" Release build....
Ed Saturday, April 8, 2006
Ok, my bad. I guess I'm talking about an entirely different thing! So I hope this helps other similarly confused people:

WSD, Web Site Deployment, as discussed here, is **NOT** the existing "Web Setup Project" found in VS 2005 - which I was referring to

WSD, is an add-in, found at:
msdn.microsoft.com/.../wdp/

Use it to precompile your site. And now that it's another project in your solution, you can use the Web Setup Project to create an installer.

I don't know about everyone else, but IMHO, this isn't exactly an improvement. Ok, I'm too polite, this new process is crap.
Ben Miller Saturday, July 15, 2006
Thanks man. This is exactly the explanation I needed.
Rick Wednesday, July 19, 2006
So confused!

I have been battling this new 2.0 compilation issue for 2-3 days now :(.

I cannot use the Web Site model so I am creating a Web Project with the Web Application Tool (I have my reasons). How do I debug the application?
When I try to do it within VS it creates a projectx.dll and tries to compile on the fly (app_web_xxx) and so it has a conflict with app_web_xxx and the dll because the class exists in both.
So I try to deploy the app somewhere else (no source) and then it says it can't execute because it can't find some source files (xxx.ascx.cs).

Please explain how I am supposed to debug a Web Application Project.

Thanks
RV
N&amp;#233;viton (please send me a email) Friday, September 1, 2006
I cant got it!
How can I have no random names like:
App_Web_2ku7lvmp.dll

Everytime when I publish my WebSite I need upload all my .aspx and .ascx because the dlls files get new names and the references:
<%@ page language="C#" autoeventwireup="true" inherits="_Default, App_Web_ik1cjhwd" %>
stay all wrong!

Sorry about my bad english!

scott Sunday, September 3, 2006
Néviton:

Use the Web Deplyoment Project I linked to in the post. You'll get dependable file names.
Christian Friday, September 22, 2006
So this is strange. I have converted my solution from VS2003 and have ended up with something that compiles exactly as in VS2003. I have the release/debug/config manager UI and when I compile I get dll's in bin/Release or bin/debug directories.

I'm not sure if the result of the conversion is a "web site" or "web application". I suspect neither. I have the right click option to "convert to web application"

For now this situation works well for me because it means I can continue to develop with few changes but I guess I'll hit problems when I need to add a new web project. Will it then be one of these new types that VS won't build because it'll be built by ASP.NET? If so that sound like a nightmare because I'll end up with a mixture of build types.
Chris Tuesday, December 5, 2006
"Note: the Publish command does not change the debug setting in web.config. The Publish command always compiles for “release”, however, if you precompile to an updateable web site, and then update the web site in place (which results in dynamic compilations), those dynamic compilations will produce debug code and pdb files."

What exactly do you mean by "and then update the site in place"?

Tks.
rick Wednesday, December 6, 2006
Chris asked:

begin quote:

"Note: the Publish command does not change the debug setting in web.config. The Publish command always compiles for “release”, however, if you precompile to an updateable web site, and then update the web site in place (which results in dynamic compilations), those dynamic compilations will produce debug code and pdb files."

What exactly do you mean by "and then update the site in place"?

end quote

I have the same question...if you are writing code behind C# code and you publish the code to your website, what code are you supposed to edit on the website to cause IIS to rebuild your website, including your symbol files as specified by the debug=true option in your web.config file?

thanks...rick
Leonel (From argentina) Friday, December 8, 2006
Thank you so much for this article, it was exactly what i needed.
Jonas R Monday, December 11, 2006
I liked this article, it explained a lot and I am now trying to test this in real life. But I keep gettin pdb files in my bin catalogues. I have a web site and a few Class library projects in my solution. I set the class libraries to build to release and publish and I still get the pdb files in the bin catalogue. Does anyone know why?
moredotnet Thursday, January 4, 2007
The article is really cool. Though the messy thing I find is the prefix thing with the DLL name, but I think I can adjust with the change!

moredotnet
patcher Wednesday, January 17, 2007
Per Jonas R's comments, I had problems with pdb files getting included in my bin catalogues, too. I found that, oddly enough, in the project properties for those project, on the "Build" properties tab, the "Advanced" options buttons, the Output Debug Info is set to "pdb-only" for the RELEASE configuration (apparently by default, as all projects were like this). Once I changed that release configuration Output Debug Info option to "None," pdb files were no longer being generated in release mode.
kartik Thursday, October 29, 2009
Great job .. cheers .. :)
gravatar rajesh Monday, May 3, 2010
Even After years ...it helps some one like me.. thanks for your help buddy
gravatar Carlos Thursday, March 3, 2011
Almost one year after rajesh reply it helps for me too.

Thanks.
Comments are now closed.
by K. Scott Allen K.Scott Allen
My Pluralsight Courses
The Podcast!