Powershell安装Nuget包

时间:2016-04-09 15:50:22

标签: powershell

我试图找出如何使用Power Shell脚本下载和安装NUnit软件包。

我尝试了Install-Package命令,但当然是NUGet程序包管理器控制台。有什么想法吗?

3 个答案:

答案 0 :(得分:0)

您需要NuGet包提供程序才能使用Install-Package查找和下载NUnit。我认为你遇到的问题是,如果以前没有为PowerShell安装/配置NuGet包提供程序,那么第一次运行Install-Package NUnit之类的命令时,如果你想安装它,它会提示你NuGet包提供商。

示例:

Find-Package NUnit
WARNING: The specified PackageManagement provider 'NuGet' is not available.
Find-Package : No match was found for the specified search criteria and package name 'NUnit'.
At line:1 char:1
+ Find-Package NUnit
+ ~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ObjectNotFound: (Microsoft.Power...ets.FindPackage:FindPackage) [Find-Package], Exception
+ FullyQualifiedErrorId : NoMatchFoundForCriteria,Microsoft.PowerShell.PackageManagement.Cmdlets.FindPackage

但是在我配置了NuGet提供程序之后,它运行得很好:

Find-Package -Name Nunit

Name                           Version          Source                         Summary                                                                                                              
----                           -------          ------                         -------                                                                                                              
NUnit                          3.2.0            nuget.org                      NUnit is a unit-testing framework for all .Net languages with a strong TDD focus.  

答案 1 :(得分:0)

我的回答是建立在@ Negorath的基础之上。我相信他们缺少一些细节:

> Get-PackageProvider -ListAvailable

Name                     Version          DynamicOptions
----                     -------          --------------
msi                      3.0.0.0          AdditionalArguments
msu                      3.0.0.0
NuGet                    2.8.5.208        Destination, ExcludeVersion, Scope, SkipDependencies, Headers, FilterOnTag, Contains, AllowPrereleaseVersions, ConfigFile, SkipValidate
PowerShellGet            1.0.0.1          PackageManagementProvider, Type, Scope, AllowClobber, SkipPublisherCheck, InstallUpdate, NoPathUpdate, Filter, Tag, Includes, DscResource, RoleCapability, Command, PublishLocation, ScriptSourceL... Programs                 3.0.0.0          IncludeWindowsInstaller, IncludeSystemComponent

如你所见,我有NuGet。但如果你不这样做,你可以安装:

> Register-PackageSource -Name NuGet -ProviderName PowerShellGet -Verbose
VERBOSE: Repository details, Name = 'PSGallery', Location = 'https://www.powershellgallery.com/api/v2/'; IsTrusted = 'False'; IsRegistered = 'True'.
VERBOSE: Performing the operation "Register Package Source." on target "Package Source 'NuGet' () in provider 'PowerShellGet'.".

答案 2 :(得分:0)

我尝试了很多事情,然后这一件事帮助我解决了这个问题:

>Open Powershell (as Admin)
>[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
>Install-PackageProvider -Name NuGet

然后您可以在以下位置看到“ nuget”文件夹:C:\ Program Files \ PackageManagement \ ProviderAssemblies