在 .NET Standard 2 中禁用可传递项目引用 [英] Disable transitive project reference in .NET Standard 2

查看:26
本文介绍了在 .NET Standard 2 中禁用可传递项目引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ASP.NET Core 2.0 编写一个 MVC 网站.

I'm writing an MVC website using ASP.NET Core 2.0.

在 ASP.NET Core 项目(我们称之为 Web)中,我在同一个解决方案中引用了一个 .NET Standard 2 项目(我们称之为 Service).Service 项目还引用了解决方案中的第三个 .NET Standard 2 库(我们称之为 Business).Business 项目声明了一个名为 Model 的类型.

In the ASP.NET Core project (let's call it Web), I reference a .NET Standard 2 project in the same solution (let's call it Service). The Service project also references a third .NET Standard 2 library in the solution (let's call this one Business). The Business project declares a type called Model.

问题是我可以在Web项目中使用Model(即编译器看到类型Model,我可以做>var a = new Model();) 就好像Web 项目引用了Business,但实际上它只引用了Service.

The problem is that I can use Model in the Web project (i.e. the compiler sees the type Model and I can do var a = new Model();) as if the Web project has referenced Business, but it actually only has a reference to Service.

如何在 Web 中隐藏 Model?这是 ASP.NET Core 2 的新功能还是所有 .NET Standard 项目都是这样?

How can I hide Model from Web? Is this a new feature in ASP.NET Core 2 or all .NET Standard projects are like this?

编辑

此处所述,这是由于可传递项目引用,这是 .NET Standard 中的一项新功能",但是如何我要修吗?

As specified here, this is due to transitive project references which is a new "feature" in .NET Standard, but how do I fix it?

推荐答案

嗯,我的问题很接近这里标记为重复的问题,但要解决它需要不同的策略.

Well my question was close to one marked as duplicate here but to solve it requires different tactic.

感谢Federico Dipuma"的评论以及在这里给出的答案能够解决这个问题.

Thanks to comment from "Federico Dipuma" and the answer given here I was able to solve this problem.

您应该编辑 Service.csproj 文件并将 PrivateAssets="All" 添加到您不想流向的 ProjectReference 键顶.

You should edit the Service.csproj file and add PrivateAssets="All" to ProjectReference keys you don't want to flow to top.

<ItemGroup>
    <ProjectReference Include="..Business.csproj" PrivateAssets="All" />
</ItemGroup>

这篇关于在 .NET Standard 2 中禁用可传递项目引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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