1

create a brand new asp net core web api in visual studio 2022 version (17.4.1) targeting .net 6

the solution won't build, and we got this error

Error NU1102 Unable to find package Microsoft.WindowsDesktop.App.Ref with version (= 6.0.12)

toumir
  • 621
  • 6
  • 17

2 Answers2

1

Finally I found a workaround for this problem

global.json fixes the problem

{
  "sdk": {
    "version": "6.0.0",
    "rollForward": "latestMinor",
    "allowPrerelease": false
  }
}

If you want to use the latest SDK version that is installed on your machine, no global.json file is needed. however, you typically want to specify an acceptable range for the SDK version that is used. The global.json file has a rollForward feature that provides flexible ways to specify an acceptable range of versions.

The .NET SDK looks for a global.json file in the current working directory (which isn't necessarily the same as the project directory) or one of its parent directories.

https://learn.microsoft.com/en-us/dotnet/core/tools/global-json

That's all it worked for me :)

toumir
  • 621
  • 6
  • 17
  • for vs 17.4.1 or vs 17.4.2 it must use the above json file to fix the problem, for vs 17.4.3 the bug was fixed :) – toumir Dec 15 '22 at 10:53
  • It worked for me. In my case I have VS 17.4.4. After installation of .net SDK 7.0.103 (an automatic update?) my targeted .net 6 project was broken. I put this json file alongside with the SLN file and worked perfectly. – Guillermo Espert Feb 16 '23 at 09:19
0

This error might also come if the Visual Studio is not updated to the latest version. I updated my Visual Studio 2022 with the latest update and the error was gone.