[英]Powershell Install Nuget package
I am trying to find out how I can download and install the NUnit package by using Power Shell script.我试图找出如何使用 Power Shell 脚本下载和安装 NUnit 包。
I tried Install-Package
command but that if of course for the NUGet Package Manager Console.我尝试了Install-Package
命令,但这当然是针对 NUGet 包管理器控制台的。 Any ideas?有什么想法吗?
You need the NuGet package provider to be able to find and download NUnit using Install-Package
.您需要 NuGet 包提供程序才能使用Install-Package
查找和下载 NUnit。 The issue I think you're running into is that if you do not previously have the NuGet package provider installed/configured for PowerShell, the first time you run a command like Install-Package NUnit
, it will prompt you if you want to install the NuGet package provider.我认为您遇到的问题是,如果您之前没有为 PowerShell 安装/配置 NuGet 包提供程序,则第一次运行Install-Package NUnit
类的命令时,它会提示您是否要安装NuGet 包提供程序。
Example:示例:
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
But after I've configured the NuGet provider, it works just fine:但是在我配置了 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.
My answer is building upon @Negorath's.我的答案是建立在@Negorath 的基础上。 I believe they are missing some details:我相信他们遗漏了一些细节:
> 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
As you can see I have NuGet.如您所见,我有 NuGet。 But if you don't you can install with:但如果你不这样做,你可以安装:
> 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'.".
I tried many things then this one helped me to fix this :我尝试了很多东西,然后这个帮助我解决了这个问题:
>Open Powershell (as Admin)
>[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
>Install-PackageProvider -Name NuGet
Then you can see 'nuget' folder in the location : C:\\Program Files\\PackageManagement\\ProviderAssemblies然后您可以在以下位置看到“nuget”文件夹:C:\\Program Files\\PackageManagement\\ProviderAssemblies
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.