fix: resolve MSB3491 race condition in WriteLaunchers parallel builds#199
Open
BenjaminMichaelis wants to merge 1 commit into
Open
fix: resolve MSB3491 race condition in WriteLaunchers parallel builds#199BenjaminMichaelis wants to merge 1 commit into
BenjaminMichaelis wants to merge 1 commit into
Conversation
Write build variables to \ (per-project output directory) instead of a shared global temp path. Multiple projects building in parallel each get their own unique output directory, eliminating the delete-then-create race on the shared temp file. Update the RepositoryPaths.BuildVariables reader to use AppContext.BaseDirectory instead of Path.GetTempPath(), since the .tmp file now lives alongside the built assembly. AppContext.BaseDirectory is AOT-safe and correctly resolves in Live Unit Testing scenarios. Remove the now-unnecessary TempStagingPath property and collapse the two conditional WriteLinesToFile calls into one unconditional write.
There was a problem hiding this comment.
Pull request overview
This PR fixes a parallel-build race (MSB3491) and a non-determinism bug by moving the “build variables” file from a shared global temp path to each project’s output directory, and updating runtime lookup accordingly.
Changes:
- Write
IntelliTect.MultiTool.BuildVariables.tmpto$(OutDir)(per-project/per-TFM) instead of%TEMP%. - Update
RepositoryPaths.BuildVariablesto read fromAppContext.BaseDirectory(matching the output dir at runtime). - Refresh an AOT test comment to reflect the new file location.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| IntelliTect.Multitool/Build/IntelliTect.Multitool.targets | Writes build variables file into $(OutDir) to avoid parallel build collisions and cross-project contamination. |
| IntelliTect.Multitool/RepositoryPaths.cs | Reads build variables from AppContext.BaseDirectory so runtime resolves the same per-project output directory file. |
| IntelliTect.Multitool.AotTest/Program.cs | Updates comment describing why RepositoryPaths is excluded from AOT test. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
WriteLauncherswrote build variables to a hardcoded global temp path:When a solution has multiple projects referencing this package,
dotnet buildbuilds them in parallel. All projects resolved to the same absolute file path, andWriteLinesToFilewithOverwrite="true"is not atomic (delete-then-create). Two parallel project builds racing on that path caused:There was also a correctness bug: even when writes didn't collide, the winning writer was non-deterministic — the file could end up containing variables from any project in the solution, not the one that would consume it at runtime.
Fix
Write the build variables file to
$(OutDir)— each project's output directory — which is already unique per project and per TFM. Update the C# reader to look inAppContext.BaseDirectoryinstead ofPath.GetTempPath(), sinceAppContext.BaseDirectoryresolves to the same output directory at runtime.Changes
IntelliTect.Multitool/Build/IntelliTect.Multitool.targetsTempStagingPathproperty (was the source of the shared path)WriteLinesToFilecalls into one unconditional write to$(OutDir)IntelliTect.MultiTool.BuildVariables.tmpIntelliTect.Multitool/RepositoryPaths.csPath.GetTempPath()→AppContext.BaseDirectoryinBuildVariablesinitializerIntelliTect.Multitool.AotTest/Program.csWhy
$(OutDir)+AppContext.BaseDirectoryAppContext.BaseDirectoryfollowsAppContext.BaseDirectoryworks in single-file/AOT (unlikeAssembly.Location)$(OutDir)always ends with a path separator; valid on Windows and Linux