如何将 Nuget 与多个解决方案一起使用 [英] How to use Nuget with more than one solution

查看:72
本文介绍了如何将 Nuget 与多个解决方案一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a number of solutions which share the same projects in different folders, for example,

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)

使用此结构,Nuget 在应用程序 1 和应用程序 2 内创建两个包文件夹

With this structure Nuget creates two packages folder inside of Application 1 and Application 2

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

But all of this projects and solutions related to each other, so logically it's better to have only one packages folder.

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

Is it possible to set in nuget only one folder and use that folder for all solutions?

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

Or should I structure my solutions and projects another way?

推荐答案

您可以通过将 nuget.config 文件添加到每个解决方案并包含以下内容来实现

You can do this by adding nuget.config files to each solution with following contents

<settings>
<repositoryPath>..\Packages</repositoryPath>
</settings>

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

Make sure that they all point to the same folder.

制作此文件时,您必须重新启动 Visual Studio 以使其使用此设置(或至少关闭并打开解决方案).

When you make this file, you have to restart Visual Studio to make it use this setting ( or at least close and open the solution).

但更实用的是只创建一个所有解决方案都使用的 nuget.config.只需确保它位于比您希望包含的任何解决方案文件更高的文件夹中.还原时,nuget 管理器从解决方案文件旁边开始搜索此文件,如果未找到,则开始向上查找文件夹结构.

But more practical would be to create just one nuget.config that all solutions make use of. Just make sure it resides on a folder higher then any solution file you wish to include. When restoring, the nuget manager searches for this file, starting from next to the solution file and if not found, start looking higher up the folder structure.

这篇关于如何将 Nuget 与多个解决方案一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆