Skip to content

Commit 73841f6

Browse files
authored
[AOT] Update logger to support NativeAOT (#40154)
<!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request ### Root cause: `FileVersionInfo.GetVersionInfo(Assembly.Location)` is not compatible with NativeAOT ### Fix: 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. <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist - [x] **Closes:** [#40151](#40151) - [ ] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [ ] **Tests:** Added/updated and all pass - [ ] **Localization:** All end-user-facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx <!-- Provide a more detailed description of the PR, other things fixed, or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed
1 parent a9f7c3b commit 73841f6

File tree

1 file changed

+1
-10
lines changed

1 file changed

+1
-10
lines changed

src/common/ManagedCommon/Logger.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,7 @@ public static class Logger
2222
private static readonly string Debug = "Debug";
2323
private static readonly string TraceFlag = "Trace";
2424

25-
private static readonly Assembly Assembly = Assembly.GetExecutingAssembly();
26-
27-
/*
28-
* Please pay more attention!
29-
* If you want to publish it with Native AOT enabled (or publish as a single file).
30-
* You need to find another way to remove Assembly.Location usage.
31-
*/
32-
#pragma warning disable IL3000 // Avoid accessing Assembly file path when publishing as a single file
33-
private static readonly string Version = FileVersionInfo.GetVersionInfo(Assembly.Location).ProductVersion;
34-
#pragma warning restore IL3000 // Avoid accessing Assembly file path when publishing as a single file
25+
private static readonly string Version = Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyFileVersionAttribute>()?.Version ?? "Unknown";
3526

3627
/// <summary>
3728
/// Initializes the logger and sets the path for logging.

0 commit comments

Comments
 (0)