Skip to content

Restore validation, cleanup, and tool shims for optimized Native AOT publish - #56650

Merged
marcpopMSFT merged 5 commits into
dotnet:release/11.0.1xxfrom
marcpopMSFT:marcpopmsft-aot-publish-contract-gaps
Oct 20, 2026
Merged

marcpopMSFT merged 5 commits into
dotnet:release/11.0.1xxfrom
marcpopMSFT:marcpopmsft-aot-publish-contract-gaps

Conversation

@marcpopMSFT

@marcpopMSFT marcpopMSFT commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

🤖 Restore three build contracts skipped by optimized Native AOT publishing, in three separate commits.

Changes

  • Run _CheckForInvalidConfigurationAndPlatform before the optimized build prerequisites, restoring hooked SDK validations such as the runtime identifier/platform mismatch diagnostic (NETSDK1032).
  • Wrap optimized build prerequisites and SDK extensions in _BuildForOptimizedPublish, run IncrementalClean before publish post-processing, and use _CleanRecordFileWrites on build failure. This restores intermediate DLL/PDB/XML/generated-file cleanup and removes obsolete tracked managed outputs after a prior full build without restoring managed build copies. This does not add cleanup tracking for every native or publish artifact.
  • Extend the optimized build pipeline from PackTool with GenerateShimsAssets only when explicit tool shim runtime identifiers are requested, before cleanup and publish file collection. Preserve existing full-build and NoBuild shim behavior.

Each commit includes regression coverage and updates to documentation/general/publish-build-optimization.md.

Validation

  • Built the SDK redist, refreshed it after the target changes, and verified the deployed Publish/PackTool target hashes match the source.
  • Passed 15 focused Microsoft.NET.Publish.Tests cases: platform validation, successful and repeated publish cleanup, prior full build followed by optimized publish, failure before/after compilation followed by clean, optimized/full/no-build tool shims, no requested shims, managed tool shim compatibility, optimized output layout, the CoreBuild dependency guard, and unsupported optimized publish modes.
  • Passed 7 Microsoft.NET.ILLink.Tests smoke cases selected from the configured ILLink scope.
  • Independently reproduced all three regressions using unchanged target overlays with the installed 11.0 RC1 SDK, then verified the fixes using real Native AOT compilation and retained per-invocation binlogs.
  • Targeted test TRX files and build binlogs are retained under artifacts/log/targeted-tests/. Validation was on Windows x64; Linux/macOS were not run locally. The full SDK build succeeded with existing NU1902/NU1903 audit warnings for System.Security.Cryptography.Pkcs 8.0.1 in ApiCompat projects; those dependencies were not changed or suppressed by this PR.

Scope and related fixes

Targets release/11.0.1xx from its provisioned baseline. This PR neither modifies nor includes the XML documentation repair in #56620 (for #56618), or the build-hook ordering repair in #56649 (for #56645). XML cleanup coverage disables publishing documentation so it tests compiler-output tracking independently of #56620. NoBuild remains a separate publish path.


Tactics

Summary

Optimized Native AOT publish skipped the full build pipeline and so lost three build contracts: SDK configuration/platform validation (e.g. NETSDK1032), intermediate-output cleanup bookkeeping (IncrementalClean), and tool shim generation. This PR runs _CheckForInvalidConfigurationAndPlatform first, wraps the optimized prerequisites in _BuildForOptimizedPublish with IncrementalClean/_CleanRecordFileWrites, and adds GenerateShimsAssets to the PackTool optimized pipeline only when explicit shim RIDs are requested. Changes are confined to Publish/PackTool targets, restoring previously expected behavior, which suits servicing.

Customer Impact

Customers using optimized Native AOT publish on the 11.0 SDK (RC1 verified) can see missing validation errors (e.g. RID/platform mismatch no longer reported), stale intermediate or obsolete managed outputs after a prior full build, and missing packaged tool shims when shim runtime identifiers are requested. This affects specific scenarios (AOT publish, AOT tools with shims), not all users. No workaround is documented in the PR.

Regression?

Yes. The behavior was lost by the optimized publish build pipeline in the 11.0 SDK (reproduced with the installed 11.0 RC1 SDK). The specific introducing PR is not identified in the PR context.

Testing

  • New/updated unit tests in GivenThatWeWantToPublishAnAotApp.cs and GivenThatWeWantToPublishAToolProjectWithPackagedShim.cs, one set per commit.
  • Author-reported local runs (Windows x64): 15 focused Publish tests (later 13 Publish, 12 tool-pack cases after review changes), and 7 ILLink smoke tests, all passing; all three regressions reproduced before the fix using real Native AOT compilation and binlogs.
  • Linux/macOS not run locally; CI pipelines were started.
  • Review feedback on shim path alignment was addressed (shared staging directory) with added tests. The XML-docs finding is deferred to Publish XML documentation during optimized Native AOT builds #56620.

Risk

Low–Medium. About 240 lines changed, mostly tests and docs; target changes are ~19 lines across two shared targets files. The cleanup change touches shared incremental-clean behavior and shim staging paths, which carry some edge-case risk, but they apply only to the optimized publish path and are covered by focused tests.

marcpopMSFT and others added 3 commits October 14, 2026 17:05
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 15, 2026 00:17
@marcpopMSFT
marcpopMSFT requested review from a team as code owners October 15, 2026 00:17
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).
1 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

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.

🔵 Needs a closer look

Shared cleanup changes have unresolved XML and shim compatibility issues and require human review.

2 open findings
What changed in this PR

Restores validation, cleanup bookkeeping, and explicitly requested tool shims in the SDK’s optimized Native AOT publish pipeline.

Changes:

  • Runs configuration validation before optimized build prerequisites.
  • Records generated files and cleans obsolete tracked outputs.
  • Adds shim generation, regression tests, and documentation.
File Description
test/​Microsoft.NET.Publish.Tests/​GivenThatWeWantToPublishAToolProjectWithPackagedShim.cs Tests tool shim publishing modes.
test/​Microsoft.NET.Publish.Tests/​GivenThatWeWantToPublishAnAotApp.cs Tests validation and cleanup scenarios.
src/​Tasks/​Microsoft.NET.Build.Tasks/​targets/​Microsoft.NET.Publish.targets Restores validation and cleanup bookkeeping.
src/​Tasks/​Microsoft.NET.Build.Tasks/​targets/​Microsoft.NET.PackTool.targets Registers optimized shim generation.
documentation/​general/​publish-build-optimization.md Documents restored build contracts.

🧠 Review effort: Balanced

Use one framework-based shim directory independent of inferred SelfContained, and include it in the generation cache. Cover optimized/full publish to NoBuild, build to optimized publish, custom staging roots, and self-contained managed tools.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@marcpopMSFT

Copy link
Copy Markdown
Member Author

/tactics

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 091747d8-06d9-4830-a9b2-aa50cb71eaa4
@marcpopMSFT
marcpopMSFT enabled auto-merge October 19, 2026 18:23
@marcpopMSFT
marcpopMSFT merged commit d64640a into dotnet:release/11.0.1xx Oct 20, 2026
23 checks passed

This branch had an error being deployed

1 failed deployment
copilot-pat-pool — 676623e4 Deployed Oct 20, 2026 by marcpopMSFT via pre_activation #9731
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants