Skip to content

fix(csproj): auto-detect Unity Hub DLLs on Windows/macOS/Linux#33

Merged
NormandErwan merged 2 commits into
mainfrom
claude/analyze-repo-issues-Ok1RZ
May 2, 2026
Merged

fix(csproj): auto-detect Unity Hub DLLs on Windows/macOS/Linux#33
NormandErwan merged 2 commits into
mainfrom
claude/analyze-repo-issues-Ok1RZ

Conversation

@NormandErwan
Copy link
Copy Markdown
Owner

@NormandErwan NormandErwan commented May 2, 2026

Problem

Previously, DocFxForUnity.csproj resolved Unity DLLs in only two ways:

  1. UNITY_MANAGED_PATH env var if set
  2. Unconditional fallback to lib/UnityEngine (the CI path)

A developer without UNITY_MANAGED_PATH defined and no lib/UnityEngine folder (i.e. anyone who hasn't run the CI workflow locally) would silently get an empty reference list — no Unity types resolved, no xref links, no error message explaining why.

This is linked to issues #28, #14, #15, and #12.

Solution

All path resolution logic is moved inside the AddUnityReferences target (evaluated at build time). Three-level priority chain:

Priority Source Condition
1 UNITY_MANAGED_PATH env var explicit override
2 lib/UnityEngine/ CI path, checked with Exists()
3 OS-specific glob over Unity Hub default install dir auto-detection, no config required

If no DLL is found after all three steps, a MSBuild <Warning> is emitted with a clear, actionable message.

Auto-detection paths (priority 3)

OS Glob
Windows C:\Program Files\Unity\Hub\Editor\*\Editor\Data\Managed\UnityEngine\*.dll
macOS /Applications/Unity/Hub/Editor/*/Unity.app/Contents/Managed/UnityEngine/*.dll
Linux $(HOME)/Unity/Hub/Editor/*/Editor/Data/Managed/UnityEngine/*.dll

The * wildcard covers any Unity version installed via Unity Hub — no version pinning required in the .csproj.

Test plan

  • CI — workflow still extracts DLLs to lib/UnityEngine/; priority 2 fires, no regression
  • Local + UNITY_MANAGED_PATH — priority 1 fires, same behaviour as before
  • Local + Unity Hub installed, no env var — priority 3 finds DLLs; dotnet build -v:normal shows no warning
  • Local + no Unity installed@(_UnityDll) is empty; MSBuild warning is visible in build output

https://claude.ai/code/session_01DctbQWKKrBNCfvBuKsu5ad


Generated by Claude Code

If UNITY_MANAGED_PATH is not set and lib/UnityEngine/ does not exist
(CI path), the target now falls back to OS-specific glob patterns over
the default Unity Hub installation directory (*-wildcard on version).
A MSBuild Warning is emitted when no DLL is found after all three
resolution steps, replacing the previous silent failure.

https://claude.ai/code/session_01DctbQWKKrBNCfvBuKsu5ad
@NormandErwan NormandErwan marked this pull request as ready for review May 2, 2026 19:46
…PATH

- Add DocFxForUnity.csproj to the list of files to copy in setup step 2,
  with a note on renaming and updating docfx.json
- Replace the outdated "Assets > Open C# Project" troubleshooting tip
  with instructions matching the committed .csproj approach
- Add a "Unity managed DLLs not found" FAQ entry describing the
  three-step resolution order (env var → lib/ → OS glob)
- Add a new "Advanced: UNITY_MANAGED_PATH" section with per-OS paths
  and shell snippets for overriding the auto-detected Unity version
- Update xref version examples from 2017/2018/2019 to current versions

https://claude.ai/code/session_01DctbQWKKrBNCfvBuKsu5ad
@NormandErwan NormandErwan merged commit 9c5a321 into main May 2, 2026
2 checks passed
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.

2 participants