dotnet / dotnet/sdk

Properly annotate dotnet CLI MSBuild-OM build call sites for trimming (IL2026)

Open
#55,225 0 comments 0 reactions 1 assignee Claimed by @JeremyKuhne View on GitHub
untriaged
Dominant language
C#
Stars
3.2k
Forks
1.3k
PR merge metrics
PR metrics pending

Description

## Context

dotnet/msbuild#14064 ("Enable trim/AOT analyzers for Microsoft.Build and clean up annotations") adds `[RequiresUnreferencedCode]` to MSBuild's in-proc build-execution APIs — `BuildManager.BeginBuild`/`BuildRequest`, `Project.Build`, `ProjectInstance.Build`, and `BuildSubmission.Execute`/`ExecuteAsync`.

When that change flows into the VMR (dotnet/dotnet), `Microsoft.DotNet.Cli` — which sets `IsAotCompatible=true`, enabling the trim analyzer — fails to build with `IL2026` at every in-proc MSBuild build call site. This blocks the dotnet/msbuild → dotnet/dotnet codeflow (dotnet/dotnet#7636).

## Temporary mitigation

To unblock the codeflow, **temporary** method-level `[UnconditionalSuppressMessage("AOT", "IL2026", ...)]` attributes were added to the failing methods in dotnet/dotnet#7636 (in the VMR's `src/sdk` copy):

- `Commands/Run/VirtualProjectBuildingCommand.cs` → `Execute()` (already carried an `IL3050` suppression)
- `Commands/Run/RunCommandSelector.cs` → `TryComputeAvailableDevices(...)`
- `Commands/Run/RunCommandSelector.cs` → `TryDeployToDevice()`
- `Commands/Run/RunCommand.cs` → local function `InvokeRunArgumentsTarget` (in `GetTargetCommandForProject`)
- `Commands/Workload/Restore/WorkloadRestoreCommand.cs` → `RunTargetToGetWorkloadIds(...)`
- `Commands/Test/MTP/SolutionAndProjectUtility.cs` → local function `GetRunProperties` (in `GetModuleFromProject`)

## Follow-up (this issue)

Replace the temporary suppressions with a proper annotation strategy. The CLI already marks these paths with `[RequiresDynamicCode("Uses MSBuild Object Model types, which are not AOT-safe")]`; the natural fix is to mirror that boundary with a parallel `[RequiresUnreferencedCode("Uses MSBuild Object Model types, which are not AOT-safe")]` propagating to the command entry points, or otherwise refactor so the trimming requirement is expressed rather than suppressed.

Once this is done, remove the `IL2026` `UnconditionalSuppressMessage` attributes added by dotnet/dotnet#7636.

Related: dotnet/msbuild#14064, dotnet/dotnet#7636

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.