1

在项目属性>C/C++ > Optimization > Whole Program Optimization中,我可以设置/GL.

我可以/GL在共享属性表(.props文件)中启用/禁用它并以此为基础创建许多项目吗?

我努力了 :-

<PropertyGroup>
 <WholeProgramOptimization 
    Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
      true
 </WholeProgramOptimization>

但是,看起来没有任何效果。
我真的必须手动编辑每个项目的属性吗?

我正在使用 VS2017 版本 15.3.0。

相关:Visual Studio 属性表:为什么缺少字符集?

4

1 回答 1

0

要使用您自己的属性表进行此设置,项目 (.vcxproj)必须Microsoft.Cpp.Default.props.

否则,项目级别的属性看起来不错,但不是用于 .c(pp) 的 CL 任务的属性。

例如,假设以下D:\shared\my-customization.props工作表:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ImportGroup Label="PropertySheets" />
  <PropertyGroup Label="UserMacros">
    <MY_CUSTOMIZATION_PREAMBLE>1</MY_CUSTOMIZATION_PREAMBLE>
  </PropertyGroup>

  <PropertyGroup>
    <WholeProgramOptimization>false</WholeProgramOptimization>
     // some others settings suffers from the same restrictions
    <CharacterSet>Unicode</CharacterSet>
    <PlatformToolset>v142</PlatformToolset>
    <UseDebugLibraries Condition="'$(Configuration)'!='Release'">true</UseDebugLibraries>
    <UseDebugLibraries Condition="'$(Configuration)'=='Release'">false</UseDebugLibraries>

    <_PropertySheetDisplayName>MyCustomization preamble</_PropertySheetDisplayName>
  </PropertyGroup>
</Project>

要在您的多个项目中共享它们,必须将其包含在他们的 .vcxproj 中,如下所示:

[...]
  <PropertyGroup Label="Globals">
    [...]
  </PropertyGroup>
  <Import Project="D:\my-customization.props" Condition="'$(MY_CUSTOMIZATION_PREAMBLE)' == ''" />
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
     [...]
  </PropertyGroup>
  [...]
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    [ usual location to import the property sheet ]
于 2020-12-09T13:21:14.713 回答