.NET Core中的项目引用与以前的.NET版本不同吗? [英] Project references in .NET Core different from previous .NET versions?

查看:265
本文介绍了.NET Core中的项目引用与以前的.NET版本不同吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前使用C#和dotnet Core设置新的Web Api。而且我在引用其他项目时注意到一些奇怪的行为。

Currently setting up a new Web Api using C# and dotnet Core. And i notice some strange behaviour when referencing other projects.

我的解决方案非常简单:DataAccess,BusinessLogic,WebApi

My solutions is pretty straight forward: DataAccess, BusinessLogic, WebApi

WebApi项目引用了BusinessLogic项目,而BusinessLogic项目引用了DataAccess项目。

The WebApi project has a reference to the BusinessLogic project and the BusinessLogic project has a reference to the DataAccess project.

现在,我的WebApi项目是以前的.NET版本。将无法访问DataAccess项目中的任何内容,但是在我当前的设置中,我可以访问WebApi项目中来自DataAccess项目的任何内容,而无需对其进行引用。

Now with previous versions of .NET my WebApi project would not have access to anything from the DataAccess project but in my current setup i can access anything form the DataAccess project in my WebApi project without having a reference to it.

可以有人请解释一下这种行为以及可能的预防方法吗?

Could anyone please explain this behaviour and possibly how to prevent it?

推荐答案

在此线程中找到了一种防止这种行为的方法:在.NET Standard 2中禁用传递项目引用

Found a way to prevent this behaviour in this thread: Disable transitive project reference in .NET Standard 2

编辑项目文件时, Pr可以将ivateAssets 属性设置为 All 以防止此行为。

When editing the project file the PrivateAssets attribute can be set to All to prevent this behaviour.

  <ItemGroup>
    <ProjectReference Include="..\DataAccess\1-DataAccess.csproj" PrivateAssets="All" />
  </ItemGroup>

这篇关于.NET Core中的项目引用与以前的.NET版本不同吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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