Version number in Winform form text

C#WinformsVisual Studio

C# Problem Overview


How can I insert the assembly version number (which I set to auto increment) into a Winform form text?

C# Solutions


Solution 1 - C#

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

Solution 2 - C#

Text = Application.ProductVersion

Quick way to get the full version as a string (e.g. "1.2.3.4")

Solution 3 - C#

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.*")]

Solution 4 - C#

its in the System.Reflection.AssemblyName class eg.

Assembly.GetExecutingAssembly().GetName().Version.ToString()

Solution 5 - C#

as you can see here: http://msdn.microsoft.com/en-us/library/system.reflection.assemblyname.version.aspx

class Example
{
    static void Main()
    {
        Console.WriteLine("The version of the currently executing assembly is: {0}",
            Assembly.GetExecutingAssembly().GetName().Version);

        Console.WriteLine("The version of mscorlib.dll is: {0}",
            typeof(String).Assembly.GetName().Version);
    }
}

Solution 6 - C#

System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
System.Diagnostics.FileVersionInfo fvi = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location);
return fvi.ProductVersion;

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionAndrewView Question on Stackoverflow
Solution 1 - C#Iain WardView Answer on Stackoverflow
Solution 2 - C#bytedevView Answer on Stackoverflow
Solution 3 - C#George BirbilisView Answer on Stackoverflow
Solution 4 - C#HathView Answer on Stackoverflow
Solution 5 - C#Davide PirasView Answer on Stackoverflow
Solution 6 - C#VismariView Answer on Stackoverflow