Version number in Winform form text
How can I insert the assembly version number (which I set to auto increment) into a Winform form text?
Either of these will work:
var version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
this.Text = String.Format("My Application Version {0}", version);
string version = System.Windows.Forms.Application.ProductVersion;
this.Text = String.Format("My Application Version {0}", version);
Assuming this is run on the Form
you wish to display the text on
Text = Application.ProductVersion
Quick way to get the full version as a string (e.g. "1.2.3.4")
I'm using the following in a WinForm:
public MainForm()
{
InitializeComponent();
Version version = Assembly.GetExecutingAssembly().GetName().Version;
Text = Text + " " + version.Major + "." + version.Minor + " (build " + version.Build + ")"; //change form title
}
Not showing revision number to the user, build number is enough technical info
Make sure your AssemblyInfo.cs ends in the following (remove the version it has there by default) for VisualStudio to autoincrement build and revision number. You have to update major and minor versions yourself at every release (update major version for new features, minor version when you do just fixes):
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.*")]