Reputation: 4782
I am running the same project built by Cake and MSBuild on various platforms (Windows, Linux, Mac) targeting .NET Core 3.1. Everything goes well except on Mac where I'm getting NETSDK1045 error as follows:
Project "MyProject.csproj" on node 1 (Build target(s)).
/usr/local/share/dotnet/sdk/3.0.100/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(127,5): error NETSDK1045: The current .NET SDK does not support targeting .NET Core 3.1. Either target .NET Core 3.0 or lower, or use a version of the .NET SDK that supports .NET Core 3.1.
On Mac, where the problem exists, I'm using latest version of Mono 6.12.0.122 which includes MSBuild 16.6.0.
.NET Core 3.1 is installed. I don't have any override or global.json. Here is the list of all installed SDKs:
dotnet --list-sdks
2.1.802 [/usr/local/share/dotnet/sdk]
2.2.402 [/usr/local/share/dotnet/sdk]
3.0.100 [/usr/local/share/dotnet/sdk]
3.1.416 [/usr/local/share/dotnet/sdk]
3.1.417 [/usr/local/share/dotnet/sdk]
5.0.406 [/usr/local/share/dotnet/sdk]
6.0.201 [/usr/local/share/dotnet/sdk]
Here is the information about the runtime environment from the dotnet
command:
Runtime Environment:
OS Name: Mac OS X
OS Version: 10.14
OS Platform: Darwin
RID: osx.10.14-x64
Base Path: /usr/local/share/dotnet/sdk/6.0.201/
Why does the error NETSDK1045 happens in spite of .NET Core 3.1 and even later versions are installed? And why does it happen on Mac only?
Upvotes: 1
Views: 804
Reputation: 4782
There is a common problem that and old version of MSBuild does not see the new version of .NET Core SDK.
On Mac, the problem is in MSBuild 16.6.0, which is shipped with the latest stable version of Mono (6.12.0.122).
This version of MSBuild was released earlier than the .NET Core 3.1.416 SDK. Therefore, MSBuild cannot find that version of .NET Core, but was looking for an older version that was supported by MSBuild at the time of its release. It finds .NET Core 3.0, which would not work for 3.1 projects, so that's the cause of the error. Paradoxically, if no earlier version of SDK than 3.1.416 is installed, then MSBuild was able to find it. So, there are two solutions: (1) uninstall all SDK versions earlier than 3.1.416, or (2) update MSBuild.
I installed Mono's "Preview" version 6.12.0.174, which came with the updated MSBuild - 16.10.1, so that version was able to successfully find the .NET Core 3.1.416 SDK, even though earlier versions were installed. Therefore, solution nr. 2 (from those described above) worked in my case.
The same problem existed in Microsoft Visual Studio for Mac but was fixed by Microsoft recently. The issue is not related to Cake Build.
On Windows, there may be an error that MS Build shipped with Visual Studio 2017 does not see .NET Core 3.1 SDK. If you take a newer MS Build, i.e., the one that is shipped with Visual Studio 2019, the problem will be resolved.
Upvotes: 2