如何使用Nuget与多个解决方案

Ale*_*lov 9 nuget

我有许多解决方案,在不同的文件夹中共享相同的项目,例如,

Common folder
 - common 1
 - common 2
Contracts folder
 - contracts for project A
 - contracts for Project B
Application 1 folder (in this folder I have my solution file)
 - Solution A
 - nuget creates packages folder there
Application 2 folder
 - Solution B
 - nuget creates packages folder there
packages folder( I need this folder at top level, so all projects can reference it)
Run Code Online (Sandbox Code Playgroud)

使用此结构,Nuget在Application 1和Application 2中创建了两个包文件夹

但是所有这些项目和解决方案都相互关联,所以逻辑上最好只有一个包文件夹.

是否可以在nuget中仅设置一个文件夹并将该文件夹用于所有解决方案?

或者我应该以另一种方式构建我的解决方案和项目

Sch*_*478 7

您可以通过将nuget.config文件添加到具有以下内容的每个解决方案来执行此操作

<settings>
<repositoryPath>..\Packages</repositoryPath>
</settings>
Run Code Online (Sandbox Code Playgroud)

确保它们都指向同一个文件夹.

创建此文件时,必须重新启动Visual Studio才能使用此设置.


Bet*_*tty 0

在两个解决方案之间共享存储库实际上是不可能的,就像您更新解决方案 A 中的包一样,解决方案 b 中的项目不会更新,除非它们也在解决方案 A 中(并且可能会自动删除它们的包,因为解决方案 A不再使用它们)。基本上意味着拥有 2 个解决方案文件是多余的,否则您将在不知道的情况下破坏另一个解决方案。

这些解决方案如何相互关联?如果我们有更多的信息,也许还有另一种方法可以解决问题。