Jeagr
Jeagr

Reputation: 1058

Auto-Include Version # in Label

I am currently including the version number of my publish/release in a label on my application, but have been unable to figure out how to add it so that it auto-updates for every publish. Currently, I am just using a simple text:

//VERSION LABEL
string version = "1.0.0.15 - BETA";
versionLabel.Text = "v" + version;

Is there a way to auto-update the version with each publish?

Upvotes: 1

Views: 3540

Answers (1)

Brad Christie
Brad Christie

Reputation: 101604

How about using the assembly version? Depending if you let it auto-uprev, this could save you some time.

var appVersion = Assembly.GetExecutingAssembly().GetName().Version;
versionLabel.Text = String.Format("v{0}", appVersion);

This would be based on the AssemblyInfo's version.

To elaborate on what I mean, if you look at AssemblyInfo.cs, you'll see something like the following:

// 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 Revision and Build Numbers 
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]

That's essentially saying that if you make it 1.0.* or 1.0.0.* that VS will assign a revision or build and revision, respectfully, for you with every compilation.

Upvotes: 6

Related Questions