1

XML プロジェクト ファイルを圧縮しようとしています。プロジェクトは単一のソース ファイルをコンパイルしますが、同じ設定を複数回複製する傾向があるため、サイズが 11 KB を超えています。ソース ファイルごとの設定を移動し、さまざまな条件ステートメントまたは式を使用して構成 PropertyGroup に引き上げようとしています (XML ではそれらを何と呼びますか?)。

MSDN ブログの .vcxproj および .props ファイル構造のガイドを正しく解析している場合は、設定をプロパティ グループに配置できます。

<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 が設定を取得しないのはなぜですか? どうすれば修正できますか?


これは、プリプロセッサ マクロを含むプロパティ ページのスクリーン キャプチャです。変更された XML には次のものがありますが、Visual Studio には反映されていません。の有無にかかわらず試してみましたClCompile

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

ここに画像の説明を入力


圧縮されたプロジェクト ファイルは次のとおりです。オリジナルはここにあります。プロジェクトは 1 つのソース ファイルをコンパイルし、サイズが 11KB を超えますが、圧縮されていません。

私のモッドは から始まり<!-- 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>
4

1 に答える 1

2

ファイルの初期設定が早すぎるため、設定が上書きされます。VS と同じように実行<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />.

私の間違いを更新してください。一見すると、設定をプロパティとして定義しているため、設定はまったく効果がありません。VS と同じように実行し、それらItemDefinitionGroupを a ではなくan で定義しますPropertyGroup(ここでも、msbuild 評価規則に従って正しい場所に配置します)。

圧縮に関しては、設定を別のプロパティ シートに保存し、それらをインポートします。賢明に整理すれば、プロジェクト ファイルの設定自体を編集する必要がなくなります (そのため、VS が設定された ItemDefinitionGroups は空になります)。ただし、必要に応じてプロパティ シートを追加/削除するだけで、プロジェクト ファイルは単なるコンテナーになります。ソース/ヘッダー ファイルとプロパティ シート用。VS GUI (「Property Manager」と呼ばれます) でインポートを行うと、それらは自動的に前述の正しい場所に配置され、順序も問題ありません。プロジェクトと同じオプション ダイアログを使用して、VS で編集することもできます。

プロパティ シートの階層全体を作成して他のものをインポートできることに注意してください。これは繰り返しを避けるのに役立ちます。たとえば、Ws2_32.lib を各構成/プラットフォーム コンボに手動で追加する代わりに、それを行うプロパティ シートをインポートするだけです。プラットフォーム/構成などに応じて名前が異なるライブラリに特に便利です。また、コンパイラ/リンカー/用に別の標準プロパティ シートをいくつか作成したとします...それらを「マスター」シートに追加できます。サンプル:

ここに画像の説明を入力

于 2016-10-04T10:44:07.593 に答える