microsoft / MSBuildLocator

An API to locate MSBuild assemblies from an installed Visual Studio location. Use this to ensure that calling the MSBuild API will use the same toolset that a build from Visual Studio or msbuild.exe would.
Other
221 stars 86 forks source link

Issue with MSBuildLocator.RegisterDefaults() on Mac M1 #302

Closed sergey-fuflygin closed 3 months ago

sergey-fuflygin commented 4 months ago

I am encountering an issue on my Mac M1 when calling MSBuildLocator.RegisterDefaults(). The following error is produced:

No .NET SDKs were found.

Download a .NET SDK:
https://aka.ms/dotnet/download

Learn about SDK resolution:
https://aka.ms/dotnet/sdk-not-found
Unhandled exception. System.InvalidOperationException: Failed to find all versions of .NET Core MSBuild. Call to hostfxr_resolve_sdk2. There may be more details in stderr.
   at Microsoft.Build.Locator.DotNetSdkLocationHelper.GetSdkFromGlobalSettings(String workingDirectory)
   at Microsoft.Build.Locator.DotNetSdkLocationHelper.GetDotNetBasePaths(String workingDirectory)+MoveNext()
   at Microsoft.Build.Locator.DotNetSdkLocationHelper.GetInstances(String workingDirectory, Boolean allowQueryAllRuntimes)+MoveNext()
   at Microsoft.Build.Locator.MSBuildLocator.GetInstances(VisualStudioInstanceQueryOptions options)+MoveNext()
   at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Boolean& found)
   at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source)
   at Microsoft.Build.Locator.MSBuildLocator.RegisterDefaults()

dotnet --info output is below

.NET SDK:
 Version:           8.0.303
 Commit:            29ab8e3268
 Workload version:  8.0.300-manifests.c915c39d
 MSBuild version:   17.10.4+10fbfbf2e

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  14.5
 OS Platform: Darwin
 RID:         osx-arm64
 Base Path:   /usr/local/share/dotnet/sdk/8.0.303/

.NET workloads installed:
There are no installed workloads to display.

Host:
  Version:      8.0.7
  Architecture: arm64
  Commit:       2aade6beb0

.NET SDKs installed:
  6.0.424 [/usr/local/share/dotnet/sdk]
  8.0.303 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.32 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.7 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.32 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.7 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  None

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download

The above causes .NET Upgrade Assistant to fail (comment).

Could you please guide me on resolving this issue or any additional troubleshooting steps? Your help would be greatly appreciated.

YuliiaKovalova commented 4 months ago

Hi @sergey-fuflygin,

Thank you for contacting us! According to the specified info, it looks like PATH environment variables doesn't contain the required info to help with sdk resolution. Please add path/usr/local/share/dotnet to PATH env variable and try again.

sergey-fuflygin commented 3 months ago

Hi @YuliiaKovalova,

Thank you for the quick response!

I added /usr/local/share/dotnet to the PATH environment variable as you suggested, and it resolved the issue. I’m no longer receiving any errors.

image

Here is the output of echo $PATH:

sergey.fuflygin@sergey ~ % echo $PATH                              
/usr/local/share/dotnet:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet/sdk:/usr/local/share/dotnet/sdk/8.0.303/:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/usr/local/share/dotnet:~/.dotnet/tools:/usr/local/sbin:/Applications/Postgres.app/Contents/Versions/latest/bin:/Users/sergey.fuflygin/.dotnet/tools                        

Thanks again for your help!

baronfel commented 3 months ago

@sergey-fuflygin do you remember how you installed the .NET SDK? All of our installers should be setting $PATH for you automatically, so failures like this make me a bit worried.

sergey-fuflygin commented 3 months ago

@baronfel I likely downloaded the installer from https://dotnet.microsoft.com/en-us/download/dotnet/8.0, but to be honest, I don’t remember the exact steps I took.

If you want me to try uninstalling it and installing it again, please share the recommended steps, and I will do that. I’m ready to investigate this issue deeper to help identify the root cause.