20

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

enter image description here

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

enter image description here

What's going on here?

1
  • 1
    How did you obtain that screenshot, is that from the NuGet Package Explorer if you inspect the lib\net45\assemblyname.dll assembly? Does the package work when not used through your feed, but for example from the filesystem? Does it work on other machines? What does the .NuSpec look like? What are the contents of the package? What feed software do you use?
    – CodeCaster
    Commented Jan 25, 2016 at 11:42

8 Answers 8

24

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.

3
  • 2
    I had this same problem. You can also clear the Nuget cache through the package manager console with this command: nuget locals all -list
    – Matt P
    Commented Aug 17, 2017 at 20:45
  • Huh? All I see with Tools > Options with "NuGet" is NuGet Package Manager, then General as described but then just 3 options: to allow download of missing pkgs, auto-check for them during builds, and to skip applying binding redirects. Nothing about clearing cache.
    – vapcguy
    Commented Jan 27, 2020 at 22:17
  • In Visual Studio 2017 Pro there is a [Clear All NuGet Cache(s)] button on the General page.
    – Tim Hobbs
    Commented Jan 29, 2020 at 8:38
14

Make sure your nuspec file contains a 'lib/net45' target

<package>
  <metadata>
    ...
  </metadata>
  <files>
    <file src="bin\Release\*.*" target="lib/net45" />
  </files>
</package>
0
14

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.

9

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/

2
  • 2
    I will, in 2 days when SO will let me :)
    – MrBliz
    Commented Jan 25, 2016 at 16:07
  • 1
    This package is amazing, you'd be crazy to do it any other way. THANKS!
    – Ian
    Commented Aug 10, 2016 at 10:48
4

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.

1
  • THANKS! I was having a problem installing Microsoft.VisualStudio.PlatformUI in order to use DelegateCommand and changing package.config to packagereference helped to solve the issue. Commented Sep 10, 2020 at 13:28
3

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.

9
  • How did you installed ? Commented Jul 20, 2020 at 15:42
  • @MuhammadAli Starting in Visual Studio 2017, the installer includes the NuGet Package Manager. For 2015 or earlier, see nuget.org/downloads which has downloads for 2015 and 2013 Commented Jul 20, 2020 at 16:26
  • Yeah I have VS2017 installed, But you said I installed new version because VS have old version of nuget installed. So how do you install nuget ? In the downloads I just see an console exe. What to do with that exe ? Please can you explain more ? Commented Jul 20, 2020 at 16:31
  • @MuhammadAli In my case it was 2015. Direct link to the EXE is: dist.nuget.org/win-x86-commandline/latest/nuget.exe . ALso, see: stackoverflow.com/a/47497456/3195477 Commented Jul 20, 2020 at 16:41
  • 1
    Hi I solved it, I was having wrong package like Mono.Android version v8.0 and I was using 6. Commented Jul 31, 2020 at 7:48
2

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.

0

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.