Repository navigation
Description
Describe the bug
In a multi-architecture container publish, each architecture's build passes ContainerRuntimeIdentifier, and the other container properties, on to its ProjectReferences as global properties.
So a RID-agnostic library gets one project instance per architecture, plus the outer build's, and every instance compiles into the same obj and bin folder. The architectures' builds run in parallel by default (ContainerPublishInParallel is true), so two compilations of one library can write the same file at once.
In a larger repository, a publish whose outputs were not up to date failed 3 times out of 3:
error CS2012: Cannot open '…/obj/Quartz.Analyzers/debug/Quartz.Analyzers.dll' for writing
It failed the same way for another referenced library. Even when the race doesn't hit, every referenced project is compiled once more for each architecture.
To Reproduce
.NET SDK 11.0.100 on Windows x64.
app/app.csproj:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<RuntimeIdentifiers>linux-x64;linux-arm64</RuntimeIdentifiers>
<ContainerRuntimeIdentifiers>linux-x64;linux-arm64</ContainerRuntimeIdentifiers>
<ContainerRepository>shared-obj-repro</ContainerRepository>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../lib/lib.csproj" />
</ItemGroup>
</Project>app/Program.cs:
WebApplication.CreateBuilder(args).Build().Run();
Console.WriteLine(Lib.Greeting.Text);lib/lib.csproj. The target is only there to show each compilation:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
</PropertyGroup>
<Target Name="ShowWhoCompiles" BeforeTargets="CoreCompile">
<Message Importance="high" Text="lib CoreCompile: ContainerRuntimeIdentifier='$(ContainerRuntimeIdentifier)' RuntimeIdentifier='$(RuntimeIdentifier)' IntermediateAssembly='@(IntermediateAssembly->'%(FullPath)')'" />
</Target>
</Project>lib/Greeting.cs:
namespace Lib;
public static class Greeting
{
public const string Text = "hello";
}From a clean tree, run:
dotnet publish app -c Release -t:PublishContainer -p:ContainerArchiveOutputPath=out/shared.tar.gz -v:n
The library compiles three times, into one path. The two architecture builds run on different nodes:
lib CoreCompile: ContainerRuntimeIdentifier='' RuntimeIdentifier='' IntermediateAssembly='…\lib\obj\Release\net10.0\lib.dll'
lib CoreCompile: ContainerRuntimeIdentifier='linux-x64' RuntimeIdentifier='' IntermediateAssembly='…\lib\obj\Release\net10.0\lib.dll'
lib CoreCompile: ContainerRuntimeIdentifier='linux-arm64' RuntimeIdentifier='' IntermediateAssembly='…\lib\obj\Release\net10.0\lib.dll'
This one-file library compiles too quickly for the two writes to collide; with larger libraries they do, as shown above. -p:ContainerPublishInParallel=false avoids the collision, but the library is still compiled three times.
Cause
The _InnerBuild item's AdditionalProperties become global properties of each architecture's build: ContainerRuntimeIdentifier, _ContainerLabel, _IsMultiRIDInnerBuild and the rest. For a RID-agnostic reference the project-reference protocol drops RuntimeIdentifier, but these properties still flow to every ProjectReference. Each architecture therefore gets its own instance of every referenced project, and all of them share one output path. #46109 is the same kind of collision for the app's own PublishDir when --output is passed. This one happens without --output, and with the artifacts layout as well.
Expected
Referenced projects build once and are shared by the architectures, as they already are for RuntimeIdentifier. For example, the inner build's container-only properties could be removed from its project references (GlobalPropertiesToRemove, or adding them to _GlobalPropertiesToRemoveFromProjectReferences for the inner builds).
Workaround
<ContainerPublishInParallel>false</ContainerPublishInParallel> in the published project.
Found in quartznet/quartznet#4390, which publishes the Quartz.NET dashboard image for linux-x64 and linux-arm64.
Activity
github-actions commentedon Nov 21, 2026
🎯 Agentic Issue Triage
Triage Assessment:
@baronfel| @dotnet/sdk-container-builds-maintainershigh- Issue directly targets multi-arch container publish targets, and the CODEOWNERS section is unambiguous.Similar issues: #46109 (
potentially related)➡️ Summary: Multi-arch container publish passes container properties to ProjectReferences, building each library per architecture into one folder, causing CS2012 races. Consider removing those inner-build properties from project references.
The container workarounds name the SDK issues that remove them