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

查看:95
本文介绍了禁用.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 (即编译器看到的类型为模型,我可以执行 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 隐藏模型?这是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天全站免登陆