如何使用Install-Package安装适用于PowerShell的MongoDB驱动程序?

时间:2019-05-03 11:24:28

标签: mongodb powershell nuget

我正在尝试从Powershell与MongoDB进行交互,并且需要安装驱动程序包。根据{{​​3}}的指示,我发出命令:

Install-Package MongoDB.Driver -Version 2.8.0

但是我得到一个错误:

Install-Package : A parameter cannot be found that matches parameter name 'Version'.
At line:1 char:32
+ Install-Package MongoDB.Driver -Version 2.8.0
+                                ~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Install-Package], ParameterBindingException
    + FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage

不确定如何进行。

> Get-PackageSource

Name                             ProviderName     IsTrusted  Location                                                                              
----                             ------------     ---------  --------                                                                              
PSGallery                        PowerShellGet    False      https://www.powershellgallery.com/api/v2                                              
nuget.org                        NuGet            False      https://api.nuget.org/v3/index.json                                                   
My Downloads                     NuGet            False      C:\Users\Richard\Downloads                                                            

我尝试从那里下载并安装,但是仍然出现错误:

> Install-Package -scope currentuser mongodb.driver

The package(s) come(s) from a package source that is not marked as trusted.
Are you sure you want to install software from 'My Downloads'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): y
Install-Package : One or more errors occurred.
At line:1 char:1
+ Install-Package -scope currentuser mongodb.driver
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: ($TXkgRG93bmxvYW...2ZXI=\Mi44LjA=\:String) [Install-Package], Exception
    + FullyQualifiedErrorId : One or more errors occurred.,Microsoft.PowerShell.PackageManagement.Cmdlets.InstallPackage

1 个答案:

答案 0 :(得分:0)

您可以使用.NET CLI并使用此命令

  

dotnet添加软件包MongoDB.Driver --version 2.8.0

  

dotnet添加软件包MongoDB.Driver --version 2.9.0-beta1

或删除版本以自动安装最后一个稳定版本,例如:

  

安装包MongoDB.Driver

也请参阅此文章:

https://docs.microsoft.com/en-us/nuget/consume-packages/package-restore-troubleshooting