NU1202: Package is not compatible with net50-windows

Viewed 16585

I have a .NET 5 WPF application (x64) that references a user control library. When I reference the library directly, everything works.

But when I create a Nuget package and then build the app referencing the Nuget package on my build server I get:

NU1202: Package MyControls is not compatible with net50-windows (.NETFramework,Version=v5.0,Profile=windows) / win-x64.

Package MyControls supports:

  • net50-windows7.0 (.NETFramework,Version=v5.0,Profile=windows7.0)
  • netcoreapp3.1 (.NETCoreApp,Version=v3.1)

The MyControls .csproj file contains this:

  <PropertyGroup>
    <TargetFrameworks>netcoreapp3.1;net5.0-windows</TargetFrameworks>
    <UseWPF>true</UseWPF>
    <RuntimeIdentifiers>win;win-x64</RuntimeIdentifiers>
  </PropertyGroup>

The app .csproj file contains this:

 <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net5.0-windows</TargetFramework>
    <UseWPF>true</UseWPF>
    <RuntimeIdentifiers>win-x64</RuntimeIdentifiers>
   
  </PropertyGroup>

I don't understand why it outputs a package for windows 7. I found this link that describes it: https://github.com/dotnet/sdk/issues/14553 One of the comments in there seems to match my case:

I had the same phenomenon and when I tried to install these packages in a .NET 5 app, it told me that "net5.0" and "net.5.0-windows7.0" aren't compatible. All my projects where "net5.0-windows" actually, though.

If I manually copy the net5.0-windows7.0 folder to a new folder net5.0-windows under .nuget/packages, the Nuget error goes away.

But instead I get this compile error:

errorCS0103: The name 'Windows' does not exist in the current context

What should I change to make the Nuget restore work?

4 Answers

I have tested your issue with these two csproj files and did not faced the same behavior.

So please try the following steps:

  • uninstall MyControls nuget package on your app project first.

  • then, clean nuget caches or delete all files under C:\Users\xxx\.nuget\packages

  • delete bin and obj folder of the app project.

  • reinstall MyControls nuget package again to test it.

Increasing NuGet version to 5.X worked for me. It should be added before restore

I changed the target framework from windows to windows 10, like so:

MyControls (Nuget package) csproj:

<PropertyGroup>
    <TargetFrameworks>netcoreapp3.1;net5.0-windows10.0.19041.0</TargetFrameworks>
    <UseWPF>true</UseWPF>
  </PropertyGroup>

App csproj:

 <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net5.0-windows10.0.19041.0</TargetFramework>
    <UseWPF>true</UseWPF>
    <RuntimeIdentifiers>win-x64</RuntimeIdentifiers>

After that the Restore error disappeared.

I changed the version of visual studio I used from 2017 to 2022, which fixed this issue for me and the solution could be build with the latest version.

Related