Skip to content

fix: reference the Roslyn assemblies from MCPForUnity.Editor.asmdef - #1359

Merged
Scriptwonder merged 1 commit into
CoplayDev:betafrom
ananttheant:fix/roslyn-upm-asmdef-references
Sep 1, 2026
Merged

Scriptwonder merged 1 commit into
CoplayDev:betafrom
ananttheant:fix/roslyn-upm-asmdef-references

Conversation

@ananttheant

@ananttheant ananttheant commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Description

MCPForUnity.Editor.asmdef sets "overrideReferences": true, which means the assembly only sees precompiled assemblies it names explicitly — and precompiledReferences listed just Newtonsoft.Json.dll. RoslynInstaller writes its DLLs to Application.dataPath/Plugins/Roslyn, i.e. the consuming project's Assets/Plugins/Roslyn, which is outside the package. So the moment a user follows the Roslyn guide and defines USE_ROSLYN, the using Microsoft.CodeAnalysis; directives in ManageScript.cs cannot resolve and the build breaks. Embedded installs happened to work; UPM installs could not.

Worth noting ExecuteCode.cs already dodges this by reaching Roslyn through Type.GetType(...) reflection instead of compile-time using directives — ManageScript.cs was simply never given the same treatment.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Refactoring (no functional changes)
  • Test update

Changes Made

  • MCPForUnity/Editor/MCPForUnity.Editor.asmdef: added the five DLL names RoslynInstaller installs to precompiledReferences.
  • New RoslynAsmdefReferenceTests: asserts the asmdef references every DLL the installer writes. It reads that list off RoslynInstaller.NuGetEntries by reflection rather than duplicating it, so if someone adds or renames a Roslyn dependency the test fails instead of silently drifting.

I wrote the test first and confirmed it fails on beta before the asmdef change, naming all five missing assemblies:

MCPForUnity.Editor.asmdef must list every DLL RoslynInstaller installs in precompiledReferences,
otherwise USE_ROSLYN cannot compile against them. Missing: Microsoft.CodeAnalysis.dll,
Microsoft.CodeAnalysis.CSharp.dll, System.Collections.Immutable.dll,
System.Reflection.Metadata.dll, System.Runtime.CompilerServices.Unsafe.dll

Compatibility / Package Source

  • Unity version(s) tested: 2022.3.62f1
  • Package source used: file: (local clone, branch fix/roslyn-upm-asmdef-references off beta)
  • Resolved commit hash from Packages/packages-lock.json: n/a (file reference)

Testing/Screenshots/Recordings

  • Python tests — not applicable, no Python-side changes
  • Unity EditMode tests
  • Unity PlayMode tests — not applicable
  • Package import/compile check

Full EditMode suite on 2022.3.62f1: 1120 passed, 0 failed (66 pre-existing ignores), with zero compile errors.

That last point is the one I most wanted to verify rather than assume: TestProjects/UnityMCPTests has none of these Roslyn DLLs present, and the project still compiles cleanly with them listed. So Unity does ignore a precompiledReferences entry whose assembly is absent, and this change is a no-op for the majority of projects that never install Roslyn.

Documentation Updates

  • I have added/removed/modified tools or resources — no tool or resource surface changed

website/docs/guides/roslyn.md still describes the correct user-facing flow, so no doc change was needed.

Related Issues

Closes #1295

Additional Notes

What I could not verify locally is the positive case end to end: a UPM install with the DLLs actually present in Assets/Plugins/Roslyn and USE_ROSLYN defined, compiling successfully. I verified the mechanism (absent entries are ignored; the names now match what the installer writes) but if one of you has a project already set up that way, a confirmation would be worth having before merge.

The alternative fix would be converting ManageScript.cs's six #if USE_ROSLYN blocks to reflection, mirroring ExecuteCode.cs. That removes the asmdef question entirely but is a much larger and riskier change, so I went with the small one — happy to take the other route if you'd prefer it.

Summary by CodeRabbit

  • Bug Fixes

    • Improved editor compatibility by ensuring required Roslyn compiler libraries are available.
    • Prevented package builds from failing when Roslyn support is enabled.
  • Tests

    • Added automated coverage to verify all required Roslyn libraries are correctly referenced and remain available during Unity package builds.

@coderabbitai

coderabbitai Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: 18267ef6-f31b-4085-bad5-c7fa48caf916

📥 Commits

Reviewing files that changed from the base of the PR and between 88f318f and c47b5f2.

📒 Files selected for processing (4)
  • MCPForUnity/Editor/MCPForUnity.Editor.asmdef
  • TestProjects/UnityMCPTests/Assets/Tests/EditMode/Setup.meta
  • TestProjects/UnityMCPTests/Assets/Tests/EditMode/Setup/RoslynAsmdefReferenceTests.cs
  • TestProjects/UnityMCPTests/Assets/Tests/EditMode/Setup/RoslynAsmdefReferenceTests.cs.meta

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

The editor assembly definition now references the Roslyn DLLs installed by RoslynInstaller. A new EditMode test reflects over the installer entries and verifies that every installed DLL appears in the assembly definition.

Changes

Roslyn assembly reference validation

Layer / File(s) Summary
Add Roslyn precompiled references
MCPForUnity/Editor/MCPForUnity.Editor.asmdef
The assembly definition adds the Roslyn and supporting DLLs to precompiledReferences.
Validate installer references in EditMode
TestProjects/UnityMCPTests/Assets/Tests/EditMode/Setup/RoslynAsmdefReferenceTests.cs, TestProjects/UnityMCPTests/Assets/Tests/EditMode/Setup.meta, TestProjects/UnityMCPTests/Assets/Tests/EditMode/Setup/RoslynAsmdefReferenceTests.cs.meta
The new NUnit test reads RoslynInstaller.NuGetEntries, loads the editor assembly definition, and reports any installed DLL that is missing from precompiledReferences. Unity metadata files define the new test folder and test asset.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to c47b5

The change enables the optional Roslyn integration to compile in UPM installs while leaving projects without Roslyn unaffected, and adds coverage to prevent reference drift. No actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 1 files. (3 skipped: 3 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary change: adding Roslyn assembly references to MCPForUnity.Editor.asmdef.
Description check ✅ Passed The description is complete and follows the repository template. It explains the bug, lists the changes, identifies compatibility details, records test results, and links issue #1295.
Linked Issues check ✅ Passed The PR satisfies issue #1295 by adding all five Roslyn DLLs installed by RoslynInstaller to precompiledReferences and adding a test that prevents the installer list and asmdef references from divergin…
Out of Scope Changes check ✅ Passed All changes support the stated fix. The asmdef update, Unity test, and required Unity metadata files are directly related to resolving and preventing the UPM Roslyn reference failure.
Full details: Linked Issues check

Explanation

The PR satisfies issue #1295 by adding all five Roslyn DLLs installed by RoslynInstaller to precompiledReferences and adding a test that prevents the installer list and asmdef references from diverging.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 1 files. (3 skipped: 3 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

MCPForUnity.Editor sets overrideReferences, so it only sees precompiled
assemblies it names explicitly, and precompiledReferences listed only
Newtonsoft.Json.dll. RoslynInstaller writes its DLLs into the consuming
project's Assets/Plugins/Roslyn, outside the package, so defining
USE_ROSLYN left ManageScript.cs unable to resolve its
Microsoft.CodeAnalysis using directives and broke the build. Embedded
installs happened to work; UPM installs could not.

Adds the five DLL names RoslynInstaller installs. Unity ignores a
precompiledReferences entry whose assembly is absent, so projects
without Roslyn are unaffected — verified by the full EditMode suite
compiling and passing with none of these DLLs present.

The new test reads the DLL list off RoslynInstaller by reflection rather
than duplicating it, so the two cannot drift apart.

Closes CoplayDev#1295
@Scriptwonder
Scriptwonder force-pushed the fix/roslyn-upm-asmdef-references branch from c47b5f2 to a402781 Compare September 1, 2026 19:53
@Scriptwonder
Scriptwonder merged commit 9834f8d into CoplayDev:beta Sep 1, 2026
7 checks passed
toxifly added a commit to toxifly/unity-mcp that referenced this pull request Nov 26, 2026
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.

[Bug]: USE_ROSLYN can't be referenced when unity-mcp installed via UPM

2 participants