Debug and Release Builds in ASP.NET 2.0

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.

posted on Tuesday, November 15, 2005 12:04 AM by scott Rated Excellent [5 out of 5].

Comments

Monday, November 14, 2005 11:25 PM by Joteke's Blog

# Debug And release Builds in ASP.NET 2.0

K. Scott Allen writes it clearly how debug and release builds work in ASP.NET 2.0. These have been...
Tuesday, November 15, 2005 5:43 AM by Jason Haley

# Interesting Finds

Thursday, November 17, 2005 3:36 PM by Bill

# re: Debug and Release Builds in ASP.NET 2.0

Nice buddy ;-)
Thursday, November 17, 2005 7:16 PM by Christopher Steen

# Link Listing - November 17, 2005

CAB November 2005 Release Ships! [Via: Brad Wilson ]
CAB: ClickOnce and BankTeller [Via: Brad
Wilson...
Friday, November 18, 2005 9:52 AM by JasonBSteele

# re: Debug and Release Builds in ASP.NET 2.0

At last... its all starting to make sense! Cheers for this :)
Friday, November 18, 2005 10:44 AM by scott

# re: Debug and Release Builds in ASP.NET 2.0

You are quite welcome, Jason!
Friday, November 18, 2005 2:30 PM by Jim

# re: Debug and Release Builds in ASP.NET 2.0

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>)
Friday, November 18, 2005 8:52 PM by ASPNETWorld.com Blog

# Debug And Release Builds in ASP.NET 2.0

Friday, November 18, 2005 11:51 PM by William Robertson

# re: Debug and Release Builds in ASP.NET 2.0

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?
Saturday, November 19, 2005 5:54 AM by Steve

# re: Debug and Release Builds in ASP.NET 2.0

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.
Sunday, November 20, 2005 11:16 AM by scottgu@microsoft.com

# re: Debug and Release Builds in ASP.NET 2.0

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
Sunday, November 20, 2005 3:08 PM by Luciano Castro

# Debug e Release in vs2005 : 1.1 vs 2.0

Wednesday, November 30, 2005 9:02 PM by Paul Litwin's Blog

# Compilation of Web Sites in v1.1 vs v2.0

K. Scott Allen wrote up a nice summary of how debug and release builds work in ASP.NET 2.0 (and ASP.NET...
Sunday, December 04, 2005 1:04 PM by K. Scott Allen

# The Great Migration

I popped into the&amp;nbsp;Central Penn Code Camp this weekend and did a presentation on ASP.NET 2.0. There...
Monday, December 05, 2005 2:00 AM by Felix

# re: Debug and Release Builds in ASP.NET 2.0

How can I switch between connectionstrings ( stored in web.config ) depending on the fact that the site is in Debug or Release build ?
Monday, December 05, 2005 5:51 AM by Technical Notes

# Building for Debug and Release in ASP.NET 2.0

K. Scott Allen provides a solid overview of the differences between how builds are done in ASP.NET 2.0...
Monday, December 05, 2005 4:30 PM by Scott Allen

# re: Debug and Release Builds in ASP.NET 2.0

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:
http://msdn.microsoft.com/asp.net/reference/infrastructure/wdp/default.aspx
Tuesday, December 06, 2005 8:13 PM by Tim

# re: Debug and Release Builds in ASP.NET 2.0

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.
Wednesday, December 07, 2005 1:43 PM by Zerosleep

# re: Debug and Release Builds in ASP.NET 2.0

Great stuff Scott. Saved me lots of time today.
Sunday, December 11, 2005 12:03 AM by anselme

# dll name

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
Thursday, December 15, 2005 9:55 AM by scott

# re: Debug and Release Builds in ASP.NET 2.0

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).
Friday, December 23, 2005 12:21 AM by BlaBlubBlog

# Debug and Release Builds in ASP.NET 2.0

Tuesday, January 17, 2006 2:55 PM by Bill

# re: Debug and Release Builds in ASP.NET 2.0

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

Tuesday, January 17, 2006 5:01 PM by Ricky的BLOG

# 有关VS 2005 的ASP.NET2.0项目只能编译“Debug”版项目的问题

这几天利用VS2005 实际开发 ASP.NET2.0 项目,发现一个很奇怪的问题,无论怎么设置&amp;nbsp; build 的时候显示的编译配置总是Debug,即便是Publish Website 也显示的是Debug配置的编译。这怎么可能,于是“驱猫上网”(只是形容一下,必非真用“猫”),翻了半天,找到一篇Blog,揭开了心中疑团。...
Sunday, January 22, 2006 3:53 PM by scott

# re: Debug and Release Builds in ASP.NET 2.0

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.
Tuesday, January 24, 2006 8:51 AM by Jack

# re: Debug and Release Builds in ASP.NET 2.0

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)
Monday, February 06, 2006 8:11 PM by scott

# re: Debug and Release Builds in ASP.NET 2.0

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.
Wednesday, February 08, 2006 12:50 AM by Swati

# re: Debug and Release Builds in ASP.NET 2.0

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
Wednesday, February 08, 2006 7:01 AM by scott

# re: Debug and Release Builds in ASP.NET 2.0

Swati:

Just add a Project Reference like you would to another class library in your solution.
Monday, February 27, 2006 12:18 PM by Pallab Gupta

# re: Debug and Release Builds in ASP.NET 2.0

How do I use the d:DEBUG switch with the WSD?
Friday, March 03, 2006 6:01 AM by 何となく Blog by Jitta

# 紹介:Debug and Release Builds in ASP.NET 2.0

紹介:Debug and Release Builds in ASP.NET 2.0
Sunday, March 05, 2006 11:59 PM by BlaBlubBlog

# Debug and Release Builds in ASP.NET 2.0

Friday, April 07, 2006 1:35 AM by carl

# re: Debug and Release Builds in ASP.NET 2.0

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.
Friday, April 07, 2006 5:34 AM by scott

# re: Debug and Release Builds in ASP.NET 2.0

You are 100% correct, Carl.
Saturday, April 08, 2006 1:29 PM by Ed

# re: Debug and Release Builds in ASP.NET 2.0

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....
Saturday, April 08, 2006 3:27 PM by Ed

# re: Debug and Release Builds in ASP.NET 2.0

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:
http://msdn.microsoft.com/asp.net/reference/infrastructure/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.
Wednesday, April 12, 2006 10:56 AM by My way of my life

# Asp.net 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 re...
Friday, May 19, 2006 8:14 AM by 沧海笑一声

# 本周技术关注[面向webapps运维]:大公司的小团队

本周技术关注[面向webapps运维]:大公司的小团队
Friday, May 19, 2006 8:59 AM by 沧海笑一声

# 本周技术关注[面向webapps运维]:大公司的小团队

本周技术关注[面向webapps运维]:大公司的小团队
Friday, May 19, 2006 9:00 AM by 沧海笑一声

# 本周技术关注[面向webapps运维]:大公司的小团队

本周技术关注[面向webapps运维]:大公司的小团队
Saturday, May 20, 2006 3:11 AM by longrujun

# 本周技术关注[面向webapps运维]:大公司的小团队

本周技术关注[面向webapps运维]:大公司的小团队
Sunday, May 21, 2006 11:42 PM by My DasBlog!

#

Sunday, May 21, 2006 11:53 PM by Eran Nachum's Blog

# Publish website in .NET 2.0 Innovations

Saturday, July 15, 2006 10:22 AM by Ben Miller

# re: Debug and Release Builds in ASP.NET 2.0

Thanks man. This is exactly the explanation I needed.
Monday, July 17, 2006 11:34 PM by Eran Nachum's Blog

# Publish website in .NET 2.0 Innovations

Wednesday, July 19, 2006 12:01 PM by Rick

# re: Debug and Release Builds in ASP.NET 2.0

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
Thursday, August 10, 2006 8:02 PM by Community Blogs

# Treat Warnings as Errors in ASP.NET 2.0

The web.config file controls all compilation settings in a default web site project. To treat compiler
Friday, September 01, 2006 1:45 PM by Néviton (please send me a email)

# re: Dlls names AGAIN

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!

Saturday, September 02, 2006 7:52 PM by scott

# re: Debug and Release Builds in ASP.NET 2.0

Néviton:

Use the Web Deplyoment Project I linked to in the post. You'll get dependable file names.
Friday, September 22, 2006 1:26 AM by Christian

# re: Debug and Release Builds in ASP.NET 2.0

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.
Tuesday, December 05, 2006 3:09 PM by Chris

# re: Debug and Release Builds in ASP.NET 2.0

"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.
Wednesday, December 06, 2006 3:26 PM by rick

# re: Debug and Release Builds in ASP.NET 2.0

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
Friday, December 08, 2006 8:24 AM by Leonel (From argentina)

# re: Debug and Release Builds in ASP.NET 2.0

Thank you so much for this article, it was exactly what i needed.
Monday, December 11, 2006 5:53 AM by Jonas R

# re: Debug and Release Builds in ASP.NET 2.0

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?
Wednesday, January 03, 2007 11:07 PM by moredotnet

# re: Debug and Release Builds in ASP.NET 2.0

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
Wednesday, January 17, 2007 6:21 AM by patcher

# re: Debug and Release Builds in ASP.NET 2.0

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.
Thursday, February 08, 2007 9:58 PM by deusBlue

# Release builds for Visual Studio 2005 websites

Release builds for Visual Studio 2005 websites
Thursday, April 05, 2007 6:53 AM by Explosive Insight

# Visual Studio 2005

Visual Studio 2005
Sunday, April 29, 2007 1:55 AM by zhanqiangz(闲云野鹤)

# ASP.NET 2.0的编译行为

ASP.NET 2.0的编译行为
Sunday, April 29, 2007 4:39 PM by Winner.Net(2007)

# ASP.NET 2.0的编译行为

ASP.NET2.0的编译行为 在从ASP.NET1.1向2.0迁移的时候在如何生成debug和release的构建(builds)方面做了调整. 1.1 在1.1的时候(对应的IDE是VS...