为已有的几个项目添加了一个nuget package 后,在解决方法中添加了一个新项目,然后想把这个nuget package添加到这个新建的项目中去,可以此时无法添加。
怎么办那?
【解决方法】
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. |
如果在运行的时候出现如下的提示:
<Project name> already has a reference to <Package>.
那就检查一下项目的package.config文件,如果已经有了引用,就删掉。另外也看一下项目的references,如果有了,也删掉。
如果在运行命令的时候,出现了如下的错误信息。
Install-Package : An error occurred while loading packages from'https://www.nuget.org/api/v2/curated-feeds/microsoftdotnet/': The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. At line:1 char:45 + Get-Project NotesDataExporterCloud.Common | Install-Package Newtonsoft.Json + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Install-Package], InvalidOperationException + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand |
原因是的证书过期了,解决方法是添加自己的Package Source.
注意machine-wide package sources 下面的checkbox一定要勾掉,不然的话运行命令的时候会用这个来链接Nuget,还是会报证书的错误。