Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Msbuild 如何合并Directory.Build.props文件中的属性,而不是覆盖属性?_Msbuild_Visual Studio 2019_Msbuild 15 - Fatal编程技术网

Msbuild 如何合并Directory.Build.props文件中的属性,而不是覆盖属性?

Msbuild 如何合并Directory.Build.props文件中的属性,而不是覆盖属性?,msbuild,visual-studio-2019,msbuild-15,Msbuild,Visual Studio 2019,Msbuild 15,我有以下目录.Build.props文件: <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> <LibraryPath>$(BOOST_ROOT)\lib32-msvc-14.2</LibraryPath&g

我有以下
目录.Build.props
文件:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <LibraryPath>$(BOOST_ROOT)\lib32-msvc-14.2</LibraryPath>
    <IncludePath>$(BOOST_ROOT)\</IncludePath>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <LibraryPath>$(BOOST_ROOT)\lib64-msvc-14.2</LibraryPath>
    <IncludePath>$(BOOST_ROOT)\</IncludePath>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <LibraryPath>$(BOOST_ROOT)\lib32-msvc-14.2</LibraryPath>
    <IncludePath>$(BOOST_ROOT)\</IncludePath>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <LibraryPath>$(BOOST_ROOT)\lib64-msvc-14.2</LibraryPath>
    <IncludePath>$(BOOST_ROOT)\</IncludePath>
  </PropertyGroup>
</Project>
然后重新加载项目,再次导致缺少继承的值

我仔细检查了宏是否存在,它们是(
VC_
windowsdk_
宏):

我还尝试将
Directory.Build.props
更改为
Directory.Build.targets
,以便在项目加载后加载,但随后根本无法加载该文件

如何确保我的
目录.Build.props
继承默认值并附加自定义选项

我之所以要这样做,是因为我正在从不推荐使用的
Microsoft.Cpp.Win32.user.props
文件迁移

将扩展名更改为
.targets
仅适用于构建过程,但intellisense/visual Studio无法识别包含文件,并显示大量错误(编译前)。这是不可取的

如何确保我的Directory.Build.props继承默认值 值,并附加自定义选项

我认为不能使用
Directory.Build.props
覆盖项目属性UI中的系统属性

根据您的信息,
LibraryPath
IncludePath
丢失了这些值。请注意有关
目录.Build.props
导入顺序的信息:

Directory.Build.props很早就在Microsoft.Common.props中导入,以后定义的属性对其不可用。因此,避免引用尚未定义(且计算结果为空)的属性。

从NuGet软件包导入.targets文件后,将从Microsoft.Common.targets导入Directory.Build.targets。因此,它可以覆盖大多数生成逻辑中定义的属性和目标,但有时您可能需要在最终导入后自定义项目文件。

你可以参考

具体来说,
Directory.Build.props
就像初始化项目的步骤,并且总是在
Microsoft.Common.props
之前运行,它将默认值设置为大多数系统属性,例如
LibraryPath
IncludePath
。因此,在开始时,值为空是正常的。在此之后,当它执行Microsoft.Common.props时,它有以下内容:

<Includepath Condidtion="'$(Includepath)'==''">$(VC_IncludePath)......</Includepath >
然后将
/p:“VCBuildAdditionalOptions=/useev”
添加到MSBuild参数,以便它接受INCLUDE和LIB变量

你可以参考

2)或者您可以在路径
C:\Users\UserName\AppData\Local\Microsoft\MSBuild\v4.0\Microsoft.Cpp.xxx.user.props中使用初始函数来添加额外的includepath,库路径如下:

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ImportGroup Label="PropertySheets">
  </ImportGroup>
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup>
    <IncludePath>C:\any-name\include;$(IncludePath)</IncludePath>
    <LibraryPath>C:\any-name\lib;$(LibraryPath)</LibraryPath>
  </PropertyGroup>
  <ItemDefinitionGroup />
  <ItemGroup />
</Project>

C:\any name\ include$(包括路径)
C:\anyname\lib$(图书馆路径)

希望能对你有所帮助。

钱佩里的答案需要改进。 以下是我关注的问题:

  • INCLUDE/LIB env vars对于所有希望使用此函数的项目都是全局的 方法。
    必须为每个项目设置MSBuild参数
  • 不推荐使用user.props,而且对所有项目都是全局的
  • Directory.Build.props的问题是在定义$(IncludePath)和$(LibraryPath)之前包含它。您可以手动设置VS的默认路径,但这是一种糟糕的做法

    要使用user.props继任者目录.Build.props和IntelliSense,我建议使用
    AdditionalIncludeDirectories
    AdditionalLibraryDirectories

    下面是Directory.Build.props配置的示例:

    
    $(BOOST_ROOT)
    lib32
    lib64
    \调试
    $(BoostPath);%(其他包括董事)
    $(BoostPath)\$(BoostPlatform)-msvc-$([System.Text.RegularExpressions.Regex]::替换($(PlatformToolset),“v(\d+)(\d)$”,“$1.$2”)$BoostDebug;%(附加图书馆目录)
    
    如果要在项目内设置其他路径,请确保添加
    ;%(其他包括目录)
    ;%(AdditionalLibraryDirectory)
    分别包含props文件的路径

    BoostDebug
    属性设置为编译调试库的位置。在本例中,它将是lib32-msvc-14.2/debug/

    正则表达式术语
    $([System.Text.RegularExpressions.regex]::replace($(PlatformToolset),“v(\d+)(\d)$,“$1.2”)
    将平台工具集转换为库路径附录
    14.2

    为了可读性,最好在PropertyGroup中初始化它,但是
    $(PlatformToolset)
    不会在解析props文件时就初始化。幸运的是,当设置
    $(PlatformToolset)
    时,将在链接时间对
    附加库目录
    进行评估

    如果您想要更好的可读性或需要对
    $(PlatformToolset)
    执行更复杂的操作,我建议另外使用目录.Build.targets配置。解析此文件时,
    $(PlatformToolset)
    将已初始化。
    示例目录.Build.targets

    
    $([System.Text.RegularExpressions.Regex]::替换($(PlatformToolset),“v(\d+)(\d)$”,“$1.2”))
    $(BoostPath)\$(BoostPlatform)-msvc-$(BoostToolset)$BoostDebug;%(附加图书馆目录)
    
    恐怕您不能使用
    目录.Build.props
    覆盖这些值,因为它在定义默认继承值的
    Microsoft.Common.props
    之前运行。因此,它始终无法覆盖系统值,而只能创建一些自定义属性以供覆盖或以后使用。看起来这是目前无法解决的问题。使用
    Microsoft.Cpp.Win32.user.props
    set INCLUDE=xxxx
    set LIB=xxxx\lib32-msvc-14.2
    
    <?xml version="1.0" encoding="utf-8"?>
    <Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <ImportGroup Label="PropertySheets">
      </ImportGroup>
      <PropertyGroup Label="UserMacros" />
      <PropertyGroup>
        <IncludePath>C:\any-name\include;$(IncludePath)</IncludePath>
        <LibraryPath>C:\any-name\lib;$(LibraryPath)</LibraryPath>
      </PropertyGroup>
      <ItemDefinitionGroup />
      <ItemGroup />
    </Project>