-
Notifications
You must be signed in to change notification settings - Fork 247
Fix: Exception for Blazor WebAssembly using FileVersionInfo #820
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
Changes from 2 commits
ca3826f
a7d9644
7e4d052
c65a6ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -254,12 +254,21 @@ public static class LibraryMetadata | |
|
|
||
| private static string GetAssemblyVersion() | ||
| { | ||
| string? version; | ||
| var assembly = typeof(LibraryMetadata).Assembly; | ||
| var fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location); | ||
|
|
||
| // Prefer the file version, but fall back to the assembly version if it's not available. | ||
| return fileVersionInfo.FileVersion | ||
| ?? assembly.GetName().Version?.ToString() // will only change for major versions | ||
| ?? "1.0.0.0"; | ||
| try | ||
| { | ||
| var fileVersionInfo = FileVersionInfo.GetVersionInfo(assembly.Location); | ||
| version = fileVersionInfo.FileVersion; | ||
| } | ||
| catch (Exception) | ||
| { | ||
| version = assembly.GetName().Version?.ToString(); | ||
| } | ||
|
|
||
| return version ?? "2.0"; | ||
|
||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| <AssemblyOriginatorKeyFile>..\IcalNetStrongnameKey.snk</AssemblyOriginatorKeyFile> | ||
| <nullable>enable</nullable> | ||
| <LangVersion>latest</LangVersion> | ||
| <AssemblyVersion>2.0</AssemblyVersion> | ||
|
||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <PackageReference Include="NodaTime" Version="3.2.2" /> | ||
|
|
||
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.
The code introduced in this GitHub comment doesn't work for WebAssembly? The advantage was that we wouldn't need the try/catch. In both cases, caching the value would be advantageous.
Uh oh!
There was an error while loading. Please reload this page.
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.
Sorry, was too fast with my fix. Working indeed, so you can throw away the pull request and replace with the suggested code.