[You must know. NET] The 35th time, to determine whether the DLL is debug or release, this is a problem

Source: Internet
Author: User

The question of the proposed

In the evening, turning over the chat in the group, I found an interesting question: how can I use encoding to determine whether a DLL or EXE is a debug build or a release build? There was not much discussion, so I had to find some way to try to solve the problem and bring some excitement to the nightlife. Then, there is the exploration and analysis of this article.

Of course, in order to fully mobilize everyone's ideas, eliminating unnecessary Google operations, I think it is necessary to debug and release two models of similarities and differences to do a little sketchy analysis, so as to lay a good foundation for the next solution.

Debug & Release

When we applied Visual Studio to F5 operations on code files (build), there was actually a series of syntax checks, lexical checks, and compilation processes, and typically we had two builds modes, which is often said to be the debug build and release built. As you know, the debug build pattern is typically applied to development, which facilitates debugging feedback, and release builds apply to deployment, because the compiler does a lot of optimization (code redundancy, loop optimization, and so on) in release mode, eliminating the need to record debug information. Therefore, the two build patterns are different, and we have a little summary of both of them as follows:

When debug is used for development, release is used for deployment.

In debug mode, a PDB file is generated to hold state information and debug information, and in release mode, no debugging information or PDB files are generated.

In debug mode, System.Diagnostics.Debug.Write (or WriteLine) can output trace information to the trace window (output), and System.Diagnostics.Debug.WriteLine will be ignored in release mode. However, can consider System.Diagnostics.Trace.Write, its popularity is good, to debug and release about take-all, can output debugging information.

In debug mode, #define DEBUG participates in the compilation process as a default predefined constant, and in release mode, the precompilation is omitted. For example, if you do:

#if DEBUG

   Console.WriteLine("Hi");

#endif

In debug mode, Console.WriteLine ("Hi") will participate in the compilation, and the execution of the statement is ignored in release mode. However, if you manually add

#define DEBUG

In both modes, the compilation of Console.WriteLine ("Hi") is performed. The reason for this is that Visual Studio has predefined #define DEBUG by default, and we can set it by using the switch:

For a precompiled directive, you can look at the relevant chapters of. NET you must know.

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.