From 070e23d2fc1421125641d8008fbc8fd88444cd20 Mon Sep 17 00:00:00 2001 From: Mike Date: Wed, 29 Apr 2026 18:12:06 +0200 Subject: [PATCH 1/2] Add dynamic Roslyn path resolving for 6000.5+ --- .../Editor/EditorInfoProvider.cs | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/UnityEditorPatch/InfoProviders/Editor/EditorInfoProvider.cs b/UnityEditorPatch/InfoProviders/Editor/EditorInfoProvider.cs index af3d82a..1b430ff 100644 --- a/UnityEditorPatch/InfoProviders/Editor/EditorInfoProvider.cs +++ b/UnityEditorPatch/InfoProviders/Editor/EditorInfoProvider.cs @@ -16,7 +16,7 @@ public static bool TryGet(UnityVersion version, OSPlatform platform, string look var contentPath = UnityLocationUtility.GetContentPath(lookupPath); var runtimePath = Path.Combine(contentPath, pathSpecification.RuntimePath); - var roslynPath = Path.Combine(contentPath, pathSpecification.RoslynLocation); + var roslynPath = ResolveRoslynPath(contentPath, pathSpecification.RoslynLocation); var sourceGeneratorLocations = pathSpecification.SourceGeneratorLocations .Select(location => Path.Combine(contentPath, location)) .Where(File.Exists).ToArray(); @@ -39,4 +39,27 @@ public static bool TryGet(UnityVersion version, OSPlatform platform, string look return true; } -} \ No newline at end of file + + static string ResolveRoslynPath(string contentPath, string preferredRelativePath) + { + var preferredPath = Path.Combine(contentPath, preferredRelativePath); + if (Directory.Exists(preferredPath)) + { + return preferredPath; + } + + var dotNetSdkPath = Path.Combine(contentPath, "DotNetSdk", "sdk"); + if (!Directory.Exists(dotNetSdkPath)) + { + return preferredPath; + } + + var roslynCandidates = Directory.GetDirectories(dotNetSdkPath) + .Select(versionPath => Path.Combine(versionPath, "Roslyn", "bincore")) + .Where(Directory.Exists) + .OrderBy(path => path, StringComparer.OrdinalIgnoreCase) + .ToArray(); + + return roslynCandidates.LastOrDefault() ?? preferredPath; + } +} From 594d9b86fd2449938e1f01656736a8a8c99ba3a7 Mon Sep 17 00:00:00 2001 From: Mike Date: Wed, 29 Apr 2026 18:30:27 +0200 Subject: [PATCH 2/2] Replace additional folders required by new Roslyn --- .../InfoProviders/Editor/EditorInfo.cs | 2 ++ .../Editor/EditorInfoProvider.cs | 16 ++++++++++++ UnityEditorPatch/Interactors/Backup.cs | 26 ++++++++++++++++++- UnityEditorPatch/Interactors/DotNetPatch.cs | 20 +++++++++++++- 4 files changed, 62 insertions(+), 2 deletions(-) diff --git a/UnityEditorPatch/InfoProviders/Editor/EditorInfo.cs b/UnityEditorPatch/InfoProviders/Editor/EditorInfo.cs index 0a7d4c6..6b40df1 100644 --- a/UnityEditorPatch/InfoProviders/Editor/EditorInfo.cs +++ b/UnityEditorPatch/InfoProviders/Editor/EditorInfo.cs @@ -9,6 +9,8 @@ public class EditorInfo public string ContentLocation { get; init; } public string RuntimeLocation { get; init; } public string RoslynLocation { get; init; } + public string? DotNetSdkHostLocation { get; init; } + public string? DotNetSdkSharedLocation { get; init; } public string[] SourceGeneratorLocations { get; init; } } diff --git a/UnityEditorPatch/InfoProviders/Editor/EditorInfoProvider.cs b/UnityEditorPatch/InfoProviders/Editor/EditorInfoProvider.cs index 1b430ff..a02e9a7 100644 --- a/UnityEditorPatch/InfoProviders/Editor/EditorInfoProvider.cs +++ b/UnityEditorPatch/InfoProviders/Editor/EditorInfoProvider.cs @@ -17,6 +17,8 @@ public static bool TryGet(UnityVersion version, OSPlatform platform, string look var contentPath = UnityLocationUtility.GetContentPath(lookupPath); var runtimePath = Path.Combine(contentPath, pathSpecification.RuntimePath); var roslynPath = ResolveRoslynPath(contentPath, pathSpecification.RoslynLocation); + var dotNetSdkHostPath = ResolveDotNetSdkSubdirectory(contentPath, roslynPath, "host"); + var dotNetSdkSharedPath = ResolveDotNetSdkSubdirectory(contentPath, roslynPath, "shared"); var sourceGeneratorLocations = pathSpecification.SourceGeneratorLocations .Select(location => Path.Combine(contentPath, location)) .Where(File.Exists).ToArray(); @@ -33,6 +35,8 @@ public static bool TryGet(UnityVersion version, OSPlatform platform, string look RoslynLocation = roslynPath, ContentLocation = contentPath, RuntimeLocation = runtimePath, + DotNetSdkHostLocation = dotNetSdkHostPath, + DotNetSdkSharedLocation = dotNetSdkSharedPath, IsPatched = Backup.IsBackupExist(contentPath), SourceGeneratorLocations = sourceGeneratorLocations }; @@ -62,4 +66,16 @@ static string ResolveRoslynPath(string contentPath, string preferredRelativePath return roslynCandidates.LastOrDefault() ?? preferredPath; } + + private static string? ResolveDotNetSdkSubdirectory(string contentPath, string roslynPath, string subdirectory) + { + var dotNetSdkPath = Path.Combine(contentPath, "DotNetSdk"); + if (!roslynPath.StartsWith(dotNetSdkPath, StringComparison.OrdinalIgnoreCase)) + { + return null; + } + + var path = Path.Combine(dotNetSdkPath, subdirectory); + return Directory.Exists(path) ? path : null; + } } diff --git a/UnityEditorPatch/Interactors/Backup.cs b/UnityEditorPatch/Interactors/Backup.cs index f90da4a..35f118d 100644 --- a/UnityEditorPatch/Interactors/Backup.cs +++ b/UnityEditorPatch/Interactors/Backup.cs @@ -26,6 +26,8 @@ public static bool TryPerform(EditorInfo info) Directory.CreateDirectory(backupPath); FileSystemUtility.CopyDirectory(info.RoslynLocation, BackupLocation(backupPath, info.RoslynLocation, relativeTo: info.ContentLocation)); FileSystemUtility.CopyDirectory(info.RuntimeLocation, BackupLocation(backupPath, info.RuntimeLocation, relativeTo: info.ContentLocation)); + BackupDirectoryIfExists(info.DotNetSdkHostLocation, backupPath, info.ContentLocation); + BackupDirectoryIfExists(info.DotNetSdkSharedLocation, backupPath, info.ContentLocation); foreach (var sourceGeneratorLocation in info.SourceGeneratorLocations) { @@ -53,6 +55,8 @@ public static bool TryRestore(EditorInfo info) FileSystemUtility.ReplaceDirectory(info.RoslynLocation, with: BackupLocation(backupPath, info.RoslynLocation, relativeTo: info.ContentLocation)); FileSystemUtility.ReplaceDirectory(info.RuntimeLocation, with: BackupLocation(backupPath, info.RuntimeLocation, relativeTo: info.ContentLocation)); + RestoreDirectoryIfExists(info.DotNetSdkHostLocation, backupPath, info.ContentLocation); + RestoreDirectoryIfExists(info.DotNetSdkSharedLocation, backupPath, info.ContentLocation); foreach (var sourceGeneratorLocation in info.SourceGeneratorLocations) { @@ -74,4 +78,24 @@ private static string BackupLocation(string backupLocation, string location, str var relativeLocation = Path.GetRelativePath(relativeTo, location); return Path.Combine(backupLocation, relativeLocation); } -} \ No newline at end of file + + private static void BackupDirectoryIfExists(string? directory, string backupPath, string contentLocation) + { + if (string.IsNullOrEmpty(directory) || !Directory.Exists(directory)) + { + return; + } + + FileSystemUtility.CopyDirectory(directory, BackupLocation(backupPath, directory, relativeTo: contentLocation)); + } + + private static void RestoreDirectoryIfExists(string? directory, string backupPath, string contentLocation) + { + if (string.IsNullOrEmpty(directory)) + { + return; + } + + FileSystemUtility.ReplaceDirectory(directory, with: BackupLocation(backupPath, directory, relativeTo: contentLocation)); + } +} diff --git a/UnityEditorPatch/Interactors/DotNetPatch.cs b/UnityEditorPatch/Interactors/DotNetPatch.cs index 1bddd0d..1407411 100644 --- a/UnityEditorPatch/Interactors/DotNetPatch.cs +++ b/UnityEditorPatch/Interactors/DotNetPatch.cs @@ -12,6 +12,8 @@ public static bool TryPerform(SDKInfo sdkInfo, EditorInfo editorInfo) { FileSystemUtility.ReplaceDirectory(editorInfo.RuntimeLocation, with: sdkInfo.Location); FileSystemUtility.ReplaceDirectory(editorInfo.RoslynLocation, with: sdkInfo.RoslynLocation); + CopyDotNetSdkRuntimeSupport(editorInfo.DotNetSdkHostLocation, sdkInfo.Location, "host"); + CopyDotNetSdkRuntimeSupport(editorInfo.DotNetSdkSharedLocation, sdkInfo.Location, "shared"); } catch (Exception) { @@ -20,4 +22,20 @@ public static bool TryPerform(SDKInfo sdkInfo, EditorInfo editorInfo) return true; } -} \ No newline at end of file + + private static void CopyDotNetSdkRuntimeSupport(string? targetDirectory, string sdkRoot, string subdirectory) + { + if (string.IsNullOrEmpty(targetDirectory)) + { + return; + } + + var sourceDirectory = Path.Combine(sdkRoot, subdirectory); + if (!Directory.Exists(sourceDirectory)) + { + return; + } + + FileSystemUtility.CopyDirectory(sourceDirectory, targetDirectory); + } +}