Skip to content

Get version at runtime #807

Answered by adamralph
lonix1 asked this question in Q&A
Sep 8, 2022 · 1 comments · 1 reply
Discussion options

You must be logged in to vote

The README states that AssemblyVersion is set to {MinVerMajor}.0.0.0, so if you are in the 0.x version range, AssemblyVersion will be 0.0.0.0.

The Version .NET SDK property, however, is propagated to AssemblyInformationalVersion, so you can use that. For example:

public static string GetVersion(this Assembly assembly) =>
    assembly.GetCustomAttributes(false).OfType<AssemblyInformationalVersionAttribute>().FirstOrDefault()
        ?.InformationalVersion ?? "Unknown";

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@lonix1
Comment options

Answer selected by lonix1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants