Difference between Debug and Release in Visual Studio, studiodebug
In Visual Studio, there are two modes for generating an application: Debug and Release. How can we choose between them?
Assume that there is such a simple piece of code that calls Methods M1 and M1 in the main program to call the M2 method, M2 to call the M3 method, and M3 to throw an exception.
class Program
{
static void Main(string[] args)
{
M1();
Console.ReadKey();
}
static void M1()
{
M2();
}
static void M2()
{
M3();
}
static void M3()
{
throw new Exception("error");
}
}
Select the "Debug" mode and place the breakpoint on the Console. ReadKey (); line of code. Click "Debug> WINDOW> call stack" to display the "call stack" window information, as shown below:
Select the "Release" mode and debug it again. The display is as follows:
From the stack information, we can see that debugging in Debug and Release modes consumes more memory, so it runs slowly. The Release mode is optimized, it consumes less memory, so it runs faster.
In actual situations, you should deploy the applications generated in the Release mode to the server, because the applications generated in the Remease are optimized and compared to the applications generated in the Debug mode, it runs faster.
In addition, if you want to run a piece of code only in Debug mode, you can use the Debug flag to write it as follows:
#if DEBUG
Console.WriteLine(DateTime.Now);
#endif
In general:
1. Compared with the Debug mode, the Release mode is more optimized and suitable for deployment to the server after the project is completed. The Debug mode is more suitable for debugging.
2. The Code marked with Debug is automatically deleted in Release mode.
The results of visual studio2005 debug and release are different.
"The release result generated directly by F5 is correct, but I turn it off and open it from the folder, and the result is incorrect"
This is mainly because a series of Dynamic Link Libraries (DLL) need to be loaded during the application running process. Some search paths have been set in the VS environment, so you can find them during debugging. When you double-click a folder, if the program needs a DLL, it will find it in the current directory and system directory. If no DLL is found, it will naturally not be able to run ^_^.
There are usually two solutions:
1. dynamically link the MFC Library and publish the DLL together
1.1 manual method
Through the vscommand, The dumpbin.exetoken in the environment indicates which DLL your main output file (cmd.exe) depends on. You can find them manually, put them in the same directory as your exe, and copy the entire directory when transferring them to other machines.
1.2 use the Installation Tool
The most convenient is VS's built-in release tool.
In VS, choose "New Project"> "other project type"> "Install and deploy"> "Installation Wizard" and follow the prompts to set it. When you select an existing application project, the wizard will automatically search for the dependent DLL when you find its main output file (.exe ×.exe .exe.
After this "installation project" is compiled, the *. msi file is generated, and you can run it directly to install it (like the professional software such as MS Office ^_^ ).
Ii. Static link to the MFC Library
In the solution manager window, right-click the project name and select "properties ". In "project default value", find "use of MFC" and select "use MFC in static library ". In this way, all the required functions in the dependent DLL can be statically linked to the exe. In the end, only one exe can be run.
However, in this way, the size of the static link exe will be a lot bloated, ^ _ ^
Differences between DEBUG and Release
DEBU is a debugging version. It can be said that the system is still under development and the Release is a released version. The main difference that the system can use for users is that the information generated during runtime is different and the running performance is different.