Search code examples
msbuildvisual-studio-2017nugetnuget-package-restorepackagereference

Newer versions of NuGet.exe can't resolve framework match when restoring older packages (net40, netframework40)


having spent the better part of two days on this, time to get some help.

I am reworking our CI build, and have a VS2017 solution which was on .net 4.6.1, using packages.config style nuget refs, and TeamCity was using the NuGet runner v3.4.4 to restore the packages. It was originally build probably using VS2008 or 10, then converted to 2017 in 2018. Someone checked in the packages directory and it's been that way for years.

Time to bring it up to more modern standards. I converted the projects to use packageReference, and now am using msbuild and the restore;build target to restore my packages and build the solution. Works well EXCEPT for this one package.

Even in VisualStudio 2017 15.8.7, the build (which does the restore of course) is failing to restore the smtp-impostor package using a packageReference with the following error:

NU1202: Package smtp-impostor 2.0.8 is not compatible with net461 (.NETFramework,Version=v4.0). Package smtp-impostor 2.0.8 supports: netframework40 (.NetFramework 4.0,Version=v0.0)

I can't get Google to find a single useful post when searching for "netframework40".

If I use nuget3.4.4 CLI, it works fine (it seems to call msbuild 4.0). If I use nuget 5.6 CLI, I get the error message; it's using the msbuild that comes with Visual Studio 2017.

I see a lot of posts on how to get nuget to use a different version of msbuild, but I don't see how to tell msbuild to use an earlier version of nuget!

I have tried:

  1. retargeting the solution to v4.0 - same error occurs - first part of error just changes to net40
  2. setting the ToolsVersion in the csproj file tag to 14.0
  3. Setting the PlatformToolsVersion property in the csproj file to 14.0.

No dice.

I really don't want to stay with packages.config for this project (and an extra CI build step) nor checkin the single DLL for the package into my repo. It's looking more like I'll jsut have to scrap the packageReference upgrade and stick with the old style nuget runner package restore.

Anyone ever seen this? Any ideas where "netframework40" comes from and why newer nuget can't match it with net40?

Thank you in Advance!


Solution

  • Newer versions of NuGet.exe can't resolve framework match when restoring older packages (net40, netframework40)

    The issue is that this nuget package smtp-impostor 2.0.8 is not compatible with the new PackageReference format and has nothing to do with Nuget V3.4.4 or Nuget V5.6.x.

    Actually, the package was published on 2011 and the new package management format PackageReference was used since VS2017.

    Besides, the author did not make any changes to the package to accommodate the new Packagereference. And I faced the same issue in my side.

    Suggestion

    As a workaround, you have to use packages.config to install this nuget package rather than PackageReference.

    Since VS2017, VS adds the new PackageReference nuget management format and for your old VS2008, it uses Packages.config.

    Or you could contains the author of the nuget package to change it.