From 93c39e2133acd086bf81057893b3e87be34459e3 Mon Sep 17 00:00:00 2001 From: Soar Qin Date: Sun, 22 Mar 2026 15:44:34 +0800 Subject: [PATCH] build: remove legacy UpdateGameDlls target and simplify PS1 script Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus --- .gitignore | 3 --- AGENTS.md | 22 +++++++++++----------- Directory.Build.targets | 34 ---------------------------------- UpdateGameDlls.ps1 | 34 +--------------------------------- 4 files changed, 12 insertions(+), 81 deletions(-) diff --git a/.gitignore b/.gitignore index e31eb74..6e79db6 100644 --- a/.gitignore +++ b/.gitignore @@ -18,6 +18,3 @@ build/ /*/package/*.zip /*/package/patchers/ /*/package/plugins/ - -# UpdateGameDlls build-time lock file (created by UpdateGameDlls.ps1) -AssemblyFromGame/.update.lock diff --git a/AGENTS.md b/AGENTS.md index 7a10c07..21be6f3 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -41,6 +41,7 @@ DSP_Mods/ ├── PoolOpt/ # Memory pool optimization on save loading ├── UniverseGenTweaks/ # Universe generator parameter tweaks ├── UserCloak/ # Hides/fakes Steam account info +├── UpdateGameDlls/ # MSBuild helper project; runs UpdateGameDlls.ps1 before any mod compiles └── CompressSave/ # Stub only (moved to external repo) ``` @@ -70,35 +71,34 @@ DSP_Mods/ Common properties and references are factored into two root-level files that MSBuild automatically imports for every project: -- **`Directory.Build.props`** — shared `PropertyGroup` defaults (`TargetFramework`, `AllowUnsafeBlocks`, `LangVersion`, `RestoreAdditionalProjectSources`) and shared `ItemGroup`s (BepInEx packages, game DLL references, `Microsoft.NETFramework.ReferenceAssemblies`). -- **`Directory.Build.targets`** — defines the `UpdateGameDlls`, `ZipMod`, and `CopyToParentPackage` targets (see below). -- **`UpdateGameDlls.ps1`** — PowerShell script invoked by the `UpdateGameDlls` target; locates the DSP installation via Steam registry and `libraryfolders.vdf`, compares DLL timestamps, and re-publicizes stale DLLs using `assembly-publicizer`. +- **`Directory.Build.props`** — shared `PropertyGroup` defaults (`TargetFramework`, `AllowUnsafeBlocks`, `LangVersion`, `RestoreAdditionalProjectSources`) and shared `ItemGroup`s (BepInEx packages, game DLL references, `Microsoft.NETFramework.ReferenceAssemblies`), and a global `ProjectReference` to the `UpdateGameDlls` helper project (ensuring game DLLs are refreshed before any mod project resolves assembly references). +- **`Directory.Build.targets`** — defines the `ZipMod` and `CopyToParentPackage` targets (see below). +- **`UpdateGameDlls.ps1`** — PowerShell script invoked by the `UpdateGameDlls` helper project; locates the DSP installation via Steam registry and `libraryfolders.vdf`, compares DLL timestamps, and re-publicizes stale DLLs using `assembly-publicizer`. Individual `.csproj` files only declare what is unique to that project (GUID, version, extra packages, embedded resources). ### Automatic Game DLL Update -`AssemblyFromGame/` holds publicized copies of two game DLLs used as compile-time references. They are refreshed automatically **once per solution build** by the `UpdateGameDlls` MSBuild target, which calls `UpdateGameDlls.ps1`. +`AssemblyFromGame/` holds publicized copies of two game DLLs used as compile-time references. They are refreshed automatically before any mod project compiles by the `UpdateGameDlls` helper project. -The target runs only when the `UXAssist` project is being built (the designated trigger project), or when either DLL is missing from `AssemblyFromGame/`. This prevents redundant executions and file-write conflicts when projects are built in parallel (`dotnet build -m`). The PowerShell script additionally acquires an exclusive file lock (`AssemblyFromGame/.update.lock`) so that the rare case where the `!Exists` fallback triggers multiple projects concurrently is also handled safely. +The helper project (`UpdateGameDlls/UpdateGameDlls.csproj`) uses the `Microsoft.Build.NoTargets` SDK and is declared as a global `ProjectReference` in `Directory.Build.props` with `ReferenceOutputAssembly=false`, `SkipGetTargetFrameworkProperties=true`, and `Private=false`. This ensures that MSBuild's dependency graph guarantees the helper project completes before any mod project resolves assembly references, with no need for file locks or conditional triggers. -The script: +The `UpdateGameDlls.ps1` script: 1. Reads the Steam installation path from the Windows registry (`HKCU\Software\Valve\Steam`). 2. Parses `steamapps/libraryfolders.vdf` to find the library that contains DSP (AppID `1366540`). 3. Locates `/DSPGAME_Data/Managed/`. -4. Acquires an exclusive file lock on `AssemblyFromGame/.update.lock` (waits up to 60 s). -5. For each DLL (`Assembly-CSharp.dll`, `UnityEngine.UI.dll`): if the game copy is newer than the local copy, runs `assembly-publicizer … --strip --overwrite` to regenerate the local file and stamps it with the source timestamp. +4. For each DLL (`Assembly-CSharp.dll`, `UnityEngine.UI.dll`): if the game copy is newer than the local copy, runs `assembly-publicizer … --strip --overwrite` to regenerate the local file and stamps it with the source timestamp. -The target can also be run explicitly: +To explicitly update game DLLs: ``` -dotnet build -t:UpdateGameDlls +dotnet build UpdateGameDlls\UpdateGameDlls.csproj ``` **Prerequisite:** `assembly-publicizer` must be installed as a .NET global tool: ``` dotnet tool install -g BepInEx.AssemblyPublicizer.Cli ``` -If the tool is missing or DSP is not found, the target prints a warning and continues without failing the build. +If the tool is missing or DSP is not found, the script prints a warning and continues without failing the build. ### Packaging diff --git a/Directory.Build.targets b/Directory.Build.targets index 74c5463..b4463f8 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -1,39 +1,5 @@ - - - - -