Disable transitive project reference in .NET Standard 2

我们两清 提交于 2019-12-18 04:21:48

问题


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

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.

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.

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?

Edit

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


回答1:


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

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

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>


来源:https://stackoverflow.com/questions/46709000/disable-transitive-project-reference-in-net-standard-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!