0

在新的VS2010 C++工程文件中会发现有后缀为.vcxproj的文件,用notepad打开后可看到,有许多顶级MSBuild元素以一定的顺序布局。在Microsoft.Cpp.Default.props导入后,产生了大多数的组属性以及项目定义属性。还有,大多数的target在工程文件结尾处被导入。它们以Lable标志来区分。

这些有序的布局到底有什么作用?为什么会有多种属性组而不是只有一个?

有序布局是MSBuild的顺序评估模型的自然结果。如果一个工程文件由一个属性的两个定义构成,比如以下的,则后一个定义会覆盖掉前面的。因此,值"xyz"会在编译期被使用到。

  1. <MyProperty>abc</MyProperty>
  2. <MyProperty>xyz</MyProperty>

第一个属性定义也可以不在工程文件中。它放在一些导入文件中,然后在第二个属性定义之前,通过导入这些文件来达到目的。这些也同样适应于item定义元数据。(一般来说,在整篇文章中这个原则都是正确的)

话说回来,让我们看看整个的布局。以下的MSBuild结构文件描述了一个简洁的布局。VS生成的任何.vcxproj文件以这种特定顺序包含了这些顶级MSBuild元素(或者它们可能包含每一个这种顶级元素的拷贝)。需要注意的是Label是一个只能由VS读取和写入的自定义标签且作为一个为编辑而使用的标记。它们没有其他的功能。

  1. <Project DefaultTargets=“Build“ ToolsVersion=“4.0“ xmlns=‘http://schemas.microsoft.com/developer/msbuild/2003‘ >
  2. <ItemGroup Label=“ProjectConfigurations“ />
  3. <PropertyGroup Label=“Globals“ />
  4. <Import Project=“$(VCTargetsPath)\Microsoft.Cpp.default.props“ />
  5. <PropertyGroup Label=“Configuration“ />
  6. <Import Project=“$(VCTargetsPath)\Microsoft.Cpp.props“ />
  7. <ImportGroup Label=“ExtensionSettings“ />
  8. <ImportGroup Label=“PropertySheets“ />
  9. <PropertyGroup Label=“UserMacros“ />
  10. <PropertyGroup />
  11. <ItemDefinitionGroup />
  12. <ItemGroup />
  13. <Import Project=“$(VCTargetsPath)\Microsoft.Cpp.targets“ />
  14. <ImportGroup Label=“ExtensionTargets“ />
  15. </Project>


以下面的例子为参照,分析一下上面每一个元素是什么以及它们为什么会以这种方式进行排列布局。

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  3. <ItemGroup Label="ProjectConfigurations">
  4. <ProjectConfiguration Include="Debug|Win32">
  5. <Configuration>Debug</Configuration>
  6. <Platform>Win32</Platform>
  7. </ProjectConfiguration>
  8. <ProjectConfiguration Include="Debug|x64">
  9. <Configuration>Debug</Configuration>
  10. <Platform>x64</Platform>
  11. </ProjectConfiguration>
  12. <ProjectConfiguration Include="Release|Win32">
  13. <Configuration>Release</Configuration>
  14. <Platform>Win32</Platform>
  15. </ProjectConfiguration>
  16. <ProjectConfiguration Include="Release|x64">
  17. <Configuration>Release</Configuration>
  18. <Platform>x64</Platform>
  19. </ProjectConfiguration>
  20. </ItemGroup>
  21. <PropertyGroup Label="Globals">
  22. <ProjectGuid>{2B4C8F7A-A827-41E5-B80A-8EE6C0D3AF03}</ProjectGuid>
  23. <Keyword>Win32Proj</Keyword>
  24. <RootNamespace>test</RootNamespace>
  25. </PropertyGroup>
  26. <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  27. <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
  28. <ConfigurationType>Application</ConfigurationType>
  29. <UseDebugLibraries>true</UseDebugLibraries>
  30. <PlatformToolset>v120</PlatformToolset>
  31. <CharacterSet>Unicode</CharacterSet>
  32. </PropertyGroup>
  33. <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
  34. <ConfigurationType>Application</ConfigurationType>
  35. <UseDebugLibraries>true</UseDebugLibraries>
  36. <PlatformToolset>v120</PlatformToolset>
  37. <CharacterSet>Unicode</CharacterSet>
  38. </PropertyGroup>
  39. <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
  40. <ConfigurationType>Application</ConfigurationType>
  41. <UseDebugLibraries>false</UseDebugLibraries>
  42. <PlatformToolset>v120</PlatformToolset>
  43. <WholeProgramOptimization>true</WholeProgramOptimization>
  44. <CharacterSet>Unicode</CharacterSet>
  45. </PropertyGroup>
  46. <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
  47. <ConfigurationType>Application</ConfigurationType>
  48. <UseDebugLibraries>false</UseDebugLibraries>
  49. <PlatformToolset>v120</PlatformToolset>
  50. <WholeProgramOptimization>true</WholeProgramOptimization>
  51. <CharacterSet>Unicode</CharacterSet>
  52. </PropertyGroup>
  53. <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  54. <ImportGroup Label="ExtensionSettings">
  55. </ImportGroup>
  56. <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
  57. <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  58. </ImportGroup>
  59. <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
  60. <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  61. </ImportGroup>
  62. <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
  63. <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  64. </ImportGroup>
  65. <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
  66. <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  67. </ImportGroup>
  68. <PropertyGroup Label="UserMacros" />
  69. <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
  70. <LinkIncremental>true</LinkIncremental>
  71. </PropertyGroup>
  72. <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
  73. <LinkIncremental>true</LinkIncremental>
  74. </PropertyGroup>
  75. <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
  76. <LinkIncremental>false</LinkIncremental>
  77. <IncludePath>E:\osvr-build-ok\boost_1_62_0;$(IncludePath)</IncludePath>
  78. <LibraryPath>E:\osvr-build-ok\boost_1_62_0\lib64-msvc-12.0;$(LibraryPath)</LibraryPath>
  79. </PropertyGroup>
  80. <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
  81. <LinkIncremental>false</LinkIncremental>
  82. <IncludePath>E:\osvr-build-ok\boost_1_62_0;$(IncludePath)</IncludePath>
  83. <LibraryPath>E:\osvr-build-ok\boost_1_62_0\lib64-msvc-12.0;$(LibraryPath)</LibraryPath>
  84. </PropertyGroup>
  85. <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
  86. <ClCompile>
  87. <PrecompiledHeader>Use</PrecompiledHeader>
  88. <WarningLevel>Level3</WarningLevel>
  89. <Optimization>Disabled</Optimization>
  90. <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
  91. <SDLCheck>true</SDLCheck>
  92. </ClCompile>
  93. <Link>
  94. <SubSystem>Console</SubSystem>
  95. <GenerateDebugInformation>true</GenerateDebugInformation>
  96. </Link>
  97. </ItemDefinitionGroup>
  98. <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
  99. <ClCompile>
  100. <PrecompiledHeader>Use</PrecompiledHeader>
  101. <WarningLevel>Level3</WarningLevel>
  102. <Optimization>Disabled</Optimization>
  103. <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
  104. <SDLCheck>true</SDLCheck>
  105. </ClCompile>
  106. <Link>
  107. <SubSystem>Console</SubSystem>
  108. <GenerateDebugInformation>true</GenerateDebugInformation>
  109. </Link>
  110. </ItemDefinitionGroup>
  111. <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
  112. <ClCompile>
  113. <WarningLevel>Level3</WarningLevel>
  114. <PrecompiledHeader>Use</PrecompiledHeader>
  115. <Optimization>MaxSpeed</Optimization>
  116. <FunctionLevelLinking>true</FunctionLevelLinking>
  117. <IntrinsicFunctions>true</IntrinsicFunctions>
  118. <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
  119. <SDLCheck>true</SDLCheck>
  120. </ClCompile>
  121. <Link>
  122. <SubSystem>Console</SubSystem>
  123. <GenerateDebugInformation>true</GenerateDebugInformation>
  124. <EnableCOMDATFolding>true</EnableCOMDATFolding>
  125. <OptimizeReferences>true</OptimizeReferences>
  126. </Link>
  127. </ItemDefinitionGroup>
  128. <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
  129. <ClCompile>
  130. <WarningLevel>Level3</WarningLevel>
  131. <PrecompiledHeader>Use</PrecompiledHeader>
  132. <Optimization>MaxSpeed</Optimization>
  133. <FunctionLevelLinking>true</FunctionLevelLinking>
  134. <IntrinsicFunctions>true</IntrinsicFunctions>
  135. <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
  136. <SDLCheck>true</SDLCheck>
  137. </ClCompile>
  138. <Link>
  139. <SubSystem>Console</SubSystem>
  140. <GenerateDebugInformation>true</GenerateDebugInformation>
  141. <EnableCOMDATFolding>true</EnableCOMDATFolding>
  142. <OptimizeReferences>true</OptimizeReferences>
  143. </Link>
  144. </ItemDefinitionGroup>
  145. <ItemGroup>
  146. <Text Include="ReadMe.txt" />
  147. </ItemGroup>
  148. <ItemGroup>
  149. <ClInclude Include="stdafx.h" />
  150. <ClInclude Include="targetver.h" />
  151. </ItemGroup>
  152. <ItemGroup>
  153. <ClCompile Include="stdafx.cpp">
  154. <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
  155. <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
  156. <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
  157. <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
  158. </ClCompile>
  159. <ClCompile Include="test.cpp" />
  160. </ItemGroup>
  161. <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  162. <ImportGroup Label="ExtensionTargets">
  163. </ImportGroup>
  164. </Project>


<Project DefaultTargets=“Build“ ToolsVersion=“4.0“ xmlns=‘http://schemas.microsoft.com/developer/msbuild/2003‘ > 

这是一个根节点。它指出了MSBuild的版本号,以及当该文件传入到MSBuild.exe中时,要执行的默认target名。

--------------------------------------------------------------------------------------------------

<ItemGroup Label=“ProjectConfigurations“ />

此处会包含大家所熟知的工程配置选项(比如Debug|Win32以及Release|Win32),比如:

  1. <ItemGroup Label="ProjectConfigurations">
  2. <ProjectConfiguration Include="Debug|Win32">
  3. <Configuration>Debug</Configuration>
  4. <Platform>Win32</Platform>
  5. </ProjectConfiguration>
  6. <ProjectConfiguration Include="Debug|x64">
  7. <Configuration>Debug</Configuration>
  8. <Platform>x64</Platform>
  9. </ProjectConfiguration>
  10. <ProjectConfiguration Include="Release|Win32">
  11. <Configuration>Release</Configuration>
  12. <Platform>Win32</Platform>
  13. </ProjectConfiguration>
  14. <ProjectConfiguration Include="Release|x64">
  15. <Configuration>Release</Configuration>
  16. <Platform>x64</Platform>
  17. </ProjectConfiguration>
  18. </ItemGroup>

---------------------------------------------------------------------------------------------

<PropertyGroup Label=“Globals“ />

此处包含工程的层级设置比如ProjectGuid,RootNamespace等。这些属性一般不会在该工程文件中的其他地方被覆盖。该组不是独立的配置,因此一般在工程文件中一般只有一Global组存在。

比如:

  1. <PropertyGroup Label="Globals">
  2. <ProjectGuid>{2B4C8F7A-A827-41E5-B80A-8EE6C0D3AF03}</ProjectGuid>
  3. <Keyword>Win32Proj</Keyword>
  4. <RootNamespace>test</RootNamespace>
  5. </PropertyGroup>


---------------------------------------------------------------------------------------------

<Import Project=“$(VCTargetsPath)\Microsoft.Cpp.default.props“ />

该属性列表包含VC++工程的默认设置。它包含了所有工程设置的定义,比如Platform,PlatformToolset,OutputPath,TargetName,UseofAtl等。以及同样也是所有的项目定义组属性都为每个已知项目组所知。一般来说,该文件中的属性不与特定工具相关的。

 <PropertyGroup Label=“Configuration“ />

该属性组有一个附加的配置条件(比如Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"),且呈现多种版本,每个配置中一种。该属性组包含配置广泛的属性,这些属性在Microsoft.Cpp.props中控制系统属性列表的包含情况。比如,如果定义属性<CharacterSet>Unicode</CharacterSet>,随后系统属性列表的属性microsoft.Cpp.unicodesupport.props将会被包含进来(在属性管理器中能够查看到)。实际上,在Microsoft.Cpp.props中的一个导入,可以看到这行:

<Import Condition=”‘$(CharacterSet)’ == ‘Unicode'”   Project=”$(VCTargetsPath)\microsoft.Cpp.unicodesupport.props”/>

比如:

  1. <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  2. <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
  3. <ConfigurationType>Application</ConfigurationType>
  4. <UseDebugLibraries>true</UseDebugLibraries>
  5. <PlatformToolset>v120</PlatformToolset>
  6. <CharacterSet>Unicode</CharacterSet>
  7. </PropertyGroup>
  8. <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
  9. <ConfigurationType>Application</ConfigurationType>
  10. <UseDebugLibraries>true</UseDebugLibraries>
  11. <PlatformToolset>v120</PlatformToolset>
  12. <CharacterSet>Unicode</CharacterSet>
  13. </PropertyGroup>
  14. <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
  15. <ConfigurationType>Application</ConfigurationType>
  16. <UseDebugLibraries>false</UseDebugLibraries>
  17. <PlatformToolset>v120</PlatformToolset>
  18. <WholeProgramOptimization>true</WholeProgramOptimization>
  19. <CharacterSet>Unicode</CharacterSet>
  20. </PropertyGroup>
  21. <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
  22. <ConfigurationType>Application</ConfigurationType>
  23. <UseDebugLibraries>false</UseDebugLibraries>
  24. <PlatformToolset>v120</PlatformToolset>
  25. <WholeProgramOptimization>true</WholeProgramOptimization>
  26. <CharacterSet>Unicode</CharacterSet>
  27. </PropertyGroup>

---------------------------------------------------------------------------------------------

<Import Project=“$(VCTargetsPath)\Microsoft.Cpp.props“ />

该属性列表直接或通过导入的方式,为许多工具相关的属性定义了默认值,比如编译器的优化,警告级别属性等。MIDL(微软接口定义语言)工具的类库名属性等。另外,它还导入许多的系统属性列表,这些列表是基于在上面的属性组中定义的配置属性。

比如:

  1. <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  2. <ImportGroup Label="ExtensionSettings">
  3. </ImportGroup>
  4. <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
  5. <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  6. </ImportGroup>
  7. <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
  8. <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  9. </ImportGroup>
  10. <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
  11. <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  12. </ImportGroup>
  13. <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
  14. <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  15. </ImportGroup>


---------------------------------------------------------------------------------------------

<ImportGroup Label=“ExtensionSettings“ />

该组包含属性列表的导入,Build客制化部分(或客制化的Build规则,由于这些特性在早期的版本被调用过)。build客制化由三个文件来定义:a.targets文件,a.props文件以及.xml文件。而该导入组包含了.props文件。


---------------------------------------------------------------------------------------------

<ImportGroup Label=“PropertySheets“ />

该组包含用户属性列表的导入。这些属性列表是通过VS的属性管理添加的。这些导入的排列顺序是与属性管理中相对应的。工程文件通常包含多种此类导入组的实例,每个工程配置都有一个相对应。


---------------------------------------------------------------------------------------------

<PropertyGroup Label=“UserMacros“ />

UserMacros作为变量用来客制化build过程。比如,可定义一个用户宏$(CustomOutputPath)来定义客制化的输出路径,且也可用它来定义其他变量。需要注意的是,在vs2010中,尽管支持属性列表,但是由于不支持配置用户宏,IDE也没有去处理该组属性。

<PropertyGroup Label="UserMacros" />


---------------------------------------------------------------------------------------------

<PropertyGroup />

该属性组通常以一个附加配置条件出现,也会看到多种属性组的实例,每个配置有一个。它与其他属性组的不同点是它没有label标签(实际上也可把它看作有一个label标签,只是这个标签是一个空字符串而已)。该组包含工程配置的层级设置。这些设置应用到指定item组部分的所有文件。build客制化item定义的元数据也是在这里初始化的。

比如:

  1. <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
  2. <LinkIncremental>true</LinkIncremental>
  3. </PropertyGroup>
  4. <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
  5. <LinkIncremental>true</LinkIncremental>
  6. </PropertyGroup>
  7. <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
  8. <LinkIncremental>false</LinkIncremental>
  9. <IncludePath>E:\osvr-build-ok\boost_1_62_0;$(IncludePath)</IncludePath>
  10. <LibraryPath>E:\osvr-build-ok\boost_1_62_0\lib64-msvc-12.0;$(LibraryPath)</LibraryPath>
  11. </PropertyGroup>
  12. <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
  13. <LinkIncremental>false</LinkIncremental>
  14. <IncludePath>E:\osvr-build-ok\boost_1_62_0;$(IncludePath)</IncludePath>
  15. <LibraryPath>E:\osvr-build-ok\boost_1_62_0\lib64-msvc-12.0;$(LibraryPath)</LibraryPath>
  16. </PropertyGroup>


---------------------------------------------------------------------------------------------

<ItemDefinitionGroup />

与上一条的属性组类似,只是它包含的是item的定义以及item定义的元数据,而不是属性的。

比如:

  1. <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
  2. <ClCompile>
  3. <PrecompiledHeader>Use</PrecompiledHeader>
  4. <WarningLevel>Level3</WarningLevel>
  5. <Optimization>Disabled</Optimization>
  6. <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
  7. <SDLCheck>true</SDLCheck>
  8. </ClCompile>
  9. <Link>
  10. <SubSystem>Console</SubSystem>
  11. <GenerateDebugInformation>true</GenerateDebugInformation>
  12. </Link>
  13. </ItemDefinitionGroup>
  14. <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
  15. <ClCompile>
  16. <PrecompiledHeader>Use</PrecompiledHeader>
  17. <WarningLevel>Level3</WarningLevel>
  18. <Optimization>Disabled</Optimization>
  19. <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
  20. <SDLCheck>true</SDLCheck>
  21. </ClCompile>
  22. <Link>
  23. <SubSystem>Console</SubSystem>
  24. <GenerateDebugInformation>true</GenerateDebugInformation>
  25. </Link>
  26. </ItemDefinitionGroup>
  27. <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
  28. <ClCompile>
  29. <WarningLevel>Level3</WarningLevel>
  30. <PrecompiledHeader>Use</PrecompiledHeader>
  31. <Optimization>MaxSpeed</Optimization>
  32. <FunctionLevelLinking>true</FunctionLevelLinking>
  33. <IntrinsicFunctions>true</IntrinsicFunctions>
  34. <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
  35. <SDLCheck>true</SDLCheck>
  36. </ClCompile>
  37. <Link>
  38. <SubSystem>Console</SubSystem>
  39. <GenerateDebugInformation>true</GenerateDebugInformation>
  40. <EnableCOMDATFolding>true</EnableCOMDATFolding>
  41. <OptimizeReferences>true</OptimizeReferences>
  42. </Link>
  43. </ItemDefinitionGroup>
  44. <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
  45. <ClCompile>
  46. <WarningLevel>Level3</WarningLevel>
  47. <PrecompiledHeader>Use</PrecompiledHeader>
  48. <Optimization>MaxSpeed</Optimization>
  49. <FunctionLevelLinking>true</FunctionLevelLinking>
  50. <IntrinsicFunctions>true</IntrinsicFunctions>
  51. <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
  52. <SDLCheck>true</SDLCheck>
  53. </ClCompile>
  54. <Link>
  55. <SubSystem>Console</SubSystem>
  56. <GenerateDebugInformation>true</GenerateDebugInformation>
  57. <EnableCOMDATFolding>true</EnableCOMDATFolding>
  58. <OptimizeReferences>true</OptimizeReferences>
  59. </Link>
  60. </ItemDefinitionGroup>


---------------------------------------------------------------------------------------------

<ItemGroup />

包含工程中的item(源文件等),一般会有多个item组,每个item类型对应一个。

比如:

  1. <ItemGroup>
  2. <Text Include="ReadMe.txt" />
  3. </ItemGroup>
  4. <ItemGroup>
  5. <ClInclude Include="stdafx.h" />
  6. <ClInclude Include="targetver.h" />
  7. </ItemGroup>
  8. <ItemGroup>
  9. <ClCompile Include="stdafx.cpp">
  10. <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
  11. <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
  12. <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
  13. <PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
  14. </ClCompile>
  15. <ClCompile Include="test.cpp" />
  16. </ItemGroup>


---------------------------------------------------------------------------------------------

<Import Project=“$(VCTargetsPath)\Microsoft.Cpp.targets“ />

以直接或导入方式,定义VC++的target,比如build,clean等

比如:

<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />


---------------------------------------------------------------------------------------------

<ImportGroup Label="ExtensionTargets">

</Project>

该组包含了build客制化target文件的导入。


---------------------------------------------------------------------------------------------

以上的排序是确保编辑的工程文件,可通过IDE给出期望的结果。比如,当在属性页定义一个属性值时,IDE通常会在默认空标签的属性组中替换上所定义的属性。这确保系统属性列表自带的默认值会被用户自定义的值所覆盖。同样地也适用于在尾部引入的target文件,这是由于target文件使用了前面定义的属性以及它们自身通常不定义属性导致的。与此类似,在系统属性列表(包含在Microsoft.Cpp.props中)之后导入的用户属性列表也一样。这确保了用户能够覆盖任何由系统属性列表自带的默认值。

如果一个a.vcxproj文件不是依据这个布局来排列,则build结果可能不会跟所期望的一样。比如,可能在这个不同的布局文件里面,用户通过使用属性页定义的属性由于被系统属性页覆盖掉了,导致在编译期间可能不会被使用。

即使IDE设计的时长可以容忍,即使VS在任何.vcxproj文件上工作都非常顺利。若.vcxproject文件没有导入组属性列表,也将不会在属性管理视图中看到任何的用户属性列表。然而,当通过属性管理器视图添加一个属性列表时,VS会创建一个这样的标签导入组到.vcxproj文件的对应正确位置,且为新的属性列表添加导入。然而,如果.vcxproj文件与上面所描述的布局非常不一致,那么vs可能不知道正确位置是什么,因此,它可能会在一个随意的位置上去创建它。一般来说,VS IDE使用的自动推测会在不太重要的属性上协调.vcxproj文件的一致性。

可能会想知道VS是如何知道往哪儿写一个特定属性的。比如,当在一般属性页中设置UseOfAtl属性时,它会被写入Configuration属性组,而在同一个一般属性页中的TargetName属性则被写入缺少label的属性组中。那些都是通过属性自己告诉给vs的。实际上是通过属性页xml文件的属性模式来进行的。一个这样的信息片段包含一个在目标文件中(要写入值的那个文件)的Rule规则属性的优先位置信息。通过利用已经存在的label标签来定义该优先位置。label标签用来区分同样类型(比如两个属性组)的不同顶级元素。因此,一个属性能够在属性页xml文件中被描述,当在工程文件中要定义时,属性组存放在该xml文件中,

最后,以下是MSBuild文件的架构来说明一个vs2010的属性列表(.props)文件的布局。基于以上的讨论来推断布局元素的功能。

  1. <Project ToolsVersion=“4.0“ xmlns=“http://schemas.microsoft.com/developer/msbuild/2003“>
  2. <ImportGroup Label=“PropertySheets“ />
  3. <PropertyGroup Label=“UserMacros“ />
  4. <PropertyGroup />
  5. <ItemDefinitionGroup />
  6. <ItemGroup />
  7. </Project>

总结一下,按序布局的.vcxproj以及.props文件与MSBuild顺序评估模型是一致的。label的应用帮助IDE在该文件的正确位置读取和写入元素定义。

关闭 返回顶部
联系我们
Copyright © 2011. 聚财吧. All rights reserved.