Search code examples
nugetnuget-packagevisual-studio-2019zxing.net

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


I am trying to install the ZXing.Net library to VisualStudio 2019 to use in Unity but entering the command in the console returns a category of InvalidOperation

I just copy pasted the code right our of ZXing.Net in nuget.org but it returned this error:

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

Solution

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

    Just as the error message indicates, please check if you have one solution with at least one project open in Visual Studio. If you run the command in when there's no solution open(It means you don't create or even open a project), that's the expected behavior that you get that error.

    When you use the command Install-Package ZXing.Net -Version 0.16.5 in Package Manager Console, you should at least make sure the specific project is selected in Default Project drop-down list. See Package Manager Console.

    For normal situation:

    If we create a new simple C# console or class library project, make sure the project is selected in Package Manager Console window, then the command can succeed to install that package into current project. (Also it will install the package into global-package folder:%userprofile%\.nuget\packages)

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

    To be honest, I'm not certainly sure what you're meaning... If you're just trying to install that package into Global-packages folder, you can simply create a new C# project and run that command.(like what I described in For normal situation)

    Maybe what you actually need to do is to install that package into your C# script project? If so, you can also try to install that package by VS UI, see this, after you open your C# script project(from Unity) in Visual Studio, right-click it in Solution Explorer to use the Manage Nuget Packages UI, then you can use the UI to search that package and install specific version like using command-line. See:

    enter image description here

    Hope it helps :)