Last active
June 12, 2025 18:25
-
-
Save wchesley/f1d3e8174a68ec6b35a810814949f42c to your computer and use it in GitHub Desktop.
Get App Version as String
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
| // File: AppVersion.cs | |
| // Author: Walker Chesley | |
| using System.Reflection; | |
| /// <summary> | |
| /// Get the application version from the assembly for Major, Minor, and Build. | |
| /// </summary> | |
| /// <returns>Current application version as string with 'v' prepended to it. ie. "v1.2.3"</returns> | |
| /// <remarks>If no version is set, defaults to 'v0.0.0'</remarks> | |
| public static class AppVersion | |
| { | |
| /// <summary> | |
| /// Application Version string. | |
| /// </summary> | |
| /// <value>v0.15.456</value> | |
| private static Lazy<string> _version = new Lazy<string>(() => | |
| { | |
| var version = Assembly.GetEntryAssembly()?.GetName().Version; | |
| if (version is null) | |
| { | |
| return "v0.0.0"; | |
| } | |
| return $"v{version.Major}.{version.Minor}.{version.Build}"; | |
| }); | |
| /// <summary> | |
| /// Public property to get the application version. | |
| /// </summary> | |
| public static string Version => _version.Value; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment