If I understand this correctly - if you are properly running in "Release" mode, then the System.Diagnostics.Debug line will basically not even exist within your compiled app.
I created a quick example within a Page_Load method using the following :
I didn't alter anything within the web.config and when I ran the application in "Debug" mode under the drop-down within Visual Studio, "YES" was written in the Console. I re-ran the application in "Release" mode and the above line was never executed.
After doing this - you will have two web.config files, a Web.Debug.Config and a Web.Release.Config typically, which resemble the following :
Awesome info; I was able to get the same results on a console app.
On our web app, I tried to change the solution configuration from Debug to Release using the following click path:
Right click solution --> Configuration Properties --> Configuration --> Configuration Drop Down List but the only option listed is debug. Shouldn't there be a release option? I checked msbuild logs and they throw a warning; I believe this to be the root
cause of our issue but don't know how to reconfigure the solution to release.
There should be a drop down within Visual Studio towards the top on your Toolbar
(it should have Debug in it) and will be located next to the Search box.
You should be able to select Release from there and then build your project as normal.
VS 2010 Profession (I think). I was able to get the show advance build configurations to show but debug is the only option. I have even tried to inject XML into the solution file but any new mode just copies settings from "Debug" directly over. I have
also tried deleting and re-adding the solution.
Is the aspnet_compiler in charge of taking care of this setting?
The compiler will use the appropriate settings (either Debug or Release) to handle compilation. Release will create a more optimized version of the application since it won't have to worry about any Traces or Debugging-related operations being performed.
(As previously mentioned Scott Hanselman covers the major differences here.)
Have you tried restarting Visual Studio since applying the "Enable Advanced Build Configurations" change?
I checked the web.config and found in the System.Web/compilers/compiler/compilerOptions there is a "/define:Debug=True". When I changed it to false the application compiled correctly and the debug code does not do anything anymore.
Rion William...
All-Star
26544 Points
4414 Posts
Re: System.Diagnostics.Debug.WriteLineIf
Jan 29, 2013 06:22 PM|LINK
If I understand this correctly - if you are properly running in "Release" mode, then the System.Diagnostics.Debug line will basically not even exist within your compiled app.
I created a quick example within a Page_Load method using the following :
protected void Page_Load(object sender, EventArgs e) { System.Diagnostics.Debug.WriteLineIf(true,"YES"); }I didn't alter anything within the web.config and when I ran the application in "Debug" mode under the drop-down within Visual Studio, "YES" was written in the Console. I re-ran the application in "Release" mode and the above line was never executed.
After doing this - you will have two web.config files, a Web.Debug.Config and a Web.Release.Config typically, which resemble the following :
Web.Debug.Config
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> <system.web> <!-- Comments --> </system.web> </configuration>Web.Release.Config
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"> <system.web> <compilation xdt:Transform="RemoveAttributes(debug)" /> </system.web> </configuration>monoliths
Member
168 Points
79 Posts
Re: System.Diagnostics.Debug.WriteLineIf
Jan 29, 2013 08:01 PM|LINK
Awesome info; I was able to get the same results on a console app.
On our web app, I tried to change the solution configuration from Debug to Release using the following click path:
Right click solution --> Configuration Properties --> Configuration --> Configuration Drop Down List but the only option listed is debug. Shouldn't there be a release option? I checked msbuild logs and they throw a warning; I believe this to be the root cause of our issue but don't know how to reconfigure the solution to release.
Rion William...
All-Star
26544 Points
4414 Posts
Re: System.Diagnostics.Debug.WriteLineIf
Jan 29, 2013 08:11 PM|LINK
There should be a drop down within Visual Studio towards the top on your Toolbar (it should have Debug in it) and will be located next to the Search box.
You should be able to select Release from there and then build your project as normal.
monoliths
Member
168 Points
79 Posts
Re: System.Diagnostics.Debug.WriteLineIf
Jan 29, 2013 08:24 PM|LINK
It is not there. I even went as far as to delete/re-create the solution and add the existing web site. I still only have an option for debug...
Sorry for all the posts but I sure do appreciate your help!
Rion William...
All-Star
26544 Points
4414 Posts
Re: System.Diagnostics.Debug.WriteLineIf
Jan 29, 2013 08:39 PM|LINK
That's bizarre. (What version of VS or VWD are you using?)
Check under the following :
I might suggest checking out the following link :
Setting Debug and Release Builds in Visual Studio
monoliths
Member
168 Points
79 Posts
Re: System.Diagnostics.Debug.WriteLineIf
Jan 29, 2013 08:55 PM|LINK
VS 2010 Profession (I think). I was able to get the show advance build configurations to show but debug is the only option. I have even tried to inject XML into the solution file but any new mode just copies settings from "Debug" directly over. I have also tried deleting and re-adding the solution.
Is the aspnet_compiler in charge of taking care of this setting?
Rion William...
All-Star
26544 Points
4414 Posts
Re: System.Diagnostics.Debug.WriteLineIf
Jan 29, 2013 09:02 PM|LINK
Yes.
The compiler will use the appropriate settings (either Debug or Release) to handle compilation. Release will create a more optimized version of the application since it won't have to worry about any Traces or Debugging-related operations being performed. (As previously mentioned Scott Hanselman covers the major differences here.)
Have you tried restarting Visual Studio since applying the "Enable Advanced Build Configurations" change?
Rion William...
All-Star
26544 Points
4414 Posts
Re: System.Diagnostics.Debug.WriteLineIf
Jan 29, 2013 09:04 PM|LINK
You can find a very verbose thread from MSDN discussing the vanishing "Release" option, which mentions a few work-arounds and possible solutions.
monoliths
Member
168 Points
79 Posts
Re: System.Diagnostics.Debug.WriteLineIf
Jan 29, 2013 10:21 PM|LINK
NICE!!!
I checked the web.config and found in the System.Web/compilers/compiler/compilerOptions there is a "/define:Debug=True". When I changed it to false the application compiled correctly and the debug code does not do anything anymore.
Rion William...
All-Star
26544 Points
4414 Posts
Re: System.Diagnostics.Debug.WriteLineIf
Jan 29, 2013 10:27 PM|LINK
Great!
I'm glad that you got it all taken care of :)