2

I've tried to build a sample TodoApp downloaded on GitHub that contains a project based on .net 6.

I am using Visual Studio for Mac 2022 v17.3.6 (build 20) and Visual Studio for Mac Preview (17.4 build 715).

When I try to restore the packages of these solution, I got an error related to the project TodoAppService.NET6:

Getting restore information for project /Users/user/Projects/AzureSamples/azure-mobile-apps/samples/TodoApp/TodoAppService.NET6/TodoAppService.NET6.csproj
/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.
Unable to create package spec for project. '/Users/user/Projects/AzureSamples/azure-mobile-apps/samples/TodoApp/TodoAppService.NET6/TodoAppService.NET6.csproj'

However, all seems correct regarding to the .Net SDKs on my computer:

  • the dotnet --list-sdks command returns:
2.1.302 [/usr/local/share/dotnet/sdk]
2.1.504 [/usr/local/share/dotnet/sdk]
2.1.505 [/usr/local/share/dotnet/sdk]
2.1.700 [/usr/local/share/dotnet/sdk]
2.1.701 [/usr/local/share/dotnet/sdk]
3.0.100 [/usr/local/share/dotnet/sdk]
3.0.101 [/usr/local/share/dotnet/sdk]
3.1.100 [/usr/local/share/dotnet/sdk]
3.1.101 [/usr/local/share/dotnet/sdk]
3.1.102 [/usr/local/share/dotnet/sdk]
3.1.200 [/usr/local/share/dotnet/sdk]
3.1.300 [/usr/local/share/dotnet/sdk]
3.1.401 [/usr/local/share/dotnet/sdk]
3.1.402 [/usr/local/share/dotnet/sdk]
3.1.403 [/usr/local/share/dotnet/sdk]
3.1.404 [/usr/local/share/dotnet/sdk]
3.1.406 [/usr/local/share/dotnet/sdk]
3.1.407 [/usr/local/share/dotnet/sdk]
3.1.408 [/usr/local/share/dotnet/sdk]
3.1.409 [/usr/local/share/dotnet/sdk]
3.1.410 [/usr/local/share/dotnet/sdk]
3.1.411 [/usr/local/share/dotnet/sdk]
3.1.412 [/usr/local/share/dotnet/sdk]
3.1.413 [/usr/local/share/dotnet/sdk]
3.1.418 [/usr/local/share/dotnet/sdk]
3.1.419 [/usr/local/share/dotnet/sdk]
3.1.421 [/usr/local/share/dotnet/sdk]
3.1.422 [/usr/local/share/dotnet/sdk]
3.1.423 [/usr/local/share/dotnet/sdk]
5.0.100 [/usr/local/share/dotnet/sdk]
5.0.101 [/usr/local/share/dotnet/sdk]
5.0.103 [/usr/local/share/dotnet/sdk]
5.0.201 [/usr/local/share/dotnet/sdk]
5.0.202 [/usr/local/share/dotnet/sdk]
5.0.203 [/usr/local/share/dotnet/sdk]
5.0.301 [/usr/local/share/dotnet/sdk]
5.0.302 [/usr/local/share/dotnet/sdk]
5.0.400 [/usr/local/share/dotnet/sdk]
5.0.401 [/usr/local/share/dotnet/sdk]
5.0.407 [/usr/local/share/dotnet/sdk]
5.0.408 [/usr/local/share/dotnet/sdk]
6.0.300 [/usr/local/share/dotnet/sdk]
6.0.302 [/usr/local/share/dotnet/sdk]
6.0.400-preview.22330.6 [/usr/local/share/dotnet/sdk]
6.0.400 [/usr/local/share/dotnet/sdk]
6.0.401 [/usr/local/share/dotnet/sdk]
  • the dotnet --version command returns:
6.0.401

I've tried the solution given on this topic that describes a similar issue:

  • 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`
  • I've reinstalled the same SDKs

But I always get the same issue when I try to restore the packages...

Edit: some tests

I still haven't found any solution, but I did some tests.

First I created a basic console app using .NET 6: screenshot - console app I can build and launch this basic app.

After that, I've re-created the project TodoAppService.NET6: I can restore the packages and build it.

In Visual Studio, I can see that the latest Microsoft.NETCore.App framework is used: screenshot - created project

But when I open the TodoApp solution in Visual Studio, it seems that the same framework is not recognised, as it appears as a SDK without the version: screenshot - downloaded project

Edit: news tests

I did new tests by adding a global.json file in the TodoAppService.NET6 project of the TodoApp solution:

{
  "sdk": {
    "version": "6.0.401",
    "rollforward": "minor"
  }
}

This didn't change anything and I always has the same error when I try to restore packages...

It's really frustrating and I don't have any other idea to fix this...

Gold.strike
  • 1,269
  • 13
  • 47
  • The `global.json` file must be in the root of the solution or even the root of the repo (whichever is higher). Place it as high up as possible. – PMF Oct 03 '22 at 18:05
  • And make sure you have only one. – PMF Oct 03 '22 at 18:05
  • I've removed the `global.json` file from the project and recreated in at the root of the solution. But the result is still the same, even after relaunched Visual Studio. – Gold.strike Oct 04 '22 at 16:58
  • This is really strange. You could try enabling detailed compiler output (via the options page). This includes information about where the `global.json` is searched and many other settings that might help you diagnose the problem. I'm sorry this is one of the problems that are difficult to solve with just looking at error messages. – PMF Oct 04 '22 at 18:30
  • But there is nothing is the build output as the error occurs during the packages restore, before the build... – Gold.strike Oct 05 '22 at 12:15

1 Answers1

4

Is it possible that you have a mix of .NET and classic projects in your solution, which causes issues with MSBuild on Mono. This stack overflow issue explains the problem

Go to your solution properties, then Build -> General and uncheck 'Build with MSBuild on Mono'. If this is your issue, you should see the project will immediately build after unchecking the box.

jwalker
  • 56
  • 4
  • I can confirm this fixes the issue for builds WITHIN vs2022 for mac. But we have this issue on our private agents. So how can I fix this for builds running on a pipeline agent on a mac? I cannot specify this checkbox there – PaulVrugt Nov 28 '22 at 12:12