Visual Studio + C + + property setting basics

Source: Internet
Author: User
Tags custom name visual studio 2010

In the Visual Studio of C + + project file, the reference to the C + + project can be user-defined property settings, how to set the property?

Let's take a look at the basic rules of the props file:

1. Placing a child element in a PropertyGroup element is defined as a property, and the value of the property is the content of the child element;

<PropertyGroup>
<OutputDriver>D:\</OutputDriver>
</PropertyGroup>

Defines an attribute Outputdriver value of D:\

2. When defining an element, a condition can be used to allow the attribute definition to function under a specific condition, for example:

<PropertyGroup>
<singlefolder condition= "' $ (singlefolder) ' = = '" >false</SingleFolder>
</PropertyGroup>

The Singlefolder property is defined as false only if the Singlefolder property is undefined or null, if there is only one attribute in the attribute group, or if multiple properties in one attribute group have the same condition, you can place the condition in the The PropertyGroup element;

3, conditional expression can use "= =", "! =" to judge, can also be the value of ">", ">=", "<", "<=" judgment, and the directory can be "Exists" and "Hastrailingslash" judgment, You can also do "!" on an expression or "and", "or" for multiple expressions, and you can refer to the http://msdn.microsoft.com/en-us/library/7szfhaft.aspx

4, the value of the definition can be inherited, in fact, the original value based on the addition of new values, as follows:

<propertygroup condition= "Exists (' $ (importfolder) ')" >
<librarypath>$ (Importfolder); $ (LibraryPath) </LibraryPath>
</PropertyGroup>

If the directory specified by the property "Importfolder" exists, the directory is added to the search path of the library, and the priority is preceded by the default search path;

5. You can use. NET functions for judgment or definition of attribute values, such as defining the drive where the solution file resides can be defined as follows:

<propertygroup condition= "' $ (solutiondriver) ' = = '" >
<solutiondriver>$ ([System.io.path]::getpathroot ($ (SolutionDir))) </SolutionDriver>
</PropertyGroup>

6. You can import other property settings files using the import element, for example, you need to import a property file with the same name as the solution:

<ImportGroup>
<import project= "$ (userrootdir) \microsoft.cpp.common.user.props"/>
</ImportGroup>

Description: Userrootdir is a property defined in the C + + default properties file with a value of $ (localappdata) \microsoft\msbuild\v4.0\

7. If the imported property file needs to be seen in the Property Manager window in Visual Studio 2010, add a specific attribute to the Importgroup element as follows:

<importgroup label= "PropertySheets" >
<import project= "$ (projectpath). Props" condition= "Exists (' $ (projectpath). Props ')"/>
</ImportGroup>

If a project file exists under the directory. Vcxproj.props will import the file, for example, the project file is myproj.vcxproj and the MyProj.vcxproj.props file exists in the project directory, the file will be imported automatically MyProj.vcxproj.props Properties File

8. If the property file name you want to see in the Properties Manager window is not a filename, but a custom name, you can add a specific attribute definition to the property file, for example:

<PropertyGroup>
<_propertysheetdisplayname>cpp Common properties</_propertysheetdisplayname>
</PropertyGroup>

Well, the basic rules we've mastered (complex can study VS2010 's props file and view MSDN), here's a look at how the compile and link options are set:

1. The compiled option is placed in the Clcompile child element of the ItemDefinitionGroup element, such as the following definition:

<ItemDefinitionGroup>
<ClCompile>
<preprocessordefinitions>isf_build_dll;% ( Preprocessordefinitions) </PreprocessorDefinitions>
<PrecompiledHeaderFile>ISF/Stable_Headers.h</PrecompiledHeaderFile>
<PrecompiledHeader>Use</PrecompiledHeader>
</ClCompile>
</ItemDefinitionGroup>

In this definition, a macro is added first to define "Isf_build_dll", then the name "Isf/stable_headers.h" of the precompiled header file is defined, instead of the default "StdAfx.h", and the final definition of the precompiled header file's usage rule is " Using precompiled header files, this requires that all C + + files must contain the header file "Isf/stable_headers.h" first, unless the precompiled header file is specified on the file;

2. The linked option is placed in the link child element of the ItemDefinitionGroup element, such as the following definition:

<ItemDefinitionGroup>
<Link>
<programdatabasefile>$ (Symbolfolder) $ (outputname) .pdb</programdatabasefile>
<importlibrary>$ (Importfolder) $ (outputname) .lib</importlibrary>
</Link>
</ItemDefinitionGroup>

In this definition, the output full path of the output private PDB file and the output full path of the import library of the dynamic library are specified;

3. The library's options are placed in the Lib child elements of the itemdefinitiongroup element, such as the following definition:

<ItemDefinitionGroup>
<Lib>
<LinkTimeCodeGeneration>true</LinkTimeCodeGeneration>
</Lib>
</ItemDefinitionGroup>

Defines the code generation behavior when static library generation is "connection-time code generation";

Well, at the end of the day, more options are left for the reader to study and discover ....

Visual Studio + C + + property setting basics

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.