Skip to content

fix: resolve Roslyn assemblies on macOS (Unity.app/Contents path)#13

Open
dougfy wants to merge 1 commit intoAnkleBreaker-Studio:mainfrom
dougfy:fix/macos-roslyn-path-resolution
Open

fix: resolve Roslyn assemblies on macOS (Unity.app/Contents path)#13
dougfy wants to merge 1 commit intoAnkleBreaker-Studio:mainfrom
dougfy:fix/macos-roslyn-path-resolution

Conversation

@dougfy
Copy link
Copy Markdown

@dougfy dougfy commented Apr 26, 2026

Problem

On macOS, EditorApplication.applicationPath returns the path to the Unity.app bundle itself (e.g. /Applications/Unity/Hub/Editor/2022.3.62f2/Unity.app).

The existing TryLoadRoslyn() calls Path.GetDirectoryName() on that path and then appends Data/... — a layout that only exists on Windows and Linux. On macOS the Roslyn DLLs live inside Unity.app/Contents/..., so all search paths miss and ExecuteCode always returns:

Roslyn (Microsoft.CodeAnalysis) is not available in this Unity version. ExecuteCode requires Roslyn for dynamic compilation.

This affects all Unity 2022.3.x and Unity 6 installs on macOS, even though the required DLLs (Microsoft.CodeAnalysis.dll, Microsoft.CodeAnalysis.CSharp.dll) are bundled in every Unity release.

Fix

Detect when applicationPath ends in .app and add Unity.app/Contents as an additional data root alongside the existing Windows/Linux Data root. The search loop already handles missing directories gracefully, so this is a safe additive change.

Also adds Tools/ScriptUpdater as a search location — it ships Mono-compatible Roslyn assemblies in all 2022.3.x builds and is a reliable fallback.

Tested

  • macOS (Apple Silicon), Unity 2022.3.62f2
  • unity_execute_code now returns results instead of the Roslyn error
  • No regressions on Windows paths (additive change only)

On macOS, EditorApplication.applicationPath points to the Unity.app
bundle itself (e.g. /Applications/Unity/Hub/Editor/2022.3.62f2/Unity.app).
The previous code called Path.GetDirectoryName() on that path and then
appended 'Data/...' — a layout that only exists on Windows and Linux.

On macOS the Roslyn DLLs live inside Unity.app/Contents/..., so
TryLoadRoslyn() never found them and ExecuteCode always returned the
'Roslyn is not available' error.

Fix: detect when applicationPath ends in '.app' and add Unity.app/Contents
as an additional data root alongside the existing Windows/Linux root.
Also adds Tools/ScriptUpdater as a search location (ships Mono-compatible
Roslyn assemblies in all 2022.3.x builds).

Tested on macOS (Unity 2022.3.62f2, Apple Silicon).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant