Visual Studio Not Using Correct .NET SDK on Visual Studio For Mac 2022

Viewed 77

I am attempting to upgrade a project from .net 5 to .net 6

I am using Visual Studio for Mac 2022 v17.3 (I have tried Visual Studio for Mac Preview 2022 v17.4 as well but no luck there)

I have installed the .net 6 sdk onto machine. The output of dotnet --list-sdks is:

dotnet --list-sdks
2.2.100 [/usr/local/share/dotnet/sdk]
3.0.101 [/usr/local/share/dotnet/sdk]
3.1.301 [/usr/local/share/dotnet/sdk]
3.1.419 [/usr/local/share/dotnet/sdk]
3.1.422 [/usr/local/share/dotnet/sdk]
5.0.100 [/usr/local/share/dotnet/sdk]
5.0.408 [/usr/local/share/dotnet/sdk]
6.0.300 [/usr/local/share/dotnet/sdk]
6.0.400 [/usr/local/share/dotnet/sdk]

The output of dotnet --version is:

dotnet --version
6.0.400

I have attempted both with and without a global.json. The contents of the global.json when I tried it:

{
  "sdk": {
    "version": "6.0.400"
  }
}

I also tried my other 6 sdk version,

{
  "sdk": {
    "version": "6.0.300"
  }
}

My TargetFramework for my projects is set to net6.0

    <TargetFramework>net6.0</TargetFramework>

Despite all of this, here is the output when I attempt to build from Visual Studio: (building from command line works)

/usr/local/share/dotnet/sdk/5.0.408/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(141,5): error NETSDK1045: The current .NET SDK does not support targeting .NET 6.0. Either target .NET 5.0 or lower, or use a version of the .NET SDK that supports .NET 6.0.

(bold emphasis is my own, on the sdk version)

It is only ever trying to use 5.0.408

I know there are very many questions and answers related to this issue on stack overflow, one example of which is this question, the only problem is the solutions provided in the other similar questions are not resolving my issue. There seems to be some sort of caching happening and I cannot figure it out. I just want Visual Studio to use the proper SDK version.

If I run dotnet build MySolution.sln from the command line, it builds using the proper SDK. Visual Studio, on the other hand, does not. It only uses 5.0.408. There is not a global.json anywhere in my file structure that points to a net 5 sdk. There are no projects in my solution that Target 5, they all target 6.

1 Answers

I managed to workaround it by:

  • removing 5.0.408 from my machine
  • removing 6.0.400 from my machine
  • downloading a fresh install of 5.0.408
  • downloading a fresh install of 6.0.400
Related