簡體   English   中英

如何使用 Install-Package 為 PowerShell 安裝 MongoDB 驅動程序?

[英]How do I install MongoDB driver for PowerShell using Install-Package?

我正在嘗試從 powershell 與 MongoDB 交互,並且需要安裝驅動程序包。 根據https://www.nuget.org/packages/mongodb.driver 的說明,我發出命令:

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

您可以使用 .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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM