WPF Version Numbers
This post examines a couple of different ways that WPF version numbers can be stored and retrieved.
It's important to display the version of your WPF application somewhere in the user interface, but before you can display it, you need to know how to store and retrieve it. There are at least a couple of ways this can be accomplished and that's what we'll examine in this post.
The most straightforward and popular approach is simply to use the
Version property from the assembly's name. This can be set by right-clicking on the project and setting the Assembly version within the project's properties. In a .NET Framework app, this is found under the Application -> Assembly Information section of the project's properties, while in .NET Core, it can be found in the Package section of the project's properties.
Here's how you can read the value in code.
Sometimes you might want to describe your version as a string instead of a series of octets. For example, maybe your version is "2.0.0-alpha.3". If you want to describe your version in this way, then you won't be able to use the
Version property mentioned above because it limits you to four integer octets, like "220.127.116.11".
The AssemblyInformationalVersionAttribute can be used to specify a string with version info. This will display a warning if the string is not in the format that is used by the assembly's version number, or if the string contains wildcard characters, but the warning can be ignored.
If your application runs on the traditional .NET Framework, then you'll want to ensure that you have the attribute added to the AssemblyInfo.cs file.
If you're using .NET Core, the AssemblyInformationalVersionAttribute is automatically added and is based on the
<Version></Version> element in the csproj file.
If your application still explicitly defines an AssemblyInformationalVersionAttribute inside of your .NET Core project, then you'll get an error that states "Duplicate 'System.Reflection.AssemblyInformationalVersionAttribute' attribute". The easy way to resolve this is just to delete the attribute from your code (typically located in AssemblyInfo.cs) and just use the
<Version></Version> xml element inside of your csproj instead.