jww
jww

Reputation: 102296

VS not honoring PropertyGroup Configuration Settings

I'm trying to compact a XML project file. The project compiles a single source file but its over 11 KB in size because of a penchant for duplicating the same settings multiple times. I'm trying to move per-source-file settings and hoisting them up into Configuration PropertyGroup with different condition statements or expressions (what does XML call them?).

If I am parsing A guide to .vcxproj and .props file structure from MSDN Blogs correctly, we can place the settings iin the property group:

<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...

However, when I check my modifications by closing VS and then re-opening it with the modified project file, none of the settings are picked up. Visual Studio appears to be using its own settings.

I have a few questions:

  1. Is there a Visual Studio setting to tell it to stop sraying every setting into every source file? There's no reason to duplicate a setting 175x4 times for each source file crossed into each configuration.

  2. Does Visual Studio have a compaction utility so I don't have to do this by hand? Its very tedious work.

  3. Why is Visual Studio not picking up the settings? How do I fix it?


Here's a screen capture of a property page which includes Preprocessor Macros. The modified XML has the following, which is not reflected in Visual Studio. I've tried with and without the ClCompile.

<!-- Debug Configurations -->
<PropertyGroup Condition="'$(Configuration)'=='Release'" Label="Release Configuration">
  <ClCompile>  
    <PreprocessorDefinitions>CRYPTOPP_DLL_ONLY;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    ...
  </ClCompile>    
</PropertyGroup>

enter image description here


Here's the compacted project file. The original can be found here. The project compiles 1 source file, and its over 11KB in size un-compacted.

My mods start at <!-- All Configurations -->, and ends at <!-- Back to Visual Studio boilerplate -->. I have not finished hoisting all the settings, but the ones that have been done, like Preprocessor Macros and Runtime Library, are not reflected under 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>

Upvotes: 2

Views: 2096

Answers (1)

stijn
stijn

Reputation: 35901

Your settings are overwritten because you put them too early in the file. Do as VS does, and put them after the <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />.

update my mistake; on second sight, your settings don't have any effect whatsoever since you are defining them as properties. Do as VS does, and define them in an ItemDefinitionGroup instead of a PropertyGroup (again, in the correct location as per msbuild evaluation rules)

As for the compacting: store your settings in seperate property sheets and import those. If organized wisely this will allow you to never have to edit the project file settings itself anymore (and hence the VS populated ItemDefinitionGroups will be empty), but you'll just add/remove property sheets as needed and the project file is just a container for source/header files and property sheets. If you do the importing in the VS gui (called 'Property Manager') they will automatically end up in the correct location mentioned before, and the order will also be ok. They can also be edited in VS via the same options dialog as for the project.

Note you can create whole hierarchies of property sheets importing others, which is useful to avoid repetition. E.g. instead of manually adding Ws2_32.lib to each config/platform combo you just import a property sheet which does just that. Especially handy for libraries which have different names depending on platform/configuration etc. And suppose you have created some standard property sheets seperate for compiler/linker/... you can add them to a 'master' one. Sample:

enter image description here

Upvotes: 2

Related Questions