VS不尊重PropertyGroup配置设置
我试图压缩一个XML项目文件。该项目编译单个源文件,但其大小超过11 KB,因为喜欢多次复制相同的设置。我试图移动每个源文件设置并将它们提升到配置PropertyGroup中,使用不同的条件语句或表达式(XML称为它们是什么?)。VS不尊重PropertyGroup配置设置
如果我从MSDN博客正确地分析A guide to .vcxproj and .props file structure,我们可以将设置IIN属性组:
<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似乎在使用它自己的设置。
我有几个问题:
有一个Visual Studio设置来告诉它停止sraying每一个设置到每一个源文件?没有理由将每个源文件的175x4次设置复制到每个配置中。
Visual Studio是否有一个压实工具,所以我不必亲手做这个工作?它非常繁琐的工作。
为什么Visual Studio不能提取设置?我如何解决它?
这里有一个属性页,其中包括预处理宏的屏幕截图。修改后的XML具有以下内容,这并不反映在Visual Studio中。我已经尝试过,没有ClCompile
。
<!-- Debug Configurations -->
<PropertyGroup Condition="'$(Configuration)'=='Release'" Label="Release Configuration">
<ClCompile>
<PreprocessorDefinitions>CRYPTOPP_DLL_ONLY;%(PreprocessorDefinitions)</PreprocessorDefinitions>
...
</ClCompile>
</PropertyGroup>
这里的压缩项目文件。该original can be found here。该项目编译1个源文件,其超过11KB的大小未压缩。
我的mods开始于<!-- All Configurations -->
,结束于<!-- Back to Visual Studio boilerplate -->
。我还没有完成所有设置,但已完成的设置(如预处理器宏和运行时库)并未在Visual Studio中反映出来。
<?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>
您的设置被覆盖,因为您将它们放在文件中太早。像VS一样做,并在<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
之后将它们放在之后。
更新我的错误;在第二眼,你的设置没有任何影响,因为你将它们定义为属性。如做确实VS,并在ItemDefinitionGroup
而不是PropertyGroup
定义它们(再次,在正确的位置为每MSBuild的评价规则)
至于压实:存放在单独的属性表设置,并导入这些。如果明智地组织起来,这将允许您不必再编辑项目文件设置(因此VS填充的ItemDefinitionGroups将为空),但是您只需根据需要添加/删除属性表,而项目文件只是一个容器源/头文件和属性表。如果你在VS gui中进行导入(称为'物业经理'),它们将自动结束在前面提到的正确位置,并且订单也会正常。它们也可以通过与项目相同的选项对话框在VS中进行编辑。
请注意,您可以创建导入其他属性的整个层次结构,这有助于避免重复。例如。而不是手动将Ws2_32.lib添加到每个配置/平台组合中,您只需导入属性表即可。特别适用于根据平台/配置等具有不同名称的库。并且假设您已经创建了一些标准属性表单独编译器/链接器/ ...,您可以将它们添加到“主”一个。示例:
谢谢@stijn。 *“...将它们放在 '....”*之后 - 不幸的是,这也不起作用。我继续移动它们,加上'',把''带走,<其他猜测>。它非常不幸的微软没有正确记录这些东西。自从我进入两天以来,这已经成为我时间的完全浪费。而且我也没有更接近正确设置EnableEnhancedInstructionSet,因此X64代码仍然比Win32代码运行得慢。 –
jww
我敢打赌,鲍尔默正在计算他的奖金时正在嘲笑我的屁股。自2010年以来,我已花费了超过3000美元的Visual Studio版本的四个版本,以确保我们能够正确支持它,并且我甚至无法获得一套体面的文档。相反,我不得不来Stack Overflow乞求答案。这是荒唐的。 – jww
从微软获取bizspark。最好0美分,你(n)花费了一切 – Drew