Reputation: 5898
When trying to install a package from our newly created private Nuget Feed i get the following error.
Could not install package 'GC.Timecode 1.0.0.3'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.5.1', but the package does not contain any assembly references or content files that are compatible with that framework.
The Nuget package also targets 4.5.1. (Screenshot take from Nuget Package Explorer)
The Nuget Package is created by Octopack via On premises TFS, and then published to a private Proget Server
Nuspec file looks like this
<?xml version="1.0"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>GC.Timecode</id>
<version>1.0.0.3</version>
<authors>user</authors>
<owners>user</owners>
<licenseUrl>http://example.com</licenseUrl>
<projectUrl>http://example.com</projectUrl>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>The GC.Timecode deployment package, built on 25/01/2016</description>
<releaseNotes />
</metadata>
</package>
Contents of Package
What's going on here?
Upvotes: 20
Views: 71144
Reputation: 497
I think solution may vary from case to case, however, in my case, NuGet package was built/compiled in "Class Library .NET Core 3.1" whilst the project which were using this package belonged to .NET Framework. I just changed the project type to .NET Core 3.1 and added NuGet package again and it worked for me.
Upvotes: 0
Reputation: 12998
Another possibility which I just worked through was that local Nuget tools can be too old.
I was trying to install https://github.com/alastairtree/LazyCache which is a .Net standard 2.0 project. My local project was .NET framework 4.7.2, which is compatible. And yet I got the error cited in the question.
The problem was that my VS2015 installation of Nuget was not the latest. Although under Tools > Extensions it did NOT show any available updates, there was in fact a much newer Nuget available at https://www.nuget.org/downloads (3.6x vs 3.4x I believe).
I installed that and the problem was resolved. Apparently the old Nuget did not understand what .NET Standard was.
Upvotes: 3
Reputation: 41
I was also getting the following message.
Could not install package 'Package Name'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.6.1', 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.
In my case, changing the package management format from packages.config to PackageReference solved the problem.
Upvotes: 4
Reputation: 3574
If you're using nuspec make sure that all installed packages are noted as "dependencies" in the metadata.
<dependencies>
<dependency id="MyIncludedPackage" version="1.13.0" />
</dependencies>
</metadata>
Adding all the packages solved this issue for me.
Upvotes: 2
Reputation: 269
Slippery Pete fixed this problem for me.
The first time I tried to install my Assembly I got:
Could not install package 'Package Name'. You are trying to install this >package into a project that targets '.NETFramework,Version=v4.6.1', 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.
After ensuring my Assembly within the Nuget package was in the 'lib\net45' folder, I still got the error!
However after going to Tools->Options->Nuget->General and clearing the cache, the problem was solved.
Upvotes: 24
Reputation: 526
This happened to me and I didn't find my solution posted to any of these sites, so hopefully this helps someone else.
The message I was getting was:
Could not install package 'Package Name'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.6.1', 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.
I had a Nuget package that was built for all 4.x versions so it shouldn't matter that it didn't specify version 4.6.1 specifically. I tried changing the class library build to 4.0, 4.5, 4.5.2, 4.6, 4.6.1, and 4.6.2 but nothing fixed this problem. I also added multiple versions of the DLL to the package in individual /lib/Net4(5,51,52,6,61,62) folders and the error was still there.
Eventually, I found out the reason for my problem was the initial private Nuget package I created was a "bad" package and that bad package was cached to my local machine.
I fixed the package problem and pushed the new package to our Nuget server (leaving the version name the same), but Nuget inside Visual Studio wasn't pulling down the new package but instead referenced the bad package cached on my local machine at. Package Manager showed the package was updated and displayed the information correctly from our Nuget server but it was never fetching the new package. It was always retrieving the cached package at:
C:\Users\your_user_account\.Nuget\packages\
Simply deleting the package in question under your local user account forced Package Manager to pull down the new package from the server.
Upvotes: 14
Reputation: 1385
Make sure your nuspec file contains a 'lib/net45' target
<package>
<metadata>
...
</metadata>
<files>
<file src="bin\Release\*.*" target="lib/net45" />
</files>
</package>
Upvotes: 14
Reputation: 5898
The problem was that Octopack will by default just replicate the existing folder structure, whereas Nuget will package your dll into a lib folder.
For the lazy, you can use this package in order to Get a nuget package built on every build
https://www.nuget.org/packages/CreateNewNuGetPackageFromProjectAfterEachBuild/
Upvotes: 9