One of the adjustments to make when moving from ASP.NET 1.1 to 2.0 is how to produce debug and release builds.
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.
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
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>)
#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?
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
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
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
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).
<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
I would like to know how to use this dll created from the Web deployment project in another project.
Thanks
Just add a Project Reference like you would to another class library in your solution.
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.
"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....
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.
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
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!
Use the Web Deplyoment Project I linked to in the post. You'll get dependable file names.
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.
What exactly do you mean by "and then update the site in place"?
Tks.
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
moredotnet
Thanks.