Skip to content

Commit 4bb0022

Browse files
claudeNormandErwan
authored andcommitted
fix(csproj): auto-detect Unity Hub DLLs on Windows/macOS/Linux
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
1 parent 41066f8 commit 4bb0022

1 file changed

Lines changed: 38 additions & 10 deletions

File tree

DocFxForUnity.csproj

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,48 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<TargetFramework>netstandard2.1</TargetFramework>
4-
<!--
5-
In CI: Unity managed DLLs are extracted to lib/UnityEngine/ by the workflow.
6-
Locally: set the UNITY_MANAGED_PATH environment variable to your Unity installation:
7-
Windows: C:\Program Files\Unity\Hub\Editor\6000.0.73f1\Editor\Data\Managed\UnityEngine
8-
macOS: /Applications/Unity/Hub/Editor/6000.0.73f1/Unity.app/Contents/Managed/UnityEngine
9-
Linux: ~/Unity/Hub/Editor/6000.0.73f1/Editor/Data/Managed/UnityEngine
10-
-->
11-
<UnityManagedPath Condition="'$(UNITY_MANAGED_PATH)' != ''">$(UNITY_MANAGED_PATH)</UnityManagedPath>
12-
<UnityManagedPath Condition="'$(UnityManagedPath)' == ''">lib/UnityEngine</UnityManagedPath>
134
</PropertyGroup>
145

156
<Target Name="AddUnityReferences" BeforeTargets="ResolveAssemblyReferences">
16-
<ItemGroup>
7+
<!--
8+
Priority 1: UNITY_MANAGED_PATH environment variable (explicit override).
9+
Priority 2: lib/UnityEngine/ extracted by CI from the game-ci Docker image.
10+
Priority 3: auto-detect from default Unity Hub installation paths (glob over installed versions).
11+
If nothing is found, a MSBuild warning is emitted.
12+
-->
13+
14+
<!-- Priorities 1 & 2: explicit path -->
15+
<PropertyGroup>
16+
<UnityManagedPath Condition="'$(UNITY_MANAGED_PATH)' != ''">$(UNITY_MANAGED_PATH)</UnityManagedPath>
17+
<UnityManagedPath Condition="'$(UnityManagedPath)' == '' and Exists('$(MSBuildProjectDirectory)/lib/UnityEngine')">$(MSBuildProjectDirectory)/lib/UnityEngine</UnityManagedPath>
18+
</PropertyGroup>
19+
20+
<!-- Collect DLLs from explicit path (priorities 1 or 2) -->
21+
<ItemGroup Condition="'$(UnityManagedPath)' != ''">
1722
<_UnityDll Include="$(UnityManagedPath)/*.dll" />
23+
</ItemGroup>
24+
25+
<!-- Priority 3: auto-detect on Windows -->
26+
<ItemGroup Condition="'$(UnityManagedPath)' == '' and $([MSBuild]::IsOSPlatform('Windows'))">
27+
<_UnityDll Include="C:\Program Files\Unity\Hub\Editor\*\Editor\Data\Managed\UnityEngine\*.dll" />
28+
</ItemGroup>
29+
30+
<!-- Priority 3: auto-detect on macOS -->
31+
<ItemGroup Condition="'$(UnityManagedPath)' == '' and $([MSBuild]::IsOSPlatform('OSX'))">
32+
<_UnityDll Include="/Applications/Unity/Hub/Editor/*/Unity.app/Contents/Managed/UnityEngine/*.dll" />
33+
</ItemGroup>
34+
35+
<!-- Priority 3: auto-detect on Linux -->
36+
<ItemGroup Condition="'$(UnityManagedPath)' == '' and $([MSBuild]::IsOSPlatform('Linux'))">
37+
<_UnityDll Include="$(HOME)/Unity/Hub/Editor/*/Editor/Data/Managed/UnityEngine/*.dll" />
38+
</ItemGroup>
39+
40+
<!-- Warning if no Unity DLLs found at all -->
41+
<Warning Condition="'@(_UnityDll)' == ''"
42+
Text="Unity managed DLLs not found. Set UNITY_MANAGED_PATH to your Unity installation's Managed/UnityEngine directory (e.g. /Applications/Unity/Hub/Editor/6000.0.73f1/Unity.app/Contents/Managed/UnityEngine), or install Unity Hub at its default location." />
43+
44+
<!-- Add assembly references for all discovered DLLs -->
45+
<ItemGroup>
1846
<Reference Include="%(_UnityDll.Filename)">
1947
<HintPath>%(_UnityDll.FullPath)</HintPath>
2048
<Private>false</Private>

0 commit comments

Comments
 (0)