VS不尊重PropertyGroup配置设置

时间:2016-10-04 09:01:12

标签: visual-studio msbuild project-files

我试图压缩XML项目文件。该项目编译单个源文件,但其大小超过11 KB,因为它喜欢多次复制相同的设置。我试图移动每个源文件设置并将它们提升到具有不同条件语句或表达式的Configuration PropertyGroup(XML称之为什么?)。

如果我正确地从MSDN博客中解析A guide to .vcxproj and .props file structure,我们可以在属性组中放置设置:

<PropertyGroup Label=“Configuration“ />

  <!– This property sheet (directly or via imports) defines the

  default values for many tool-specific properties such as the

  compiler’s Optimization, WarningLevel properties, Midl tool’s

  TypeLibraryName property, etc...

但是,当我通过关闭VS检查我的修改然后用修改后的项目文件重新打开它时,没有任何设置被选中。 Visual Studio似乎使用自己的设置。

我有几个问题:

  1. 是否有Visual Studio设置告诉它停止将每个设置刻录到每个源文件中?对于每个配置中的每个源文件,没有理由将设置复制175x4次。

  2. Visual Studio是否具有压缩实用程序,因此我不必手动执行此操作?这是一项非常繁琐的工作。

  3. 为什么Visual Studio没有提取设置?我该如何解决?

  4. 这是一个属性页面的屏幕截图,其中包含预处理器宏。修改后的XML具有以下内容,但未在Visual Studio中反映出来。我曾尝试使用ClCompile和不使用<!-- Debug Configurations --> <PropertyGroup Condition="'$(Configuration)'=='Release'" Label="Release Configuration"> <ClCompile> <PreprocessorDefinitions>CRYPTOPP_DLL_ONLY;%(PreprocessorDefinitions)</PreprocessorDefinitions> ... </ClCompile> </PropertyGroup>

    <!-- All Configurations -->

    enter image description here

    这是压缩的项目文件。 original can be found here。{{3}}。该项目编译了1个源文件,其大小超过11KB未压缩。

    我的mod从<!-- Back to Visual Studio boilerplate -->开始,到<?xml version="1.0" encoding="utf-8"?> <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ItemGroup Label="ProjectConfigurations"> <ProjectConfiguration Include="Debug|Win32"> <Configuration>Debug</Configuration> <Platform>Win32</Platform> </ProjectConfiguration> <ProjectConfiguration Include="Debug|x64"> <Configuration>Debug</Configuration> <Platform>x64</Platform> </ProjectConfiguration> <ProjectConfiguration Include="Release|Win32"> <Configuration>Release</Configuration> <Platform>Win32</Platform> </ProjectConfiguration> <ProjectConfiguration Include="Release|x64"> <Configuration>Release</Configuration> <Platform>x64</Platform> </ProjectConfiguration> </ItemGroup> <PropertyGroup Label="Globals"> <ProjectGuid>{1974a53a-9863-41c9-886d-b2b8c2fc3c8b}</ProjectGuid> <RootNamespace>dlltest</RootNamespace> <PlatformToolset>v100</PlatformToolset> </PropertyGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> <!-- All Configurations --> <PropertyGroup Label="Configuration"> <ConfigurationType>Application</ConfigurationType> <UseOfMfc>false</UseOfMfc> <CharacterSet>MultiByte</CharacterSet> <WholeProgramOptimization>true</WholeProgramOptimization> <OutDir>$(Platform)\DLL_Output\$(Configuration)\</OutDir> <IntDir>$(Platform)\$(ProjectName)\$(Configuration)\</IntDir> <ClCompile> <WarningLevel>Level4</WarningLevel> <CallingConvention>StdCall</CallingConvention> <SuppressStartupBanner>true</SuppressStartupBanner> </ClCompile> </PropertyGroup> <!-- Debug Configurations --> <PropertyGroup Condition="'$(Configuration)'=='Debug'" Label="Debug Configuration"> <ClCompile> <PreprocessorDefinitions>CRYPTOPP_DLL_ONLY;%(PreprocessorDefinitions)</PreprocessorDefinitions> <Optimization>Disabled</Optimization> <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks> <IntrinsicFunctions>true</IntrinsicFunctions> <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary> </ClCompile> </PropertyGroup> <!-- Release Configurations --> <PropertyGroup Condition="'$(Configuration)'=='Release'" Label="Release Configuration"> <ClCompile> <PreprocessorDefinitions>NDEBUG;CRYPTOPP_DLL_ONLY;%(PreprocessorDefinitions)</PreprocessorDefinitions> <OmitFramePointers>true</OmitFramePointers> <IntrinsicFunctions>true</IntrinsicFunctions> <FunctionLevelLinking>true</FunctionLevelLinking> <RuntimeLibrary>MultiThreaded</RuntimeLibrary> </ClCompile> </PropertyGroup> <!-- X86 Configurations --> <PropertyGroup Condition="'$(Platform)'=='Win32'" Label="X86 Configuration"> <ClCompile> <EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet> </ClCompile> </PropertyGroup> <!-- X64 Configurations --> <PropertyGroup Condition="'$(Platform)'=='x64'" Label="X64 Configuration"> <ClCompile> <!-- <EnableEnhancedInstructionSet>StreamingSIMDExtensions2</EnableEnhancedInstructionSet> --> <EnableEnhancedInstructionSet>StreamingSIMDExtensions</EnableEnhancedInstructionSet> </ClCompile> </PropertyGroup> <!-- Back to Visual Studio boilerplate --> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <ImportGroup Label="ExtensionSettings"> </ImportGroup> <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets"> <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> </ImportGroup> <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets"> <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> </ImportGroup> <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets"> <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> </ImportGroup> <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets"> <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> </ImportGroup> <PropertyGroup Label="UserMacros" /> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> <ClCompile> <StringPooling>true</StringPooling> <PrecompiledHeader /> </ClCompile> <ResourceCompile> <PreprocessorDefinitions>%(PreprocessorDefinitions)</PreprocessorDefinitions> <Culture>0x0409</Culture> </ResourceCompile> <Link> <AdditionalDependencies>cryptopp.lib;Ws2_32.lib</AdditionalDependencies> <AdditionalLibraryDirectories>$(Platform)\DLL_Output\$(Configuration)</AdditionalLibraryDirectories> <GenerateDebugInformation>true</GenerateDebugInformation> <SubSystem>Console</SubSystem> </Link> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> <ClCompile> <StringPooling>true</StringPooling> <PrecompiledHeader /> </ClCompile> <ResourceCompile> <PreprocessorDefinitions>%(PreprocessorDefinitions)</PreprocessorDefinitions> <Culture>0x0409</Culture> </ResourceCompile> <Link> <AdditionalDependencies>cryptopp.lib;Ws2_32.lib</AdditionalDependencies> <AdditionalLibraryDirectories>$(Platform)\DLL_Output\$(Configuration)</AdditionalLibraryDirectories> <GenerateDebugInformation>true</GenerateDebugInformation> <SubSystem>Console</SubSystem> <TargetMachine>MachineX64</TargetMachine> </Link> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <ClCompile> <PrecompiledHeader /> <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> </ClCompile> <ResourceCompile> <PreprocessorDefinitions>%(PreprocessorDefinitions)</PreprocessorDefinitions> <Culture>0x0409</Culture> </ResourceCompile> <Link> <AdditionalDependencies>cryptopp.lib;Ws2_32.lib</AdditionalDependencies> <AdditionalLibraryDirectories>$(Platform)\DLL_Output\$(Configuration)</AdditionalLibraryDirectories> <GenerateDebugInformation>true</GenerateDebugInformation> <SubSystem>Console</SubSystem> </Link> </ItemDefinitionGroup> <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> <ClCompile> <PrecompiledHeader /> <DebugInformationFormat>ProgramDatabase</DebugInformationFormat> </ClCompile> <ResourceCompile> <PreprocessorDefinitions>%(PreprocessorDefinitions)</PreprocessorDefinitions> <Culture>0x0409</Culture> </ResourceCompile> <Link> <AdditionalDependencies>cryptopp.lib;Ws2_32.lib</AdditionalDependencies> <AdditionalLibraryDirectories>$(Platform)\DLL_Output\$(Configuration)</AdditionalLibraryDirectories> <GenerateDebugInformation>true</GenerateDebugInformation> <SubSystem>Console</SubSystem> <TargetMachine>MachineX64</TargetMachine> </Link> </ItemDefinitionGroup> <ItemGroup> <ClCompile Include="dlltest.cpp" /> </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> </ImportGroup> </Project> 结束。我还没有完成所有设置的提升,但已经完成的设置,如预处理器宏和运行时库,都没有反映在Visual Studio中。

    JpaOutboundGateway

1 个答案:

答案 0 :(得分:2)

您的设置会被覆盖,因为您在文件中过早地设置了这些设置。像VS那样做,并在 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />之后将它们放在

更新我的错误;在第二眼看来,由于您将它们定义为属性,因此您的设置不会产生任何影响。像VS那样做,并在ItemDefinitionGroup而不是PropertyGroup中定义它们(再次,根据msbuild评估规则在正确的位置)

至于压缩:将您的设置存储在单独的属性表中并导入它们。如果明智地组织,这将允许您再也不必编辑项目文件设置(因此VS填充的ItemDefinitionGroups将为空),但您只需根据需要添加/删除属性表,项目文件就是源/头文件和属性表的容器。如果您在VS gui中进行导入(称为&#39;物业经理&#39;),他们将自动结束前面提到的正确位置,并且订单也可以。也可以通过与项目相同的选项对话框在VS中编辑它们。

请注意,您可以创建导入其他属性表的整个层次结构,这有助于避免重复。例如。而不是手动将Ws2_32.lib添加到每个配置/平台组合,您只需导入一个属性表,它就是这样做的。特别适用于具有不同名称的库,具体取决于平台/配置等。假设您已为编译器/链接器/创建了一些标准属性表,您可以将它们添加到“#master”中。一。样品:

enter image description here