UnityRoslynUpdater icon indicating copy to clipboard operation
UnityRoslynUpdater copied to clipboard

Read dotnet install location from DOTNET_ROOT instead of Registry

Open igoforth opened this issue 1 year ago • 1 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.

igoforth avatar May 17 '24 14:05 igoforth

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);
}

DaZombieKiller avatar May 17 '24 16:05 DaZombieKiller

Implemented in https://github.com/DaZombieKiller/UnityRoslynUpdater/commit/2ec52dc8d11b2a9990305bbda0b4fcc5271723ac

DaZombieKiller avatar Jun 23 '24 13:06 DaZombieKiller

Thank you!

igoforth avatar Jun 23 '24 15:06 igoforth