From 2aa72a9e14ec2040cfd7d64f041b597b4e3cbc27 Mon Sep 17 00:00:00 2001 From: kasperk81 <83082615+kasperk81@users.noreply.github.com> Date: Thu, 26 Feb 2026 01:30:50 +0200 Subject: [PATCH 1/6] use SpecialFolder.UserProfile instead of USERPROFILE --- .../TestConfiguration.cs | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/src/Microsoft.Diagnostics.TestHelpers/TestConfiguration.cs b/src/Microsoft.Diagnostics.TestHelpers/TestConfiguration.cs index 01821e3244..4692c9e8e2 100644 --- a/src/Microsoft.Diagnostics.TestHelpers/TestConfiguration.cs +++ b/src/Microsoft.Diagnostics.TestHelpers/TestConfiguration.cs @@ -53,19 +53,9 @@ 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) - { - 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"); - } + string basePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); + if (!string.IsNullOrEmpty(basePath)) + nugetPackages = Path.Combine(basePath, ".nuget", "packages"); } // The TargetArchitecture and NuGetPackageCacheDir can still be overridden // in a config file. This is just setting the default. The other values can From 2e4d664b6e757b2bd5a019ea5c6b0d9800538ad5 Mon Sep 17 00:00:00 2001 From: kasperk81 <83082615+kasperk81@users.noreply.github.com> Date: Thu, 26 Feb 2026 01:34:55 +0200 Subject: [PATCH 2/6] Update Utilities.cs --- .../Utilities.cs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/Microsoft.Diagnostics.DebugServices.Implementation/Utilities.cs b/src/Microsoft.Diagnostics.DebugServices.Implementation/Utilities.cs index 36634a60f0..256dfe79d3 100644 --- a/src/Microsoft.Diagnostics.DebugServices.Implementation/Utilities.cs +++ b/src/Microsoft.Diagnostics.DebugServices.Implementation/Utilities.cs @@ -281,15 +281,7 @@ public static Stream TryOpenFile(string path) /// public static string GetDotNetHomeDirectory() { - string dotnetHome; - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - dotnetHome = Path.Combine(Environment.GetEnvironmentVariable("USERPROFILE") ?? throw new ArgumentNullException("USERPROFILE environment variable not found"), ".dotnet"); - } - else - { - dotnetHome = Path.Combine(Environment.GetEnvironmentVariable("HOME") ?? throw new ArgumentNullException("HOME environment variable not found"), ".dotnet"); - } + string dotnetHome = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) ?? throw new ArgumentNullException("UserProfile directory not found"), ".dotnet"); return dotnetHome; } From f2a213c4cfc59381138f14f5659a639386b24c60 Mon Sep 17 00:00:00 2001 From: kasperk81 <83082615+kasperk81@users.noreply.github.com> Date: Thu, 26 Feb 2026 02:29:56 +0200 Subject: [PATCH 3/6] Update TestConfiguration.cs --- src/Microsoft.Diagnostics.TestHelpers/TestConfiguration.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Microsoft.Diagnostics.TestHelpers/TestConfiguration.cs b/src/Microsoft.Diagnostics.TestHelpers/TestConfiguration.cs index 4692c9e8e2..256f271b44 100644 --- a/src/Microsoft.Diagnostics.TestHelpers/TestConfiguration.cs +++ b/src/Microsoft.Diagnostics.TestHelpers/TestConfiguration.cs @@ -55,7 +55,9 @@ private void ParseConfigFile(string path) // tests). string basePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); if (!string.IsNullOrEmpty(basePath)) + { nugetPackages = Path.Combine(basePath, ".nuget", "packages"); + } } // The TargetArchitecture and NuGetPackageCacheDir can still be overridden // in a config file. This is just setting the default. The other values can From 8e77ad80a41412677202043681ad51b5f5fa651c Mon Sep 17 00:00:00 2001 From: kasperk81 <83082615+kasperk81@users.noreply.github.com> Date: Thu, 26 Feb 2026 11:38:56 +0200 Subject: [PATCH 4/6] Update Utilities.cs --- .../Utilities.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.Diagnostics.DebugServices.Implementation/Utilities.cs b/src/Microsoft.Diagnostics.DebugServices.Implementation/Utilities.cs index 256dfe79d3..2677df507e 100644 --- a/src/Microsoft.Diagnostics.DebugServices.Implementation/Utilities.cs +++ b/src/Microsoft.Diagnostics.DebugServices.Implementation/Utilities.cs @@ -281,8 +281,13 @@ public static Stream TryOpenFile(string path) /// public static string GetDotNetHomeDirectory() { - string dotnetHome = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) ?? throw new ArgumentNullException("UserProfile directory not found"), ".dotnet"); - return dotnetHome; + string basePath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); + if (!string.IsNullOrEmpty(basePath)) + { + throw new ArgumentNullException("UserProfile directory not found"); + } + + return Path.Combine(Environment.GetFolderPath(basePath, ".dotnet");; } /// From f3b6749ac676f6464e12905a88371f89a0a39b75 Mon Sep 17 00:00:00 2001 From: kasperk81 <83082615+kasperk81@users.noreply.github.com> Date: Thu, 26 Feb 2026 16:18:36 +0200 Subject: [PATCH 5/6] Update Utilities.cs --- .../Utilities.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.Diagnostics.DebugServices.Implementation/Utilities.cs b/src/Microsoft.Diagnostics.DebugServices.Implementation/Utilities.cs index 2677df507e..96cf99993e 100644 --- a/src/Microsoft.Diagnostics.DebugServices.Implementation/Utilities.cs +++ b/src/Microsoft.Diagnostics.DebugServices.Implementation/Utilities.cs @@ -287,7 +287,7 @@ public static string GetDotNetHomeDirectory() throw new ArgumentNullException("UserProfile directory not found"); } - return Path.Combine(Environment.GetFolderPath(basePath, ".dotnet");; + return Path.Combine(Environment.GetFolderPath(basePath, ".dotnet")); } /// From c9674f1faeb570d9ab67233d34ee022be0e44f99 Mon Sep 17 00:00:00 2001 From: kasperk81 <83082615+kasperk81@users.noreply.github.com> Date: Thu, 26 Feb 2026 16:32:49 +0200 Subject: [PATCH 6/6] Fix path combination for UserProfile directory --- .../Utilities.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.Diagnostics.DebugServices.Implementation/Utilities.cs b/src/Microsoft.Diagnostics.DebugServices.Implementation/Utilities.cs index 96cf99993e..553dae6987 100644 --- a/src/Microsoft.Diagnostics.DebugServices.Implementation/Utilities.cs +++ b/src/Microsoft.Diagnostics.DebugServices.Implementation/Utilities.cs @@ -287,7 +287,7 @@ public static string GetDotNetHomeDirectory() throw new ArgumentNullException("UserProfile directory not found"); } - return Path.Combine(Environment.GetFolderPath(basePath, ".dotnet")); + return Path.Combine(basePath, ".dotnet"); } ///