Reputation: 2539
How can I insert the assembly version number (which I set to auto increment) into a Winform form text?
Upvotes: 66
Views: 63135
Reputation: 188
To include application name and version the following one liner will do it:
Text = $"{Application.ProductName} {Application.ProductVersion}";
Upvotes: 0
Reputation: 9936
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
Upvotes: 102
Reputation: 9119
Text = Application.ProductVersion
Quick way to get the full version as a string (e.g. "1.2.3.4")
Upvotes: 25
Reputation: 2930
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.*")]
Upvotes: 12
Reputation: 12779
its in the System.Reflection.AssemblyName
class eg.
Assembly.GetExecutingAssembly().GetName().Version.ToString()
Upvotes: 3
Reputation: 745
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
System.Diagnostics.FileVersionInfo fvi = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location);
return fvi.ProductVersion;
Upvotes: 1
Reputation: 44605
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);
}
}
Upvotes: 2