diff --git a/src/Microsoft.Diagnostics.DebugServices.Implementation/Utilities.cs b/src/Microsoft.Diagnostics.DebugServices.Implementation/Utilities.cs index 36634a60f0..553dae6987 100644 --- a/src/Microsoft.Diagnostics.DebugServices.Implementation/Utilities.cs +++ b/src/Microsoft.Diagnostics.DebugServices.Implementation/Utilities.cs @@ -281,16 +281,13 @@ public static Stream TryOpenFile(string path) /// public static string GetDotNetHomeDirectory() { - string dotnetHome; - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + string basePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); + if (!string.IsNullOrEmpty(basePath)) { - dotnetHome = Path.Combine(Environment.GetEnvironmentVariable("USERPROFILE") ?? throw new ArgumentNullException("USERPROFILE environment variable not found"), ".dotnet"); + throw new ArgumentNullException("UserProfile directory not found"); } - else - { - dotnetHome = Path.Combine(Environment.GetEnvironmentVariable("HOME") ?? throw new ArgumentNullException("HOME environment variable not found"), ".dotnet"); - } - return dotnetHome; + + return Path.Combine(basePath, ".dotnet"); } /// diff --git a/src/Microsoft.Diagnostics.TestHelpers/TestConfiguration.cs b/src/Microsoft.Diagnostics.TestHelpers/TestConfiguration.cs index 01821e3244..256f271b44 100644 --- a/src/Microsoft.Diagnostics.TestHelpers/TestConfiguration.cs +++ b/src/Microsoft.Diagnostics.TestHelpers/TestConfiguration.cs @@ -53,18 +53,10 @@ private void ParseConfigFile(string path) // This emulates that logic so the VS Test Explorer can still run the tests for // config files that don't set the NugetPackagesCacheDir value (like the SOS unit // tests). - string nugetPackagesRoot = null; - if (OS.Kind == OSKind.Windows) + string basePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); + if (!string.IsNullOrEmpty(basePath)) { - nugetPackagesRoot = Environment.GetEnvironmentVariable("UserProfile"); - } - else if (OS.Kind is OSKind.Linux or OSKind.OSX) - { - nugetPackagesRoot = Environment.GetEnvironmentVariable("HOME"); - } - if (nugetPackagesRoot != null) - { - nugetPackages = Path.Combine(nugetPackagesRoot, ".nuget", "packages"); + nugetPackages = Path.Combine(basePath, ".nuget", "packages"); } } // The TargetArchitecture and NuGetPackageCacheDir can still be overridden