-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Add trim/aot analyzer warnings for transitive references #118180
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
Conversation
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 PR introduces new analyzer warnings to detect when assemblies referenced by a project are not marked as trim or AOT compatible. The warnings are opt-in via the VerifyReferenceTrimCompatibility
and VerifyReferenceAotCompatibility
MSBuild properties, helping developers identify potentially problematic dependencies during trimming or AOT compilation scenarios.
Key changes:
- Adds two new diagnostic IDs for trim and AOT compatibility warnings
- Extends the existing trim and AOT analyzers to check referenced assemblies for compatibility metadata
- Provides comprehensive test coverage for the new functionality
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
ReferenceTrimCompatibilityTests.cs |
Test cases for the new trim compatibility analyzer warnings |
ReferenceCompatibilityTestUtils.cs |
Utility class to create test scenarios with external assembly references |
ReferenceAotCompatibilityTests.cs |
Test cases for the new AOT compatibility analyzer warnings |
ILLink.RoslynAnalyzer.Tests.csproj |
Simplifies reference assembly copying for tests |
SharedStrings.resx |
Adds resource strings for the new diagnostic messages |
DiagnosticId.cs |
Defines new diagnostic IDs for trim and AOT compatibility warnings |
Microsoft.NET.ILLink.Analyzers.props |
Exposes the new MSBuild properties to the compiler |
RequiresUnreferencedCodeAnalyzer.cs |
Implements trim compatibility checking for referenced assemblies |
RequiresDynamicCodeAnalyzer.cs |
Implements AOT compatibility checking for referenced assemblies |
RequiresAnalyzerBase.cs |
Adds infrastructure to support compilation-level analysis actions |
MSBuildPropertyOptionNames.cs |
Defines constants for the new MSBuild property names |
Comments suppressed due to low confidence (2)
src/tools/illink/src/ILLink.RoslynAnalyzer/RequiresUnreferencedCodeAnalyzer.cs:67
- The variable name 'isTrimmable' is misleading as it stores the attribute object, not a boolean value. Consider renaming it to 'trimCompatibilityAttribute' or 'isTrimmableAttribute'.
var isTrimmable = refAssembly.GetAttributes().FirstOrDefault(attr =>
src/tools/illink/src/ILLink.RoslynAnalyzer/RequiresDynamicCodeAnalyzer.cs:46
- The variable name 'isAotCompatible' is misleading as it stores the attribute object, not a boolean value. Consider renaming it to 'aotCompatibilityAttribute' or 'isAotCompatibleAttribute'.
var isAotCompatible = refAssembly.GetAttributes().FirstOrDefault(attr =>
src/tools/illink/src/ILLink.RoslynAnalyzer/RequiresUnreferencedCodeAnalyzer.cs
Outdated
Show resolved
Hide resolved
The IsAotCompatible opt-out was accidentally added back after being intentionally removed due to a bad merge.
@ViktorHofer @dotnet/illink I've changed the analyzer tests to run against a live ref pack (the one we just built) to get the latest IsTrimmable/IsAotCompatible metadata. This means the dotnet-linker-tests pipeline will need to build libs before running analyzer tests. Any concerns with this? |
No concerns with that. You can build just the |
- Don't mention attribute in messages - Build libs.sfx instead of libs
Context: dotnet/runtime#118180 The new warnings are opt-in under the following settings: * `<VerifyReferenceTrimCompatibility>true</VerifyReferenceTrimCompatibility>` * `<VerifyReferenceAotCompatibility>true</VerifyReferenceAotCompatibility>`
Context: dotnet/runtime#118180 The new warnings are opt-in under the following settings: * `<VerifyReferenceTrimCompatibility>true</VerifyReferenceTrimCompatibility>` * `<VerifyReferenceAotCompatibility>true</VerifyReferenceAotCompatibility>`
Adds new analyzer warnings for references to assemblies not marked as trim or aot compatible.
The new warnings are opt-in under the following settings:
<VerifyReferenceTrimCompatibility>true</VerifyReferenceTrimCompatibility>
<VerifyReferenceAotCompatibility>true</VerifyReferenceAotCompatibility>
The analyzer uses AssemblyMetadataAttribute in the referenced assemblies to detect whether they are marked as trim/aot compatible. To mark a project as trim/aot compatible, it should be built with the usual recommended property settings:
<IsTrimmable>true</IsTrimmable>
adds[assembly: AssemblyMetadata("IsTrimmable", "True")]
<IsAotCompatible>true</IsAotCompatible>
adds[assembly: AssemblyMetadata("IsAotCompatible", "True")
Fixes #117712