Repository navigation
Set _IsPublishing=true and add ProjectReference for PublishDotnetAot - #6590
Conversation
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]>
There was a problem hiding this comment.
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=trueinto the in-proc<MSBuild Targets="Publish;PublishItemsOutputGroup">invocation used byPublishDotnetAot. - Add a
ProjectReferencefromredist.csprojtodotnet-aot.csproj(non-output reference) to enforce ordering and reduce concurrent access to sharedbin/objoutputs.
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.
|
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. |
…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]>
|
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. |
|
@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
left a comment
There was a problem hiding this comment.
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 :-) |
Summary
Follow-up to #6576. Two related changes to
PublishDotnetAotinsrc/sdk/src/Layout/redist/:Pass
_IsPublishing=trueas a global property to the<MSBuild Targets="Publish">call ondotnet-aot.csproj. Per @MichalStrehovsky's feedback on Use MSBuild task instead of Exec for PublishDotnetAot #6576, running the Publish target without_IsPublishing=truehas been a source of subtle issues — it's the property the SDK uses to gate Publish-aware behaviors (suppressing apphost generation whenPublishAot=true, severalNETSdkErrorconditions,_RuntimeIdentifierUsesAppHostadjustments, etc.).Add a
ProjectReferencefromredist.csprojtodotnet-aot.csproj(ReferenceOutputAssembly=false,SkipGetTargetFrameworkProperties=true,Private=false). This sequences the outer solution build's evaluation ofdotnet-aot.csprojto complete before redist'sGenerateSdkLayouttarget runs, eliminating the race surface re-introduced by change (1).cc @ericstj @MichalStrehovsky @NikolaMilosavljevic