Reputation: 237
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.
Upvotes: 1
Views: 4726
Reputation: 4586
Inside of Visual Studio 2022 for Mac, I went to Tools, then SDK manager, and set this and it automatically detected the SDK after selecting this file:
Upvotes: 0
Reputation: 237
I managed to workaround it by:
If this doesnt work, I found another solution which is to uncheck "Build with MSBuild on mono" in the solution build properties. (Right click solution file, go to properties, "Build > General", uncheck)
Upvotes: 1
Reputation: 1287
I've tried to do like you but this doesn't work.
I've removed the SDK 5.0.408 and 6.0.401 like this:
version="5.0.408"
sudo rm -rf /usr/local/share/dotnet/sdk/$version
sudo rm -rf /usr/local/share/dotnet/shared/Microsoft.NETCore.App/$version
sudo rm -rf /usr/local/share/dotnet/shared/Microsoft.AspNetCore.All/$version
sudo rm -rf /usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/$version
sudo rm -rf /usr/local/share/dotnet/host/fxr/$version
version="6.0.401"
sudo rm -rf /usr/local/share/dotnet/sdk/$version
sudo rm -rf /usr/local/share/dotnet/shared/Microsoft.NETCore.App/$version
sudo rm -rf /usr/local/share/dotnet/shared/Microsoft.AspNetCore.All/$version
sudo rm -rf /usr/local/share/dotnet/shared/Microsoft.AspNetCore.App/$version
sudo rm -rf /usr/local/share/dotnet/host/fxr/$version`
Then I've reinstalled the SDK 5.0.408 and 6.0.401.
But I always have the same error when I try to restore packages from Visual Studio.
Is there something else?
Upvotes: 0