当前使用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版本不同吗?
发布评论