Skip to content

Multi-arch container publish compiles every referenced project once per architecture, into one output folder (CS2012 in parallel) #57267

Open

Description

@lahma

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

  1. added
    untriaged
    on Nov 21, 2026
  2. locked and limited conversation to collaborators on Nov 21, 2026
  3. unlocked this conversation on Nov 21, 2026
  4. added
    Area-Containers
    cookie
    and removed
    untriaged
    on Nov 21, 2026
  5. github-actions commented on Nov 21, 2026

    @github-actions
    Contributor

    🎯 Agentic Issue Triage

    Triage Assessment:

    • 🏷️ Labels: Area-Containers Related to dotnet SDK containers functionality Bug cookie Issue Monster Loves Cookies!
    • 💻 Assignment: @baronfel | @dotnet/sdk-container-builds-maintainers
    • 🟩 Confidence: high - 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.

    Generated by 🏷️ Issue Triage for #57267 · copilot · auto (Claude Sonnet 5.5) · ~13 AIC · ⌖ ~2 AIC · ⊞ 15.5K · ◷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Area-ContainersBugcookie

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions