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

查看:22
本文介绍了禁用特定 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 的程序集.在构建项目 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.

传递依赖案例 D 引用 A、B 和 C.构建 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天全站免登陆