.net NuGet 用于具有多个项目的解决方案
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5418856/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
NuGet for solutions with multiple projects
提问by Paul Stovell
Suppose I have a solution with 3 projects:
假设我有一个包含 3 个项目的解决方案:
- Core
- UI
- Tests
- 核
- 用户界面
- 测试
Some of the NuGet packages I use will apply to all 3 projects. Some will just apply to UI and Tests, and some will just apply to Tests (like NUnit).
我使用的一些 NuGet 包将适用于所有 3 个项目。有些只适用于 UI 和测试,有些只适用于测试(如 NUnit)。
What is the rightway to set this up using NuGet?
使用 NuGet 进行设置的正确方法是什么?
- Should I use "Add Library Package Reference" on all three projects any time I need a reference?
- Should I use "Add Library Package Reference" the first time I need a package, and then use Add Reference->Browse for subsequent usages?
- 我是否应该在需要参考时在所有三个项目中使用“添加库包参考”?
- 第一次需要包时,是否应该使用“添加库包引用”,然后使用添加引用->浏览进行后续使用?
In either case, how many packages.configfiles should I have?
无论哪种情况,我应该有多少个packages.config文件?
回答by Jason
For anybody stumbling across this, now there is the following option :
对于任何遇到此问题的人,现在有以下选项:
Right-click your solution > Manage NuGet Packages for Solution...
右键单击您的解决方案 > 管理解决方案的 NuGet 包...
... Or:
... 或者:
Tools > Library Package Manager > Manage NuGet Packages for Solution...
工具 > 库包管理器 > 管理解决方案的 NuGet 包...
And if you go to the Installed packages area you can 'Manage' a single package across every project in the solution.
如果您转到已安装的包区域,您可以在解决方案中的每个项目中“管理”单个包。
回答by Simon
Use the console to target multiple projects
使用控制台定位多个项目
Tools > Library Package Manager > Package Manager Console
then use this command
然后使用这个命令
Get-Project PROJECT-NAMES-WITH-COMMAS | Install-Package PACKAGENAME
for example
例如
Get-Project Core,UI | Install-Package FluentDateTime
回答by rasx
This sweet deal works for me:
这个甜蜜的交易对我有用:
PM> Get-Project -all | where {$_.Name -match "Songhay.Silverlight" -and
$_.Name -notmatch "ApplicationLoader" -and $_.Name -notmatch ".Xml"}
| ForEach-Object {Install-Package MvvmLight -project $_.Name}
回答by Aaron Powell
回答by Nekresh
You should use the "Add Library Package Reference" for all your external library on every project in your solution. You'll end up with a packages.config per project.
您应该对解决方案中每个项目的所有外部库使用“添加库包参考”。您最终会为每个项目创建一个 packages.config。
However, you'll download the package only one time and reuse them locally for all your other projects.
但是,您只需下载该包一次,然后在本地将它们重用于所有其他项目。
回答by Dark_Knight
In Package Manager Consoleyou can write the following command:
在包管理器控制台中,您可以编写以下命令:
Get-Project -all | ForEach-Object {Get-Package -ProjectName $_.Name -filter
PACKAGE_NAME} | where-object { $_.id -eq 'PACKAGE_NAME' } | Install-Package
PACKAGE_NAME -Version VERSION
You can use that command for install or update as well (Update-Package)
您也可以使用该命令进行安装或更新(更新包)

