尝试安装 ZXing.Net 库时,NuGet 程序包管理器控制台 returns InvalidOperation

NuGet Package Manager Console returns InvalidOperation when trying to install the ZXing.Net library

我正在尝试将 ZXing.Net 库安装到 VisualStudio 2019 以在 Unity 中使用,但在控制台中输入命令 returns InvalidOperation

的类别

我刚刚在 nuget.org 中复制粘贴了 ZXing.Net 的代码,但它返回了这个错误:

PM> Install-Package ZXing.Net -Version 0.16.5

Install-Package : The current environment doesn't have a solution open.
At line:1 char:16
+ Install-Package <<<<  ZXing.Net -Version 0.16.5
    + CategoryInfo          : InvalidOperation: (:) [Install-Package], InvalidOperationException
    + FullyQualifiedErrorId : NuGetNoActiveSolution,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand

Install-Package : The current environment doesn't have a solution open.

正如错误消息所示,请检查您是否有一种解决方案至少在 Visual Studio 中打开了一个项目。如果您在出现 no solution open 时 运行 命令(这意味着您没有创建甚至没有打开项目),这就是您收到该错误的预期行为。

当您在程序包管理器控制台中使用命令 Install-Package ZXing.Net -Version 0.16.5 时,您至少应确保在 Default Project 下拉列表中选择了特定项目。参见 Package Manager Console

For normal situation:

如果我们创建一个新的简单 C# 控制台或 class 库项目,请确保在包管理器控制台 window 中选择该项目,然后该命令可以成功将该包安装到 当前项目。 (它还会将软件包安装到 global-package 文件夹中:%userprofile%\.nuget\packages

I am trying to install the ZXing.Net library to VisualStudio 2019 to use in Unity

老实说,我不确定你的意思...如果你只是想将该包安装到 Global-packages 文件夹中,你可以简单地创建一个新的 C# 项目和 运行那个命令。(就像我在For normal situation中描述的那样)

也许您真正需要做的是在 在 Visual Studio[=40] 中打开您的 C# 脚本项目(来自 Unity)之后,将该包安装到您的 C# script project? If so, you can also try to install that package by VS UI, see this =], 在 Solution Explorer 中右击使用 Manage Nuget Packages UI, 然后你可以使用 UI 搜索那个包并像使用命令行一样安装特定版本.参见:

希望对您有所帮助:)