首页 > 解决方案 > Shared property sheet (Debug and Release) for a C++ visual studio solution

问题描述

I have a C++ visual studio 2017 solution having 50 projects added to the solution file. I have few external libraries paths for both debug and release build separately.

Example:

    Debug paths:
     ./../External/adobe/debug
     ./../External/ms/debug

    Release paths:
     ./../External/adobe/release
     ./../External/ms/release

I do not want to add these paths to each and individual project. Is there a way to add these paths at solution level for both debug and release configurations.

I tried the Property sheet via property manager, but if I add a path in .props file, it is available in both the configurations. I want to have debug and release path separately in configuration.

标签: c++visual-studiovisual-studio-2010

解决方案


我有类似的问题在解决方案级别添加用户 marcos。

  1. 您可以通过像 SoronelHaetir 的回答一样一次选择所有项目,将自定义属性表文件添加到属性管理器窗口中的每个项目配置节点中,但它会将自定义属性表文件路径添加到项目文件 ( .vcxproj),这可能不是你期望在某些情况下发生。

    以这种方式覆盖属性和目标相当于将以下导入添加到.vcxproj解决方案中的所有文件

    <Import Project=="..\my_custom_property_sheet.props" />
    

    另请参阅共享或重用 Visual Studio 项目设置 - 创建属性表

  2. 如果您只想从 MSBuild 命令提示符覆盖项目属性和目标而不更改项目文件。您可以参考 如何:修改 C++ 项目属性和目标而不更改项目文件

    msbuild myproject.sln /p:ForceImportBeforeCppTargets="C:\sources\my_props.props"
    msbuild myproject.sln /p:ForceImportAfterCppTargets="C:\sources\my_target.targets"
    
  3. 尽管有以下文档,但我们似乎无法将自定义属性表添加到属性管理器窗口中的解决方案级别节点:

    在包含许多项目的大型解决方案中,在解决方案级别创建属性表会很有用。将项目添加到解决方案时,使用 Property Manager 将该属性表添加到项目中。如果项目级别需要,您可以添加新的属性表来设置项目特定的值。

    实际上,我找到了另一个参考:自定义您的构建 - Directory.Build.props 和 Directory.Build.targets。可能对不想污染现有项目.vcxproj文件的人有意义。

    <?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">
        <BOOST_VERSION>boost_1_78_0</BOOST_VERSION>
      </PropertyGroup>
      <PropertyGroup />
      <ItemDefinitionGroup />
      <ItemGroup>
        <BuildMacro Include="BOOST_VERSION">
          <Value>$(BOOST_VERSION)</Value>
        </BuildMacro>
      </ItemGroup>
    </Project>
    

最后,要分别为调试和发布版本添加一些外部库路径,可以参考.vcxproj 和 .props 文件结构 - 每个配置的 PropertyGroup 元素

此属性组有多个实例,每个配置一个用于所有项目配置。每个属性组必须附加一个配置条件。

例如,

<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup Label="ProjectConfigurations"/>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <PlatformToolset>v142</PlatformToolset>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
</Project>

也可以看看


推荐阅读