-
Notifications
You must be signed in to change notification settings - Fork 7.5k
[AOT] Update logger to support NativeAOT #40154
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
moooyo
left a comment
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.
LGTM
|
Anyone have any concern? |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
…ilzh/loggeraot
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
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 updates the logger implementation to support NativeAOT by replacing FileVersionInfo.GetVersionInfo(Assembly.Location) with a static reflection approach using GetCustomAttribute<AssemblyFileVersionAttribute>()?.Version.
- Removes NativeAOT-incompatible file system access for version information
- Replaces FileVersionInfo usage with assembly attribute reflection
- Eliminates the need for pragma warnings related to single-file publishing
| #pragma warning disable IL3000 // Avoid accessing Assembly file path when publishing as a single file | ||
| private static readonly string Version = FileVersionInfo.GetVersionInfo(Assembly.Location).ProductVersion; | ||
| #pragma warning restore IL3000 // Avoid accessing Assembly file path when publishing as a single file | ||
| private static readonly string Version = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyFileVersionAttribute>()?.Version ?? "Unknown"; |
Copilot
AI
Aug 5, 2025
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.
[nitpick] The fallback value "Unknown" may not provide sufficient information for debugging purposes. Consider using a more descriptive fallback like "Version not available" or including additional context about why the version could not be determined.
| private static readonly string Version = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyFileVersionAttribute>()?.Version ?? "Unknown"; | |
| private static readonly string Version = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyFileVersionAttribute>()?.Version ?? "Version not available"; |
Summary of the Pull Request
Root cause:
FileVersionInfo.GetVersionInfo(Assembly.Location)is not compatible with NativeAOTFix:
Replaced the usage of FileVersionInfo with static reflection
GetCustomAttribute<AssemblyFileVersionAttribute>()?.Version. This uses static reflection to read version metadata directly from the assembly, which is fully supported in NativeAOT. It does not require file system access and is trimming/AOT-safe.PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed