禁用特定 MsBuild 项目的可传递 PackageReference 依赖项 [英] Disable transitive PackageReference dependency for a specific MsBuild project

查看:188
本文介绍了禁用特定 MsBuild 项目的可传递 PackageReference 依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将旧式 MsBuild csproj 项目迁移到使用 PackageReference 格式,并且遇到了传递依赖项的问题.

I am migrating an old style MsBuild csproj project to using PackageReference format and have run into a problem with transitive dependencies.

考虑以下项目 A 引用 NuGet 包 B 和 C,每个包都包含一个使用 PackageReference 的程序集.On Build Project A 使用 IL 合并将 B 作为公共符号并入 A 程序集中,并将 C 作为内化符号合并.项目 D 有一个项目参考 A.

Consider the following Project A reference NuGet package B and C, each containing one single assembly using PackageReference. On Build Project A uses IL merge to incorporate B as public symbols in the A assembly and C as internalized symbols. Project D have a project reference to A.

引用 A、B 和 C 的传递依赖项 D.构建D时,编译错误类型错误 CS0433:A"和B"中都存在类型X"发生.

The transitive dependencies case D to reference A, B and C. When building D, compile errors of the type error CS0433: The type 'X' exists in both 'A' and 'B' occur.

有没有什么办法可以强制 D 在上面的场景中不添加对 B 或 C 的显式引用?

Is there any way to force D to not add an explicit reference to B or C in the scenario above?

推荐答案

我最终使用了 解决方法 将传递依赖移至别名以绕过编译器错误.

I ended up using a workaround to move the transitive dependency to an alias to get around the compiler error.

<Target Name="ChangeAliasesOfBNameAssemblies" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
  <ItemGroup>
    <ReferencePath Condition="'%(FileName)' == 'B'">
      <Aliases>nonmerged</Aliases>
    </ReferencePath>
  </ItemGroup>
</Target>

我尝试使用私有资产,但无法以这种方式消除编译器错误.

I tried to use private assets but couldn't get the compiler error to go away in that way.

这篇关于禁用特定 MsBuild 项目的可传递 PackageReference 依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆