Skip to content

Make project reference traversal safe for parallel builds - #751

Merged
kzu merged 1 commit into
mainfrom
alta/sunny-deneb-gnqx
Dec 3, 2026
Merged

kzu merged 1 commit into
mainfrom
alta/sunny-deneb-gnqx

Conversation

@kzu

@kzu kzu commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

A solution using NuGetizer packaging projects failed a plain parallel dotnet build with CS2012 (file used by another process); -m:1 passed. The .NET 11 SDK passes -maxcpucount, so builds are parallel by default.

Cause

Packing called referenced projects with extra global properties: FromPackagingProject=true (packaging projects' ProjectReference item definition), BuildingPackage and DesignTimeBuild=false (_GetReferencedPackageContents), IsPackable=false and PackFolder/PackFrameworkSpecific (_SplitProjectReferencesByIsNuGetized). Each distinct set is another MSBuild configuration of the reference. Global properties are inherited, so those configurations also built the reference's own references (ResolveProjectReferences) into the same obj folder, racing with the normal build.

Change

References are called with the global properties a normal build uses, so GetPackageContents runs on the instance Build built:

  • Removed FromPackagingProject (it only fed an import of a file that isn't in build/), the Xamarin.Android 9.4 DesignTimeBuild=false workaround, and BuildingPackage (the referencing project already assigns package paths to referenced contents through IsPackaging).
  • PrivateAssets=all passes _PackAsPrivateAssets=true, which NuGetizer.props and NuGetizer.Shared.targets turn into IsPackable=false. IsPackable itself can't be told apart from a command-line -p:IsPackable=false.
  • A PackFolder override and PrivateAssets=all still reach the reference for GetPackageContents, because they change what it infers (PackNone, PackFrameworkReferences, Microsoft.Build* dependencies, bundling of packable transitive references). They are added to _GlobalPropertiesToRemoveFromProjectReferences, so they never reach the build of the reference's own references.

A binlog of a parallel solution build with PackOnBuild=true (a PackFolder override, PrivateAssets=all and a transitive reference) shows the configurations with pack properties only run GetPackageContents (resolution and inference targets, no CoreCompile or copies), and each project/TFM compiles in exactly one configuration.

Edge-case behavior changes: a framework-specific packaging project now retargets content of references of references to its own TFM, as it already did for direct references; dotnet-nugetize's DesignTimeBuild=true now reaches references too.

Tests

  • New given_parallel_builds: a packaging project calls its references in a single configuration without pack properties; with PrivateAssets=all and a PackFolder, contents are bundled transitively, no configuration with pack properties builds, and every project compiles once.
  • Rebased on main (NuGet.Packaging 8.0, RuntimeFact("Windows") running on .NET Framework). Packaging-project, complex pack, project reference, multi-targeting, transitive and inline project tests: 149 passed, 1 skipped. The 2 given_multitargeting_libraries tests failed locally only because the maccatalyst workload isn't installed here (CI restores it).

🤖 Generated with Claude Code

This pull request was created by CodeAlta.

@kzu kzu added the enhancement New feature or request label Dec 2, 2026
@kzu
kzu enabled auto-merge (rebase) December 2, 2026 20:48
@kzu

kzu commented Dec 2, 2026 •

Copy link
Copy Markdown
Member Author

252 passed 252 passed 69 skipped
322 passed 322 passed 1 skipped

🧪 Details on Ubuntu 26.04.1 LTS
🧪 Details on Microsoft Windows 10.0.26100

from dotnet-retest v1.0.0 on .NET 11.0.0 with 💜 by @devlooped

Packing called referenced projects with extra global properties
(FromPackagingProject, BuildingPackage, DesignTimeBuild, IsPackable,
PackFolder). Each distinct set starts another configuration of the
reference, which builds it (and, by inheritance, its references) again
into the same obj folder. In a parallel build two of those compile at
once and fail with CS2012.

References are now called with the global properties a normal build
uses, so GetPackageContents runs on the instance Build built:

- Drop FromPackagingProject (it only fed a dead import), the
  DesignTimeBuild=false Xamarin.Android 9.4 workaround and BuildingPackage
  (the referencing project assigns package paths itself).
- PrivateAssets=all passes _PackAsPrivateAssets=true, mapped to
  IsPackable=false in the reference, instead of IsPackable=false, which
  can't be told apart from a command-line global.
- PackFolder, PackFrameworkSpecific and _PackAsPrivateAssets still reach
  the reference for GetPackageContents, since they change what it infers,
  but are added to _GlobalPropertiesToRemoveFromProjectReferences so they
  never reach the build of its own references.

Co-authored-by: CodeAlta <noreply@codealta.io>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kzu
kzu force-pushed the alta/sunny-deneb-gnqx branch from b6949f5 to b9c328b Compare December 3, 2026 11:00
@kzu
kzu merged commit 430a401 into main Dec 3, 2026
4 checks passed
@kzu
kzu deleted the alta/sunny-deneb-gnqx branch December 3, 2026 11:12
kzu added a commit to devlooped/stunts that referenced this pull request Dec 3, 2026
…arallel

The .NET 11 SDK passes -maxcpucount, which wins over the -m:1 of
Directory.Build.rsp, and the parallel build failed with CS2012 file locks:
global properties on project references built Stunts, Stunts.CodeAnalysis
and Stunts.CompiledProxy again, in other configurations, into the same obj.

NuGetizer 1.5.2 (devlooped/nugetizer#751) no longer passes its own global
properties to referenced projects, and passes a reference's PackFolder to
GetPackageContents alone. Stunts.Package now asks for the tool layout of the
generator with that PackFolder instead of IsPackable=false, so the generator
compiles once and only its package contents take the shape of a tool. The
tool layout removes the documentation of the references it packs too, which
now get its PackFolder.

Two clean parallel builds compile each project and target framework once,
and the packages match a serial build with NuGetizer 1.5.1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: CodeAlta <noreply@codealta.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant