Enable AOT compatibility analyzers and fix issues#52865
Draft
JeremyKuhne wants to merge 2 commits intodotnet:mainfrom
Draft
Enable AOT compatibility analyzers and fix issues#52865JeremyKuhne wants to merge 2 commits intodotnet:mainfrom
JeremyKuhne wants to merge 2 commits intodotnet:mainfrom
Conversation
Member
Author
|
Still in draft; checking test results and working through a few issues. |
Member
|
/azp run sdk-unified-build |
|
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`).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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-generatedJsonSerializerContexttypes throughout workload, tool list, SDK check, template, and manifest commands. This eliminates reliance on reflection-basedDefaultJsonTypeInfoResolver.Replace
Assembly.GetExecutingAssembly().LocationwithAppContext.BaseDirectoryorEnvironment.ProcessPathinVBCSCompilerServer,InstallerBase,InstallClientElevationContext,SignCheck, andToolPackageDownloaderBase, sinceAssembly.Locationreturns empty in single-file/AOT deployments.Replace
XmlSerializerwith manual XML parsing: UseXDocument/XmlReaderinToolConfigurationDeserializerandWorkloadUnixFilePermissionsFileListto avoid runtime code generation.AOT-compatible logging registration: Change
CliTemplateEngineHostto useServices.TryAddEnumerableinstead of the genericAddConsoleFormatter<T>overload that relies onMakeGenericType.Enable AOT compatibility analyzers: Add
<IsAotCompatible>true</IsAotCompatible>todotnet.csproj,Microsoft.DotNet.Configurer,Microsoft.DotNet.InternalAbstractions,Microsoft.TemplateEngine.Cli,Microsoft.DotNet.ProjectTools,Microsoft.DotNet.TemplateLocator,Microsoft.Win32.Msi, andMicrosoft.DotNet.SdkResolverproject files.Suppress IL3000 warnings with
#pragmain locations whereAssembly.Locationis unavoidable (MSBuildForwardingApp,BuiltInTemplatePackageProvider,OptionalWorkloadProvider).