简体   繁体   中英

Project Nuget Depdendency Hell

I have a problem with projects that depend on NuGet packages that they do not consume, or indirectly require dependencies, here is the project structure:

- Data        -> Depends on Entity Framework
- Business
- UI

The problem here is that because Data has a dependency to Entity Framework , this means that the Business layer and also the UI must also install this in their projects.

How can I separate these dependencies so that only the Data layer requires Entity Framework?

This shouldn't be the case. Make sure of the follow points:

  • Make sure your references are set correctly. If you have Resharper (even just the Trial) use the "Optimize References" Command on every project. If you can use it (depends on the VS SKU), generate a Dependency Graph and have a look at it.

在此处输入图片说明 在此处输入图片说明

  • Once the references are cleaned up, go to Tools -> NuGet Package Manager -> Manage NuGet Packages for Solution -> Installed packages -> Button "Manage" and make sure you untick the projects where you don't need your dependencies. Nuget will install/uninstall accordingly.

在此处输入图片说明

  • I suggest you enable Manage NuGet Packages for Solution with a right-click on the solution and follow these instructions if you don't want to check-in Nuget-DLLs into your TFS/SourceControl

在此处输入图片说明

  • If you did it correctly, the minimal version of the dependency graph will look like this

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM