Have tried adding this to web.config
<compilation debug="false" targetFramework="4.0">
</compilation>
but website still executes code in #if DEBUG when it shouldn't
*Wierdly the inline statement <% #if DEBUG %> on aspx files works but require also for .cs code.
NB development and live website on same box
#if directives in backend .cs files are handled by the C# compiler, not ASP.Net.
Set your project to the Release configuration so that that symbol is not defined when compiling the DLL in VS.
compilation debug element is not the same thing as DEBUG preprocessor directive.
You need to re-compile your website in Release mode.
What about binaries compiled with debug symbols?
One scenario that several people find very useful is to
compile/pre-compile an application or associated class libraries with
debug symbols so that more detailed stack trace and line error
messages can be retrieved from it when errors occur.
The good news is that you can do this without having the have the
switch enabled in production.
Specifically, you can use either a web deployment project or a web
application project to pre-compile the code for your site with debug
symbols, and then change the switch to
false right before you deploy the application on the server.
The debug symbols and metadata in the compiled assemblies will
increase the memory footprint of the application, but this can
sometimes be an ok trade-off for more detailed error messages.
http://weblogs.asp.net/scottgu/archive/2006/04/11/Don_1920_t-run-production-ASP.NET-Applications-with-debug_3D001D20_true_1D20_-enabled.aspx
Ensure the compile configuration to release as well. In Visual Studio, Build Menu > Configuration Manager and make sure "Release" is selected for all your assemblies, and/or is the active solution configuration.
Related
I have developed an UWP app that uses a lot of NuGet packages (MvvmLight, SQLite, ...) and other resources (Syncfusion controls).
I encounter a bug with the Store app, which is already published for tests, that is not present when I build the app in "Debug" mode.
So, I've tried to debug in "Release" mode, with the checked options "Compile with .NET Native tool chain" and "Optimize code". The build ends successfully, but I encounter an exception with a Syncfusion control (SfDataGrid) on the main page of the app. I would like use breakpoints to understand what happens, but they are deactivated as I build the app in "Release" mode.
If I build the app in "Debug" mode, with the same options checked ("Compile with .NET Native tool chain" and "Optimize code"), I don't encounter the same bug with the Syncfusion control, and the defined breakpoints are well keeped.
So I don't see how I could fix my problem:
if I create a new solution and built it in "Release" mode, the breakpoints are well keeped, and I can debug the code
if I build Syncfusion samples in "Release" mode, it's the same thing: the breakpoints are well keeped, and I can debug the code
I have compared the "build" parameters of the app and the other ones: they are the same
I have also looked at the "Just-in-Time" page, in the Visual Studio "options". I've got the following error: "Another debugger has registered itself as the Just-In-Time debugger. To repair, enable Just-In-Time debugging or run Visual Studio repair.". Ive tried to "repair" Visual Studio, but it's always the same thing...
Here is the "Options" settings:
And the result in solution, where breakpoints are disabled:
Would you have any explanation? How could I do to debug my app in "Release" mode?
[Edit 1]: add some details after further investigations
My app is based on a "template" like Template10, called Nentang. The structure of the project is the same, and they share a big part of references or NuGets packages.
But if I compare the build result of the "blank" Nentang and my solution, there are some differences that I don't understand:
as explained, on my app, the breakpoints and debug don't work in "Release" mode, and I can see that almost all modules don't have any "Symbol File":
=> only "ntdll.dll" and "KernelBase.dll" are linked to thier pdb file in a local directory: "C:\Users\myname\AppData\Local\Temp\SymbolCache"
on the "blank" Nentang app, the breakpoints and debug work well in "Release" mode, and I can see that almost all modules have a "Symbol File":
=> allmost half of the modules are linked to the same file in the "project" directory: "C:\Projects\Samples...\Nentang.UWP\bin\x64\Release\AppX\Nentang.UWP.pdb"
=> another quarter of the modules are linked to the same file of a "system" directory: "C:\Program Files (x86)\Microsoft SDKs\Windows Kits\10\ExtensionSDKs\Microsoft.NET.Native.Framework.1.3\1.3\x64\ret\Native\SharedLibrary.pdb"
=> the other modules are not linked to a Symbol File: it's the case of "ntdll.dll" and "KernelBase.dll"
How could I restore the "Symbol files" of my project?
I have also remarked a "strange" parameter in the properties of my solution, that is not present is the Nentang properties:
There is this parameter: "f:\dd\ndp\fxcore\CoreRT\src\System.Private.CoreLib\src\System\Runtime\ExceptionServices\ExceptionDispatchInfo.cs"
What does it mean? Could it explain my problem?
Debugging optimized code is always a challenge - even more so with .NETNative. Here are a few things you could try:
Disable Just My Code
Suppress JIT Optimizations: This will not help for modules built with .NETNative toolchain. If the exception occurs in Release builds without .NETNative, then check the debugger option called "Suppress JIT optimization on module load (Managed Only)". As the name implies, this will cause the CLR to JIT compile code unoptimized, which will allow you to set breakpoints and inspect locals.
Look at the Output window for clues as to what went wrong. The exception message will be there and the preceding messages may help diagnose the cause.
Debug your application with Native debug engine. You can do this by checking the Native checkbox under the Debug tab of the project properties.
Last resort is to debug the assembly.
In ASP.NET web pages we use special tags like <%# %>,<%= %>,<%# %>and<%$ %>.
I'm just curious if those tags are compiled or not? Do we have to build the project to make it work, or is it compiled at run time?
Usually that code is compiled at runtime when the page is first hit. Depending on your settings in your web.config file it compiles in Debug or Release mode.
It is possible though to pre-compile that code before you deploy your project. See How to: Precompile ASP.NET Web Sites for Deployment. It uses the aspnet_compiler to compile the ASP.NET code to an assembly.
They are recompiled first time page code is executed after web application starts or the page is changed.
It is compiled when it is loaded into IIS, and if you have selected the precompile option when you build the website, they have been precompiled, just like with a DLL.
Setting <compilation debug="true/false"> in Web.config seems to do things that you can also set in Visual Studio in Project properties, Build tab. Are they connected somehow? Does one of them takes precedence when compiling?
They are not connected. The compilation tag is ASP.NET only, while the project option one is for Windows Forms, console, WPF and so on.
ASP.NET compilation is so special, so you have to dive further to learn about every piece of it,
http://msdn.microsoft.com/en-us/library/ms178466.aspx
Set compilation debug="true" to insert debugging symbols into the compiled page. Because this affects performance, set this value to true only during development.
I'm currently working in the web site project.I want to build project in release mode, that unfortunately saw visual studio does not have release mode for build and only have debug mode.
in web application project we see two option in build debug and release.
I want to know why web site project have debug mode in build.I was read about debug and release mode building that release mode have optimize code and have less overhead.
You need to set release meod by right clicking solution > property> in dialog change it release mode or direclty from the rop of vidual studio set it for the release , see below image marked with red
In web site projects pages are compiled dynamically upon first request. It will compile without debugging symbols unless you specify otherwise in the config file.
You cant change it with configuration manager neither you see it in its options.
In your web config file find these options
<system.web>
...
<compilation debug="true">
...
</compilation>
</system.web>
Set true to false then it will publish in release mode.
Hope it helps
In VS2008 (and earlier if I'm not mistaking) I have dropdown that lets me choose between Debug and Release mode. All well.
When I switch VS to Release, the debug attribute in my web.config files isn't set to false at all though.
Is this the way it is supposed to be? I am bound to forget to set it to the correct value on deploying.. What measures should I take to make sure this is working like it should?
This is one solution to this problem:
http://blog.aggregatedintelligence.com/2009/04/aspnet-never-again-fear-publishing-your.html
Well your web.config would probably be different for debug and release (connection string, passwords, etc...) but if it's not, look at a postbuild event which would copy over a different file.
Also check this blog post from Scott Guthrie.
Changing release mode will not change web.config, however when you build your web app, it will build the dll for only C# files in release mode where else your web.config's debug on/off is used by IIS to build debug/release version of ASPX markup files.
The build flavour just affects how the code is compiled, it does not affect your configuration files. So yes, to answer your question, this is how it is supposd to be.
The element is a good solution if you have access to the machine.config of your server, which hosts only production applications.
I usually modify the web.config file when generating the deployed files as part of the automated build process. For example web deployment projects can perform web.config section replacement. There are a number of reasons I don't like web deployment projects and I tend to do it with a simple VBS file that modifies the file using MSXML.
The answer you selected from Bobby is not correct. Visual Studio builds the files for you in release while you are in VStudio.
IIS compiles the code at startup with that setting when you deploy. Not the bin directory, but the App_Code and the code behind files.
You should precompile your app before deployment which will compile your code behinds and App_Code dir into dlls in the bin directory.
The deployment tools automatically switch that setting if you set the deployment tool to Release
I use web deployment projects. http://weblogs.asp.net/scottgu/archive/2008/01/28/vs-2008-web-deployment-project-support-released.aspx