The SDK 'Microsoft.NET.SDK.WorkloadAutoImportPropsLocator' specified could not be found. .net core 5 MacOS
Asked Answered
A

5

7

I'm working on macOS Big Sur and Visual Studio .net core 5. I think the issues started after allowing Visual Studio to install updates (I wasn't expecting any issues), after a few hours dotnet command stopped working.

I found out that it's a known issue on M1 Macs, when dotnet stops working and that the recommended version to work with - 5.0.402. I unistalled dotnet and installed the recommended version.

Commands to uninstall dotnet (require script file):

chmod +x dotnet-uninstall-pkgs.sh 
sudo ./dotnet-uninstall-pkgs.sh
sudo rm -r /etc/dotnet

After installing the newer version(5.0.402) my project still doesn't works and I'm getting this error in Visual Studio:

/usr/local/share/dotnet/x64/sdk/6.0.101/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.ImportWorkloads.props(14,38): error MSB4236: The SDK 'Microsoft.NET.SDK.WorkloadAutoImportPropsLocator' specified could not be found.

I was thinking to uninstall the latest SDK but not sure if it's a good idea and may cause to additional issues with VisualStudio.

$ ./dotnet-core-uninstall list

Output (from dotnet-core-uninstall tool):

This tool cannot uninstall versions of the runtime or SDK that are installed using zip/scripts. The versions that can be uninstalled with this tool are:

.NET Core SDKs:
  5.0.402  (x64)  [Used by Visual Studio for Mac. Specify individually or use —-force to remove]

.NET Core Runtimes:
  5.0.11  (x64)  [Used by Visual Studio for Mac or SDKs. Specify individually or use —-force to remove]

Please advise how to solve this issue.

Thanks in advance!

Anguilla answered 21/12, 2021 at 9:40 Comment(0)
D
14

Upon install of VS2022 (v17.0 - build8989) on x64 Mac, I got this error but did not get this error when building from command line.

Things tried to fix this:

  • Followed the above instructions (multiple times)
  • deleted (3x) every trace of Mono, Xamarin, NuGet, DotNet, and VisualStudio from my system and reinstalled VS2022
  • Setting the MSBuildEnableWorkloadResolver = false environment variable
  • lots of reboots

None of the above worked. What was I missing? I was setting the MSBuildEnableWorkloadResolver = false environment variable the wrong way.

If you turn on Diagnostic log verbosity, the first thing listed in the build log will be the environment variables used for the build. The way that I was trying to set this environment variable was not effecting VisualStudio!

After a little bit of research, I learned that the most systemic way to set environment variables in MacOS is through launchctl:

 % launchctl setenv MSBuildEnableWorkloadResolver false

The old approach of systemically setting environmental variables was via ~/.MacOSX/environment.plist . However, that approach was removed in OS X Lion. Setting environment variables in the traditional Unix way (.profile, .bash_profile, .zprofile, .zshenv, etc) only applies to shells and will not work for applications.

Detailed answered 25/5, 2022 at 14:9 Comment(2)
I used this answer to make the MSBuildEnableWorkloadResolver variable available on system start up to all the applications on MacOS: https://mcmap.net/q/35997/-setting-environment-variables-on-os-x . Can you include this on your answer?Curnin
2024 update: This value is valuable when using Rider to work with Xamarin Forms projects. Certain XF projects fail to load when using Rider (but work with VS). Setting this value on a per project basis allows the project to load in rider. Note: Setting this value globally will cause issues with MAUI projects because it seems to disable workloads, which are required for MAUI.Bawd
C
3

Had this happen to me recently on Windows 10. My issue was that I installed .NET 8 SDK manually (not through Visual Studio Installer) and Rider started failing to load projects in my solution with this error.

I fixed it by using MSBuild from the SDK folder and not the one included with Visual Studio.

Convex answered 2/1 at 15:24 Comment(0)
P
2

Had this issue on Windows 10 after installing Visual Studio. Rider projects failed to load after this.

Solution: In Rider project settings -> Toolset and Build select MSBuild version manually. Use the one that Rider has, not Visual Studio.

Pectinate answered 30/7 at 17:57 Comment(0)
A
0

Here are the steps that worked for me to solve this issue.

  1. I removed all dotnet components following this guide.

  2. I installed SDK 5.0.404 After installation dotnet command didn't work.

  3. I followed recommendations from this post and it solved my issue. I removed existing dotnet file and recreated it.

Hope it will be helpful for someone.

Anguilla answered 21/12, 2021 at 21:59 Comment(0)
T
0

For Win10:

dotnet new globaljson --sdk-version {desired-version} --force

saved the day. All projects that refused to load previously, loaded (i've tried system variables troubleshoots (Path, MSBuildSDKsPath), but none of them worked)

Toxicity answered 5/9 at 14:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.