-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Ensure that Trimming and AOT scenarios trigger downloading of necessary runtime packs #51765
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Ensure that Trimming and AOT scenarios trigger downloading of necessary runtime packs #51765
Conversation
…also bring in the runtime packs when targeting a single RID. This fixes a gap where 'dotnet restore' for a RID followed by 'dotnet publish --no-restore' for that RID in trimming/AOT scenarios wouldn't work.
| <ItemGroup> | ||
| <ProjectCapability Remove="TestContainer" /> | ||
| </ItemGroup> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, this is a bugfix from the DevKit folks (thanks @peterwald!) that unblocks the DevKit test explorer experience.
Because this project references xunit (thanks Arcade!) the xunit package adds this capability. Because the project has this capability, DevKit tries to load it as a test. Because this project is a library and doesn't have all of the test dependencies, it fails to load and crashes the test-discovery process.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request fixes a gap in runtime pack resolution where projects using PublishTrimmed or PublishAot without SelfContained=true would fail during publish with --no-restore because required runtime packs weren't downloaded during restore.
Key Changes:
- Introduced
DeploymentModelRequiresRuntimeComponentsproperty that consolidates logic for determining when runtime packs are needed, now includingRequiresILLinkPack(set when trimming is enabled) alongsideSelfContained,ReadyToRunEnabled, andPublishAot - Refactored
KnownRuntimePackstruct to use C# 12 primary constructor and readonly properties for better maintainability - Added comprehensive unit tests covering various publish scenarios including trimming and AOT without self-contained deployment
- Created documentation specification detailing expected behavior of
ProcessFrameworkReferencestask across different deployment scenarios
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs | Core fix to runtime pack resolution logic; refactored struct to use modern C# features; introduced constants and helper properties for better code clarity |
| src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/ProcessFrameworkReferencesTests.cs | Added comprehensive test coverage for PublishTrimmed, PublishAot, and ReadyToRun scenarios with and without SelfContained; added support for ReadyToRunEnabled in test configuration |
| documentation/specs/ProcessFrameworkReferences-outputs.md | New specification document describing expected outputs for different deployment scenarios and documenting the fix for issue #51667 |
| test/Microsoft.NET.TestFramework/Microsoft.NET.TestFramework.csproj | Removed TestContainer project capability to prevent VS from treating the framework project as a test container |
| tasks.slnf | New solution filter for convenient development focused on build tasks projects |
src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
| /// <summary> | ||
| /// We have several deployment models that require the use of runtime assets of various kinds. | ||
| /// This member helps identify when any of those models are in use, because we've had bugs in the past | ||
| /// where we didn't properly account for all of them. | ||
| /// </summary> | ||
| private bool DeploymentModelRequiresRuntimeComponents => | ||
| SelfContained || ReadyToRunEnabled || PublishAot || RequiresILLinkPack; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This member is the actual fix. Every other change is tests, infra, debugging utility, clarity, etc.
|
Nit: per #51766 (comment) |
| <SelfContained>true</SelfContained> | ||
| <RuntimeIdentifier>linux-x64</RuntimeIdentifier> | ||
| <ReadyToRunEnabled>true</ReadyToRunEnabled> | ||
| <ReadyToRunUseCrossgen2>true</ReadyToRunUseCrossgen2> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a minimum runtime pack version that the current .NET SDK is compatible with? Does the current .NET SDK still support publishing for .NET 5 in all flavors?
UseCrossgen2 property was a thing in .NET 5 where crossgen2 was in preview and setting this property to true was used to opt-in into the preview. It has no purpose (it is always true) in .NET 6+.

Fixes dotnet/runtime#51667
There was a gap when restoring a project for a RID and then publishing it for that same RID with
--no-restorewhere if that project only set PublishTrimmed or PublishAOT, the runtime packs for that RID would not be restored. This would lead to the publish command failing saying that required runtime packs weren't available. There were a couple workarounds:Along the way I added some tests to cover the new scenarios, and extracted out a documentation spec to capture how we think ProcessFrameworkReferences should behave, modulo any bugs. In the future we should be able to reference this when answering questions about what the expected behavior is.
I also made a
tasks.slnfto make it easier to iterate on the SDK's MSBuild Tasks and their tests in isolation. This massively helps the VSCode user experiences, especially on the testing inner loop.