Skip to content

Enable AOT compatibility analyzers and fix issues#52865

Draft
JeremyKuhne wants to merge 2 commits intodotnet:mainfrom
JeremyKuhne:aotcli
Draft

Enable AOT compatibility analyzers and fix issues#52865
JeremyKuhne wants to merge 2 commits intodotnet:mainfrom
JeremyKuhne:aotcli

Conversation

@JeremyKuhne
Copy link
Member

Replace reflection-based patterns with AOT-compatible alternatives across the CLI codebase:

  • Source-generated JSON serialization: Replace JsonSerializer.Serialize<T>/Deserialize<T> calls with source-generated JsonSerializerContext types throughout workload, tool list, SDK check, template, and manifest commands. This eliminates reliance on reflection-based DefaultJsonTypeInfoResolver.

  • Replace Assembly.GetExecutingAssembly().Location with AppContext.BaseDirectory or Environment.ProcessPath in VBCSCompilerServer, InstallerBase, InstallClientElevationContext, SignCheck, and ToolPackageDownloaderBase, since Assembly.Location returns empty in single-file/AOT deployments.

  • Replace XmlSerializer with manual XML parsing: Use XDocument/XmlReader in ToolConfigurationDeserializer and WorkloadUnixFilePermissionsFileList to avoid runtime code generation.

  • AOT-compatible logging registration: Change CliTemplateEngineHost to use Services.TryAddEnumerable instead of the generic AddConsoleFormatter<T> overload that relies on MakeGenericType.

  • Enable AOT compatibility analyzers: Add <IsAotCompatible>true</IsAotCompatible> to dotnet.csproj, Microsoft.DotNet.Configurer, Microsoft.DotNet.InternalAbstractions, Microsoft.TemplateEngine.Cli, Microsoft.DotNet.ProjectTools, Microsoft.DotNet.TemplateLocator, Microsoft.Win32.Msi, and Microsoft.DotNet.SdkResolver project files.

  • Suppress IL3000 warnings with #pragma in locations where Assembly.Location is unavoidable (MSBuildForwardingApp, BuiltInTemplatePackageProvider, OptionalWorkloadProvider).

@JeremyKuhne
Copy link
Member Author

Still in draft; checking test results and working through a few issues.

@NikolaMilosavljevic
Copy link
Member

/azp run sdk-unified-build

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

…ross the CLI codebase:

- **Source-generated JSON serialization**: Replace `JsonSerializer.Serialize<T>`/`Deserialize<T>` calls with source-generated `JsonSerializerContext` types throughout workload, tool list, SDK check, template, and manifest commands. This eliminates reliance on reflection-based `DefaultJsonTypeInfoResolver`.

- **Replace `Assembly.GetExecutingAssembly().Location`** with `AppContext.BaseDirectory` or `Environment.ProcessPath` in `VBCSCompilerServer`, `InstallerBase`, `InstallClientElevationContext`, `SignCheck`, and `ToolPackageDownloaderBase`, since `Assembly.Location` returns empty in single-file/AOT deployments.

- **Replace `XmlSerializer` with manual XML parsing**: Use `XDocument`/`XmlReader` in `ToolConfigurationDeserializer` and `WorkloadUnixFilePermissionsFileList` to avoid runtime code generation.

- **AOT-compatible logging registration**: Change `CliTemplateEngineHost` to use `Services.TryAddEnumerable` instead of the generic `AddConsoleFormatter<T>` overload that relies on `MakeGenericType`.

- **Enable AOT compatibility analyzers**: Add `<IsAotCompatible>true</IsAotCompatible>` to `dotnet.csproj`, `Microsoft.DotNet.Configurer`, `Microsoft.DotNet.InternalAbstractions`, `Microsoft.TemplateEngine.Cli`, `Microsoft.DotNet.ProjectTools`, `Microsoft.DotNet.TemplateLocator`, `Microsoft.Win32.Msi`, and `Microsoft.DotNet.SdkResolver` project files.

- **Suppress IL3000 warnings** with `#pragma` in locations where `Assembly.Location` is unavoidable (`MSBuildForwardingApp`, `BuiltInTemplatePackageProvider`, `OptionalWorkloadProvider`).
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.

2 participants