Introduction to Visual Studio compilation options

Source: Internet
Author: User

1. Introduction to concepts

Generally, there are two parameters that can affect vs compilation results: Compilation optimization and target platform.

Compilation Optimization

First, you must understand the concept that. Net is a quadratic compilation model, so the result of vs compilation is Il.Code. By default, the Il Code Compiled by vs includes many NOP commands (empty commands) and many branch commands. Vs will use these commandsProgramDebugging provides better support. The so-called compilation optimization is to remove these additional commands, so that the size of the Assembly and the memory occupied by the runtime are smaller.

Other commonly used terms are debug and release. The debug version is the version that disables compilation optimization, and the release version is the version that enables compilation optimization.

Target Platform

Modern Operating Systems are divided into 32-bit and 64-bit. The 32-bit operating system can run 32-bit programs, and the 64-bit operating system can run both 32-bit and 64-bit programs. The operating system determines the program category by identifying the program file header. If it contains a pe32 header, It is a 32-bit program, and if it is a pe32 + header, It is a 64-bit program. The target platform of VS has three options: x86, x64, and anycpu. If x86 is selected, a pe32 header is added before the Assembly. If x64 is selected, a pe32 + header is added. Anycpu is a little special. It adds a pe32 header to the Assembly, but the CLR will automatically adjust the target machine code compiled by the JIT compiler according to the runtime environment. Therefore, if a common static analysis tool analyzes the Assembly file, it will find that it is a 32-bit program, but it is a 64-bit program at runtime.

You can use the corflags command under Visual Studio command prompt to determine the actual category of the Assembly. For x86 compilation, PE: pe32, 32bit: 1, for x64 compilation, PE: pe32 +, 32bit: 0, for anycpu compilation, PE: pe32, 32bit: 0.

2. Set compilation options in Solution

You can provide basic settings for all projects on the solution properties page.

As you can see, there are two parameters in the top line that correspond to the concepts described above: configuration and platform. The configuration here refers to the debug mode or the release mode. The first activity (XXX) of the option indicates the current choice. The Platform indicates x86, x64, or some x86 x64 instances. The first activity (XXX) in the same option indicates the current choice. You can set each project separately and in detail in the main panel on the right.

Here are a few things to note: I have come to the conclusion after several explorations.

1. You can see that the configuration and platform options are available on the top line of the interface. On the right side of the main panel, each project has its own configuration and platform options. But what they mean is different. What really works for Project compilation is the settings in the main panel, and the top setting can think of it as the name of a compilation policy corresponding to the set on the main panel. As shown in, debug is selected in the configuration, but the main panel contains items configured in the release mode. For example, you can create a configuration named M. m is displayed in the top configuration drop-down box. The first three projects are in debug mode, and the last two are in release mode, then create a platform named n, where n is displayed in the top platform drop-down list. The first one is x86, and the last four are x64.

You can use the Configuration Manager button to maintain the configuration set and platform set.

2. You cannot change the Project Settings directly through the top drop-down box. For example, change the configuration drop-down box from activity (Debug) to release. Of course, you can see that the settings of various projects in the main panel have been changed. However, if you click OK and then enter this window, you will find that the top selection is still the previous activity (Debug ). Here you can choose the reason that you mistakenly think that you can directly change it. I guess it is convenient for you to view it.

3. Changing the settings will affect the directory for generating DLL and exe.

Platform

Mode

Directory

Anycpu, x86

Debug

Bin \ debug

Release

Bin \ release

X64

Debug

Bin \ x64 \ debug

Release

Bin \ x64 \ release

 

3. Set compilation options in the project

You can configure the project and platform on the project properties page.

As you can see, the configuration and platform drop-down boxes are also displayed on the top line. As mentioned above, it is only available for reading and cannot be changed.

Selecting the optimization code is equivalent to selecting the release mode, or you can change the platform options in the directory platform drop-down box.

There is an advanced button at the bottom of the page. The following box is displayed after you click it.

The most important part here is the debugging information. Click the drop-down box and the following is displayed:

The PDB file is generated only when full or PDB-only is selected. PDB stands for program database, which stores the Il code andSource code. The source code can be debugged only when this file is generated during compilation.

4. Notes

As we can see above, the directory generated by the Assembly is affected by the settings on the solution property page, but the actual compilation mode can be changed by the Project property page. This causes the directory name to be inconsistent with the actual assembly type. For example, if you set the platform as x64 in the solution, but change the target platform to x86 on the project properties page, the x86 assembly is generated in the x64 directory. Pay attention to this 1.1.

 

ReferenceArticle:

Description of Visual Studio. NET "Target Platform"

View the properties of the DLL file. Is the version platform x86? X64? Any CPU?

Visual Studio debugging requires a PDB File

Visual Studio 64-bit application Compilation

Generate Configuration

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.