0
votes

Visual Studio VS2017 v15.9.3

Nuget v4.7.1.5393

We are trying to migrate our project to use Nuget PackageReference. When using packages.config Nuget properly determines that the package matches the project's target framework. But when we try to migrate to PackageReference Nuget throws an error that the package does not support the target framework.

Packages.config: package id="xxx.yyy" version="7.7.7" targetFramework="net462"

Errors when attempting to use PackageReference:

NU1202: Package xxx.yyy 7.7.7 is not compatible with net462 (.NETFramework,Version=v4.6.2). Package xxx.yyy 7.7.7 does not support any target frameworks.

NU1202: Package xxx.yyy 7.7.7 is not compatible with net462 (.NETFramework,Version=v4.6.2) / win. Package xxx.yyy 7.7.7 does not support any target frameworks.

NU1202: Package xxx.yyy 7.7.7 is not compatible with net462 (.NETFramework,Version=v4.6.2) / win-x64. Package xxx.yyy 7.7.7 does not support any target frameworks.

NU1202: Package xxx.yyy 7.7.7 is not compatible with net462 (.NETFramework,Version=v4.6.2) / win-x86. Package xxx.yyy 7.7.7 does not support any target frameworks.

Package restore failed. Rolling back package changes for 'ClassLibrary1'.

12/7/2018 Update.

There appears to be multiple issues with how we're creating the package and how Nuget is interpreting it when using packageReference mode.

The first is how we're specifying the target. Nuget in package.config mode is able to determine that target="lib\net462\project1" targets .Net 4.62 framework but when Nuget is in PackageReference mode target must be changed to just target="lib\net462".

The other problem is that in package.config mode nuget was more forgiving when you had multiple architectures (x86,x84,AnyCpu), you could just include all of them in the tags.

Also, don't even think about trying to have projects in a solution where some use packages.config and others use packageReference. For that matter don'try to have to instances of VS running with different settings for the default package management format.

We've found that we've had to delete the obj folders in the solution and restart VS to clear up some of these issues while trying to convert.

1

1 Answers

0
votes

VS2017 Problem Migrating to Nuget PackageReference

According to the error messages, it seems you are target to the multiple frameworks. If yes, that the reason why you got this issue. Because nuget doesn't pick up PackageReference or project.json dependencies automatically. And it doesn't work with the new .NET SDK multi-targeting projects.

Check this thread for some more details.

To resolve this issue, you can follow below document how to target multiple frameworks:

How to add netstandard2.0 to a C# .NET 4.5 class library

Besides, The PCL library approach was retired, you now have to pick a .NETStandard. You could start the project with the "Class Library (.NET Standard)" project template. You now have the project which use the packagereference by default.

Check this thread.

Hope this helps.