简体   繁体   English

如何解决dotnet核心中的nuget依赖地狱?

[英]How to solve nuget dependency hell in dotnet core?

I am developing on an asp.net core solution with a handful of different projects and each project uses a 3rd party NuGet package of a certain versioned library.我正在开发具有少数不同项目的 asp.net 核心解决方案,每个项目都使用某个版本库的 3rd 方 NuGet 包。 These versions, eg 1.0.0 and 2.0.0, have breaking changes.这些版本,例如 1.0.0 和 2.0.0,有重大更改。 Additionally, this library is developed by another project team and it can't be influenced by me.另外,这个库是由另一个项目团队开发的,不受我的影响。 So in the future, there will be versions which are not compatible to another and my constraints are to use one exact version in a specific project.所以在未来,将会有与另一个版本不兼容的版本,我的限制是在特定项目中使用一个确切的版本。

The following is a minimal overview of the solution:以下是该解决方案的最小概述:

  • MySolution我的解决方案
    • WebApp网络应用程序
    • Project1项目1
      • CustomLibrary (v1.0.0)自定义库 (v1.0.0)
    • Project2项目2
      • CustomLibrary (v2.0.0)自定义库 (v2.0.0)

During development in Visual Studio, everything is fine and I can use the individual methods of my versioned library in each project.在 Visual Studio 的开发过程中,一切都很好,我可以在每个项目中使用我的版本库的各个方法。 If I finally publish my application, there is only one CustomLibrary.dll with v2.0.0 in the output folder.如果我最终发布我的应用程序,输出文件夹中只有一个v2.0.0 的 CustomLibrary.dll

I am a little bit confused about that.我对此有点困惑。 Does this dll hold both versions and dotnet can resolve them during runtime?这个 dll 是否包含两个版本并且 dotnet 可以在运行时解析它们? If this is not the case, the application will fail during runtime because the methods and output of v1.0.0 can be entirely different from v2.0.0.如果不是这种情况,应用程序将在运行时失败,因为 v1.0.0 的方法和输出可能与 v2.0.0 完全不同。

(In .Net framework I could do this , but it seems it doesn't apply in .Net Core) (.NET Framework中我能做到这样,但似乎并不在.net中的核心应用)

Is there a solution to deploying different versions of the same strong-named library?是否有部署同一强命名库的不同版本的解决方案? I would imagine that it should be possible to deploy specific versions of NuGet packages?我想应该可以部署特定版本的 NuGet 包吗?

I'd really appreciate it if you could help me out.如果您能帮助我,我将不胜感激。

There are a couple of .NET Core architectural limitations which will impact application design:有几个 .NET Core 架构限制会影响应用程序设计:

  1. One cannot load into single .NET Core process different versions of the same assembly at the same time.不能同时加载到单个 .NET Core 处理同一程序集的不同版本。 This limitation will prevent your app from using both projects at the same time.此限制将阻止您的应用同时使用两个项目。
  2. There is no publishing process that would magically combine two versions of the assembly into one universal assembly.没有任何发布过程可以将程序集的两个版本神奇地组合成一个通用程序集。

Keeping this in mind you would need to redesign your app and load Project1 with CustomLibrary v1.0.0 dynamically during the runtime.记住这一点,您需要重新设计您的应用程序并在运行时动态加载带有 CustomLibrary v1.0.0 的 Project1。 The same goes for the Project2. Project2 也是如此。 You should end up with a new architecture where Project1 and Project2 would be published into different file system locations and loaded dynamically during runtime.您应该最终得到一个新架构,其中 Project1 和 Project2 将发布到不同的文件系统位置并在运行时动态加载。

In the case, your application needs to work with both Project1 and Project2 during its lifespan it would be possible providing your assembly would play nicely with collectible AssemblyLoadContext.在这种情况下,您的应用程序需要在其生命周期内同时使用 Project1 和 Project2,只要您的程序集可以很好地与可收集的 AssemblyLoadContext 一起使用,就可以了。 The scenario would be that both Project1 and Project2 would be capable to be loaded and unloaded with collectible AssemblyLoadContext and application would switch between them on demand.场景是 Project1 和 Project2 都能够使用可收集的 AssemblyLoadContext 加载和卸载,并且应用程序将根据需要在它们之间切换。

Hope this will help in solving the problem.希望这将有助于解决问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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