-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathDirectory.Build.props
More file actions
193 lines (174 loc) · 10.1 KB
/
Copy pathDirectory.Build.props
File metadata and controls
193 lines (174 loc) · 10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<Project>
<PropertyGroup>
<Version>0.13.2</Version>
<!-- API Configuration - Change these URLs to use your own instance -->
<ApiBaseUrl>https://unitygametranslator.asymptomatikgames.com/api/v1</ApiBaseUrl>
<WebsiteBaseUrl>https://unitygametranslator.asymptomatikgames.com</WebsiteBaseUrl>
<SseBaseUrl>https://sse-unitygametranslator.asymptomatikgames.com</SseBaseUrl>
<!--
Where somebody gets the Manager, offered beside the manual download.
/releases/latest is resolved by GitHub itself, so this never goes stale and costs no API
call: the mod knows the address without asking anything. Here rather than in the code
because a self-hosted setup redirects its own users somewhere else, exactly like the URLs
above.
-->
<ManagerReleaseUrl>https://github.com/djethino/unitygametranslator-manager/releases/latest</ManagerReleaseUrl>
</PropertyGroup>
<!-- Generate PluginInfo.g.cs with version and API constants before build.
🔴 **BeforeTargets="PrepareForBuild", not "CoreCompile".** CoreCompile is SKIPPED when the
sources are older than the assembly — so on an up-to-date tree this target never ran, the
generated file kept what the previous build had put in it, and a build asked to point
elsewhere (-p:ApiBaseUrl=…, as build-and-deploy.ps1 -Local does) silently produced a DLL
carrying the OLD addresses. It worked whenever something happened to force a recompilation,
which is the worst kind of failure: intermittent, and invisible in the log.
PrepareForBuild runs on every build. WriteOnlyWhenDifferent keeps the incremental build:
the file is rewritten only when its content actually changes, and that change is what makes
the compiler consider the assembly out of date. -->
<Target Name="GenerateVersionFile" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<VersionFileContent>
namespace UnityGameTranslator {
internal static class PluginInfo {
public const string Version = "$(Version)"%3B
/// <summary>Base URL for API calls (e.g., https://example.com/api/v1)</summary>
public const string ApiBaseUrl = "$(ApiBaseUrl)"%3B
/// <summary>Base URL for website links (e.g., https://example.com)</summary>
public const string WebsiteBaseUrl = "$(WebsiteBaseUrl)"%3B
/// <summary>Base URL for SSE streams (e.g., https://sse-example.com)</summary>
public const string SseBaseUrl = "$(SseBaseUrl)"%3B
/// <summary>Where the Manager is downloaded from, when it is not already on the machine</summary>
public const string ManagerReleaseUrl = "$(ManagerReleaseUrl)"%3B
}
}
</VersionFileContent>
</PropertyGroup>
<WriteLinesToFile File="$(IntermediateOutputPath)PluginVersion.g.cs"
Lines="$(VersionFileContent)"
Overwrite="true"
WriteOnlyWhenDifferent="true" />
<ItemGroup>
<Compile Include="$(IntermediateOutputPath)PluginVersion.g.cs" />
</ItemGroup>
</Target>
<!--
ILRepack: merge Newtonsoft.Json, UniverseLib and UnityGameTranslator.Core
into the single shipped UnityGameTranslator.dll. This avoids version
conflicts when other plugins (e.g. UnityExplorer, mods using Newtonsoft.Json)
are installed in the same game. Each adapter sets:
<EnableILRepack>true</EnableILRepack>
<UniverseLibDllPath>relative path to the right UniverseLib variant</UniverseLibDllPath>
<ILRepackLibraryPath>semicolon-separated dirs to resolve unmerged refs</ILRepackLibraryPath>
-->
<PropertyGroup>
<!-- Suppress the package's default auto-target so only our explicit ILRepackMerge runs.
Set unconditionally because Directory.Build.props is evaluated before the
per-project EnableILRepack property is set. The path points to an existing empty
file so the package's `!Exists($(ILRepackTargetsFile))` skips its built-in target. -->
<ILRepackTargetsFile>$(MSBuildThisFileDirectory)ILRepack.disabled.targets</ILRepackTargetsFile>
</PropertyGroup>
<ItemGroup Condition="'$(EnableILRepack)' == 'true'">
<PackageReference Include="ILRepack.Lib.MSBuild.Task" Version="2.0.34.2" PrivateAssets="all" />
</ItemGroup>
<!--
For IL2CPP adapters, UnityGameTranslator.Core.dll is compiled against UniverseLib.Mono.dll
(compile-time reference) but at runtime we ship UniverseLib.{BIE|ML}.IL2CPP.Interop.dll
which has a DIFFERENT assembly name. Without rewriting, the ILRepack-merged DLL still
has an external `UniverseLib.Mono` reference -> MelonLoader warning + future fatal error.
The fix: pre-merge step using Mono.Cecil to rewrite Core.dll's external assembly
reference from `UniverseLib.Mono` to the adapter's actual runtime UniverseLib variant
name. After this, ILRepack can match the input UniverseLib variant DLL and properly
rebind types into the merged output.
Activated by setting <RewriteCoreUniverseLibRef>UniverseLib.XYZ</RewriteCoreUniverseLibRef>
in the adapter csproj.
-->
<ItemGroup Condition="'$(EnableILRepack)' == 'true' AND '$(RewriteCoreUniverseLibRef)' != ''">
<PackageReference Include="Mono.Cecil" Version="0.11.5" PrivateAssets="all" />
</ItemGroup>
<PropertyGroup>
<!-- Set unconditionally because Directory.Build.props is loaded BEFORE the per-csproj
RewriteCoreUniverseLibRef property is evaluated. The property is harmless when the
Mono.Cecil package is not installed (PackageReference is conditional). -->
<_CecilDll Condition="'$(NuGetPackageRoot)' != ''">$(NuGetPackageRoot)mono.cecil\0.11.5\lib\netstandard2.0\Mono.Cecil.dll</_CecilDll>
<_CecilDll Condition="'$(_CecilDll)' == '' AND '$(NUGET_PACKAGES)' != ''">$(NUGET_PACKAGES)\mono.cecil\0.11.5\lib\netstandard2.0\Mono.Cecil.dll</_CecilDll>
<_CecilDll Condition="'$(_CecilDll)' == ''">$(UserProfile)\.nuget\packages\mono.cecil\0.11.5\lib\netstandard2.0\Mono.Cecil.dll</_CecilDll>
</PropertyGroup>
<UsingTask TaskName="RewriteAssemblyRef"
TaskFactory="RoslynCodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll"
Condition="'$(EnableILRepack)' == 'true' AND '$(RewriteCoreUniverseLibRef)' != ''">
<ParameterGroup>
<DllPath ParameterType="System.String" Required="true" />
<FromName ParameterType="System.String" Required="true" />
<ToName ParameterType="System.String" Required="true" />
</ParameterGroup>
<Task>
<Reference Include="$(_CecilDll)" />
<Using Namespace="Mono.Cecil" />
<Code Type="Fragment" Language="cs">
<![CDATA[
var asm = AssemblyDefinition.ReadAssembly(DllPath, new ReaderParameters { ReadWrite = true });
try {
int rewrites = 0;
foreach (var r in asm.MainModule.AssemblyReferences) {
if (r.Name == FromName) {
Log.LogMessage(MessageImportance.High, "[CecilRewrite] " + DllPath + ": " + FromName + " -> " + ToName);
r.Name = ToName;
rewrites++;
}
}
if (rewrites > 0) asm.Write();
} finally {
asm.Dispose();
}
]]>
</Code>
</Task>
</UsingTask>
<Target Name="RewriteCoreReferences"
BeforeTargets="ILRepackMerge"
Condition="'$(EnableILRepack)' == 'true' AND '$(RewriteCoreUniverseLibRef)' != ''">
<RewriteAssemblyRef
DllPath="$(OutputPath)UnityGameTranslator.Core.dll"
FromName="UniverseLib.Mono"
ToName="$(RewriteCoreUniverseLibRef)" />
</Target>
<Target Name="ILRepackMerge" AfterTargets="Build" Condition="'$(EnableILRepack)' == 'true'">
<!-- Stage the UniverseLib DLL into the bin folder so ILRepack can find it -->
<Copy Condition="'$(UniverseLibDllPath)' != '' AND Exists('$(UniverseLibDllPath)')"
SourceFiles="$(UniverseLibDllPath)"
DestinationFolder="$(OutputPath)"
SkipUnchangedFiles="true" />
<PropertyGroup>
<_UniverseLibFileName>$([System.IO.Path]::GetFileName('$(UniverseLibDllPath)'))</_UniverseLibFileName>
</PropertyGroup>
<ItemGroup>
<_RepackInputs Include="$(TargetPath)" />
<_RepackInputs Include="$(OutputPath)UnityGameTranslator.Core.dll"
Condition="Exists('$(OutputPath)UnityGameTranslator.Core.dll')" />
<!-- ⚠ The shared library, and this line is not optional. What ships is ONE merged DLL, and
this list is what goes into it: an assembly missing from here compiles perfectly, then
is not found inside a game at the first call, with nothing at build time having said a
word. See the common/ submodule, and add any future shared assembly here as well. -->
<_RepackInputs Include="$(OutputPath)UnityGameTranslator.Common.dll"
Condition="Exists('$(OutputPath)UnityGameTranslator.Common.dll')" />
<_RepackInputs Include="$(OutputPath)Newtonsoft.Json.dll"
Condition="Exists('$(OutputPath)Newtonsoft.Json.dll')" />
<_RepackInputs Include="$(OutputPath)$(_UniverseLibFileName)"
Condition="'$(_UniverseLibFileName)' != '' AND Exists('$(OutputPath)$(_UniverseLibFileName)')" />
</ItemGroup>
<Message Text="[ILRepack] Merging into $(TargetFileName): @(_RepackInputs->'%(Filename)%(Extension)', ', ')" Importance="high" />
<ILRepack
Parallel="true"
Internalize="true"
InputAssemblies="@(_RepackInputs)"
TargetKind="Dll"
OutputFile="$(TargetPath)"
LibraryPath="$(ILRepackLibraryPath)"
/>
<!-- Remove the now-merged source DLLs from bin so the build output only contains UnityGameTranslator.dll -->
<Delete Files="$(OutputPath)UnityGameTranslator.Core.dll" Condition="Exists('$(OutputPath)UnityGameTranslator.Core.dll')" />
<Delete Files="$(OutputPath)Newtonsoft.Json.dll" Condition="Exists('$(OutputPath)Newtonsoft.Json.dll')" />
<Delete Files="$(OutputPath)$(_UniverseLibFileName)"
Condition="'$(_UniverseLibFileName)' != '' AND Exists('$(OutputPath)$(_UniverseLibFileName)')" />
</Target>
</Project>