Skip to content

Set _IsPublishing=true and add ProjectReference for PublishDotnetAot - #6590

Merged
dsplaisted merged 3 commits into
dotnet:mainfrom
dsplaisted:add-ispublishing-to-aot-publish
May 15, 2026
Merged

dsplaisted merged 3 commits into
dotnet:mainfrom
dsplaisted:add-ispublishing-to-aot-publish

Conversation

@dsplaisted

Copy link
Copy Markdown
Member

Summary

Follow-up to #6576. Two related changes to PublishDotnetAot in src/sdk/src/Layout/redist/:

  1. Pass _IsPublishing=true as a global property to the <MSBuild Targets="Publish"> call on dotnet-aot.csproj. Per @MichalStrehovsky's feedback on Use MSBuild task instead of Exec for PublishDotnetAot #6576, running the Publish target without _IsPublishing=true has been a source of subtle issues — it's the property the SDK uses to gate Publish-aware behaviors (suppressing apphost generation when PublishAot=true, several NETSdkError conditions, _RuntimeIdentifierUsesAppHost adjustments, etc.).

  2. Add a ProjectReference from redist.csproj to dotnet-aot.csproj (ReferenceOutputAssembly=false, SkipGetTargetFrameworkProperties=true, Private=false). This sequences the outer solution build's evaluation of dotnet-aot.csproj to complete before redist's GenerateSdkLayout target runs, eliminating the race surface re-introduced by change (1).

cc @ericstj @MichalStrehovsky @NikolaMilosavljevic

dsplaisted and others added 2 commits May 13, 2026 09:01
Per @MichalStrehovsky on dotnet#6576, running the Publish target
directly without also setting _IsPublishing=true has been a source of subtle
issues in the past, because just running Publish is not enough to get all
the Publish-time behaviors. _IsPublishing is the property the SDK uses to
gate Publish-aware logic in Microsoft.NET.RuntimeIdentifierInference.targets
and Microsoft.NET.Publish.targets (e.g. suppressing apphost generation when
PublishAot is true, AOT-specific error conditions, etc.).

This addresses the AOT NETSdkError condition guarded by
'$(PublishAot)' == 'true' and '$(_IsPublishing)' != 'true' and ...

Note: passing _IsPublishing=true as a global property means BuildManager
treats this call as a different project instance from the outer solution
build's evaluation of dotnet-aot.csproj. The previous form (no global
properties) deliberately shared the instance to avoid that race. With this
change, dotnet-aot.csproj is now evaluated three times (SolutionRestore,
outer Build, separate Publish-with-_IsPublishing), and the separate
Publish call's Build dependency could in principle race with the outer
Build over the shared bin\ and obj\ paths. In practice the surface is
narrow because dotnet-aot is OutputType=Library + NativeLib=Shared
(no apphost, no exe-specific behaviors that differ between the two
evaluations) and the outer Build's outputs are idempotent across the
two evaluations, but the structural race remains.

If this race needs to be eliminated (and not just narrowed), the next step
is to add a ProjectReference from redist.csproj to dotnet-aot.csproj with
ReferenceOutputAssembly=false / SkipGetTargetFrameworkProperties=true so
the outer Build is guaranteed to complete before redist's GenerateSdkLayout
target runs.

Co-authored-by: Copilot <[email protected]>
Without this reference, the outer solution build's evaluation of
dotnet-aot.csproj and the PublishDotnetAot target's <MSBuild Targets="Publish">
call (a different BuildManager instance because of _IsPublishing=true) can
run concurrently and race over the shared bin\dotnet-aot\... and
obj\dotnet-aot\... directories.

The reference uses the same form already established in this file for
similar "sequence only, don't consume outputs" cases (dotnet-watch,
dotnet-format, NetAnalyzers): ReferenceOutputAssembly=false,
SkipGetTargetFrameworkProperties=true, Private=false.

Verified locally (sdk equivalent): build still succeeds, dotnet-aot
native library is produced and copied into the SDK layout, and the
binlog shows the outer Build evaluation of dotnet-aot.csproj completing
before redist's AfterBuild fires.

Co-authored-by: Copilot <[email protected]>
Copilot AI review requested due to automatic review settings May 13, 2026 13:24
@dotnet-policy-service
dotnet-policy-service Bot requested a review from a team May 13, 2026 13:24

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the SDK redist layout build to publish dotnet-aot in a way that more closely matches SDK “real publish” behavior, and adds an explicit build ordering constraint to avoid build/publish races for dotnet-aot.

Changes:

  • Pass _IsPublishing=true into the in-proc <MSBuild Targets="Publish;PublishItemsOutputGroup"> invocation used by PublishDotnetAot.
  • Add a ProjectReference from redist.csproj to dotnet-aot.csproj (non-output reference) to enforce ordering and reduce concurrent access to shared bin/obj outputs.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/sdk/src/Layout/redist/targets/GenerateLayout.targets Sets _IsPublishing=true on the dotnet-aot publish MSBuild call so Publish-gated SDK behaviors apply.
src/sdk/src/Layout/redist/redist.csproj Adds a non-output ProjectReference to dotnet-aot.csproj to sequence its build before redist layout generation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@ViktorHofer
ViktorHofer enabled auto-merge (squash) May 13, 2026 13:36
@ericstj

ericstj commented May 13, 2026 •

Copy link
Copy Markdown
Member

Does this project ever have a non-publishing mode? If it doesn't, can it just always have the publish property set? The risk for using global-properties like this is it can cause a rebuild if for any reason some target input changes - or you can get different results from build targets (intentional or not) that mean the output of build and publish differ. This can cause cases like shipping something different than test. In either case, if user's need to set this maybe it should be a public property - or we need a documented/designed way to do a publish via project-reference with minimal rebuild and no public properties. Best practice design for such systems would not need to replay any targets from build and would make all behavior differences in the added targets required for publish.

@ViktorHofer
ViktorHofer disabled auto-merge May 13, 2026 14:16
…ndition

The unconditional ProjectReference added in the previous commit pulled
dotnet-aot.csproj into the restore graph on every platform, including
source-build legs where PublishDotnetAot itself is condition-skipped (target
RID not in win/linux/osx prefix, e.g. centos.10-x64). On those legs, restoring
dotnet-aot demands the ILCompiler RID-specific runtime pack
(runtime.linux-x64.Microsoft.DotNet.ILCompiler) via ProcessFrameworkReferences
RID-graph fallback, but the source-built feeds only ship
runtime.centos.10-x64.Microsoft.DotNet.ILCompiler -- yielding NU1100 on
SB_CentOSStream10_Offline_CurrentSourceBuiltSdk_x64 in build 1419063.

Apply the same TargetRid prefix check to the ProjectReference as PublishDotnetAot's
own Condition. When we are not going to publish dotnet-aot, we have no race to
sequence and no reason to pull it into the restore graph.

Co-authored-by: Copilot <[email protected]>
@nagilson

Copy link
Copy Markdown
Member

If we set _IsPublishing then the build, restore and other commands/ actions on the project would have the publish specific settings also run (e.g. build would use publish trimmed) - it's a bit of a weird pattern. If we could block building the project then this could be interesting. I'd also see if @rainersigwald has ideas.

@dotnet-policy-service
dotnet-policy-service Bot requested a review from a team May 13, 2026 23:25
@dsplaisted

Copy link
Copy Markdown
Member Author

@ViktorHofer @nagilson @ericstj I had to make a fix so this needs another approval.

As far as setting _IsPublishing directly in the project, I think that would probably work. It might be something we should look into but I prefer not to do it here.

@ViktorHofer ViktorHofer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please log a follow-up issue to follow the pattern used in finalzer.csproj for publishing as part of the build.

Comment thread src/sdk/src/Layout/redist/redist.csproj Resolved
@dsplaisted

Copy link
Copy Markdown
Member Author

Please log a follow-up issue to follow the pattern used in finalzer.csproj for publishing as part of the build.

Thanks, I've filed dotnet/sdk#54324. Please take a look to verify I understood things correctly :-)

@dsplaisted
dsplaisted merged commit d998cae into dotnet:main May 15, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants