简体   繁体   English

Powershell 安装 Nuget 包

[英]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.

相关问题 Nuget的Powershell安装包 - Powershell Install-Package from Nuget 无法在脚本 Powershell 中安装 package NuGet - Can't install the package NuGet in a Script Powershell 由于“无法初始化PowerShell主机”,无法安装nuget包 - Can't install nuget package because of “Failed to initialize the PowerShell host” 如何安装可以从 Powershell 加载的 nuget 包 - How to install a nuget package such as it can be loaded from Powershell 由于“无法初始化PowerShell主机”而无法安装nuget软件包 - Can't install nuget package because of “Failed to initialize the PowerShell host” 无法在 powershell 核心 6.2.0 中安装 nuget 包提供程序 - Can't install nuget package provider in powershell core 6.2.0 使用NuGet从PowerShell安装软件包时报告服务器错误 - Server error reported when using NuGet to install package from PowerShell Powershell: How do I install the Nuget provider for PowerShell on a unconnected machine so I can install a nuget package from the PS command line? - Powershell: How do I install the Nuget provider for PowerShell on a unconnected machine so I can install a nuget package from the PS command line? 如何在正常的PowerShell会话中(不在Visual Studio中)运行Nuget PowerShell cmdlet Install-Package? - How can I run Nuget PowerShell cmdlet Install-Package in normal PowerShell session (not inside Visual Studio)? Find-Package 有效,但 Install-Package 在 powershell 中使用 Chocolatey 仅显示 nuget 错误 - Find-Package works but Install-Package shows only nuget error using chocolatey in powershell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM