199

我目前正在研究一个最初包含一个项目 ( My.First.Project.Name) 的解决方案。我通过执行以下命令安装了 Castle Windsor:

Install-Package Castle.Windsor

我刚刚在解决方案中添加了另一个项目My.Second.Project.NameInstall-Package Castle.Windsor

'Castle.Core 2.5.2' 已经安装
'Castle.Windsor 2.5.2' 已经安装
My.First.Project.Name 已经引用了 'Castle.Core 2.5.2'
My.First.Project.Name 已经有一个参考“Castle.Windsor 2.5.2”

所以我的问题是:如何说服 NuGet 包管理器将包安装到第二个项目中

4

7 回答 7

325

There's 3 approaches :).
In NuGet 1.1 (The latest release) we've improved powershell pipelining so you can do this:

Get-Project -All | Install-Package SomePackage

That will install "SomePackage" into all of your projects. You can use wildcards to narrow down which projects:

Get-Project Mvc* | Install-Package SomePackage

That will use wildcard semantics (in this case, find all projects that start with mvc).

Get-Project SomeProject | Install-Package SomePackage

That will install SomePackage into SomeProject and nothing else.

于 2011-02-13T01:27:14.737 回答
143

There's two approaches.

As you already learned, the Package Manager Console has a drop down that lists the projects in your solution.

The other approach is to use the -Project flag. Nice thing about that is it gives you Intellisense with the project names! For example:

Install-Package SomePackage -Project MvcApplication2
于 2011-02-13T00:46:27.330 回答
84

答案很简单,令人尴尬。

“包管理器控制台”在其工具栏中有一个名为“默认项目”的下拉菜单,将那里的项目更改为My.Second.Project.Name然后允许Install-Package Castle.Windsor将包安装到第二个项目中。

于 2011-02-11T13:04:13.113 回答
15

在 Visual Studio 2015(从 Nuget v3.1.2 开始)中,语法现在是:

Install-Package ThePackage -ProjectName YourProjectName

注意:-项目名称与-项目

于 2015-08-25T15:38:57.850 回答
8

在 Visual Studio 中,您可以转到Tools -> NuGet Package Manager -> Manage NuGet Packages for the entire Solution. 从那里,选择要在项目之间共享的 Nuget 包,然后单击Manage。这将允许您将特定安装的 NuGet 包添加到您想要的任何其他项目。

于 2015-04-09T18:16:04.340 回答
7

如果您只需要将包从现有项目复制到新项目,只需将 packages.config 文件复制和/或修改到新项目并运行Update-Package -reinstall -Project YourProjectName

于 2015-11-21T21:21:34.003 回答
0

还可以选择强制重新安装。对于某些问题,这对我有帮助。

Update-Package Microsoft.Owin -Reinstall
于 2017-10-31T14:51:15.930 回答