diff --git a/src/Shared/TempFileUtilities.cs b/src/Shared/TempFileUtilities.cs index c73af5ba444..190f0dddf2b 100644 --- a/src/Shared/TempFileUtilities.cs +++ b/src/Shared/TempFileUtilities.cs @@ -20,6 +20,8 @@ internal static partial class FileUtilities // Lower order bits correspond to the same for "group" or "other" users. private const int userRWX = 0x100 | 0x80 | 0x40; private static string tempFileDirectory = null; + private const string msbuildTempFolderPrefix = "MSBuildTemp"; + internal static string TempFileDirectory { get @@ -36,7 +38,12 @@ internal static void ClearTempFileDirectory() // For all native calls, directly check their return values to prevent bad actors from getting in between checking if a directory exists and returning it. private static string CreateFolderUnderTemp() { - string basePath = Path.Combine(Path.GetTempPath(), $"MSBuildTemp{Environment.UserName}"); + // On windows Username with Unicode chars can give issues, so we dont append username to the temp folder name. + string msbuildTempFolder = NativeMethodsShared.IsWindows ? + msbuildTempFolderPrefix : + msbuildTempFolderPrefix + Environment.UserName; + + string basePath = Path.Combine(Path.GetTempPath(), msbuildTempFolder); if (NativeMethodsShared.IsLinux && NativeMethodsShared.mkdir(basePath, userRWX) != 0) {