.NET Core中的项目引用与以前的.NET版本不同吗?

编程入门 行业动态 更新时间:2024-10-13 18:19:59
本文介绍了.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版本不同吗?

本文发布于:2023-11-13 22:49:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1585534.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:版本   项目   NET   Core

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!