DaZombieKiller/UnityRoslynUpdater

Read dotnet install location from DOTNET_ROOT instead of Registry

Closed this issue · 3 comments

I manage my dotnet installs in usermode through the scoop package manager at %USERPROFILE%\scoop\apps\dotnet-sdk-preview\current. As a result, the DOTNET_ROOT environment variable is up-to-date but my registry key still points to Program Files. I could update this, but it would be more helpful to me if UnityRoslynUpdater at least had an option to obey DOTNET_ROOT.

I can take a look at implementing this later, or if you're interested in opening a pull request it should be as simple as changing GetCurrentInstallation in DotNetInstallation.cs to:

private static DotNetInstallation GetCurrentInstallation()
{
    string? location = Environment.GetEnvironmentVariable("DOTNET_ROOT");

    if (string.IsNullOrEmpty(location))
        location = Registry.GetValue(@"HKEY_LOCAL_MACHINE\SOFTWARE\dotnet\Setup\InstalledVersions\x64", "InstallLocation", null) as string;

    if (string.IsNullOrEmpty(location))
        location = GetDefaultInstallationLocation();

    return new DotNetInstallation(location);
}

Implemented in 2ec52dc

Thank you!