Differences between Debug and release compilation modes in Visual studio and the use of preprocesor directives

Source: Internet
Author: User

In Visual Studio, the most basic compilation mode is 2, Debug and release. This is also the default two ways, when you create a new project, both of these modes already exist.



We can also click on the Configuration Manager button to create a new compilation mode for ourselves. When creating this compilation mode, you will be asked whether you want to inherit from the existing one, you can choose Debug or release, or nothing, this inheritance refers to some of the ways of compiling, such as whether to optimize the code or something.


So what is the difference between Debug and release compilation mode? We can see it in the properties of project. On the Build tab, we can see the specific contents of the debug mode. The main thing is that the Optimize Code option is not checked, so there is no compression dll, that is, there is still a debugging information, you can debug the program. If you select release mode, the default is to check this option, the DLL will be compressed, so that the DLL will become very small, but can not be debugged. (Of course, you can also remove the compression DLL option in the release mode, this can be done, but there is no point, because the release mode should be compressed, why the default cancellation, not to counter normal thinking work.) )


Look at this page above, there is also a definition of the debug and Trace constants, which is used for preprocessor, that is, in the common # in VS the beginning of those things. Here is the definition of the constant debug, then in the debug mode to compile the program, that is, after the start box selected after the debug, the bottom of this sentence Console.WriteLine will be compiled into the DLL, will be executed by the CLR. If it is release mode, it will not be compiled and executed.

#ifDEBUG
Console.WriteLine ("Debugversion");
#endif

This is the list of all the preprocessor in MSDN: Https://msdn.microsoft.com/en-us/library/ed8yd1ha.aspx

If it is a website project, when the project publish, it will also involve debug,release, or other custom patterns, such as Deploytoqa (inherited from Release), because when creating a one-click deployment of VS, you need to choose a mode, So that vs knows which compiled DLL to put on top of the server.

And VS recently introduced a Web. config transform syntax, you choose which compilation mode, you need to go to the same directory of Web. config, find the Web.DeliveryInDev.config file, and then use the appropriate syntax to write this file, the general meaning is that we B.config is a template, but replaces the contents of some of the nodes, such as the address of the database to QA.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.