问题
Trying to install a package called BarcodeLib from the NuGet Package manager, but it fails with the following message:
Could not install package 'BarcodeLib 2.2.1'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.5', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
From the console:
PM> Install-Package BarcodeLib -Version 2.2.1
Attempting to gather dependency information for package 'BarcodeLib.2.2.1' with respect to project 'XXX', targeting '.NETFramework,Version=v4.5' Gathering dependency information took 498,07 ms Attempting to resolve dependencies for package 'BarcodeLib.2.2.1' with DependencyBehavior 'Lowest' Resolving dependency information took 0 ms
Resolving actions to install package 'BarcodeLib.2.2.1' Resolved actions to install package 'BarcodeLib.2.2.1' Retrieving package 'BarcodeLib 2.2.1' from 'nuget.org'. Install failed. Rolling back...
Package 'BarcodeLib.2.2.1' does not exist in project 'XXX' Package 'BarcodeLib.2.2.1' does not exist in folder 'C:\Projects\SVN\trunk\etc'
Executing nuget actions took 15,28 ms
Install-Package : Could not install package 'BarcodeLib 2.2.1'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.5', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
At line:1 char:1 + Install-Package BarcodeLib -Version 2.2.1 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Install-Package], Exception + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand
Time Elapsed: 00:00:00.5761964
Since the error message indicated that the package did not contain any files targeting .NetFrameWork 4.5, I tried to lower the framework version of my project... but that didn't help.
回答1:
Answering my own question: It was not the package that was built with an older version of .NET framework. Instead it was me who hadn't got the latest dotnet framework version, that the package required. I found this out from downloading the project and trying to open it:
The simple solution was to upgrade Visual Studio 2017 to its latest version. Either by following the link in the messagebox (Download targeting pack for v4.6.2). Most likely there is also a hidden notification about an update in Visual Studio. Show it by writing "Notifications" in quick launch textbox in the upper right corner of Visual Studio 2017, and then choose to automatically install the updates available:
来源:https://stackoverflow.com/questions/54212500/problem-with-nuget-package-lacking-compatible-references-or-files-and-its-simp