1

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?

Jeagr
  • 1,038
  • 6
  • 16
  • 30
  • Just reading more carefully, I think this is basically a duplicate of http://stackoverflow.com/questions/826777/how-to-have-an-auto-incrementing-version-number-visual-studio. – Alvin Wong Jan 31 '13 at 01:30

1 Answers1

6

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.

Brad Christie
  • 100,477
  • 16
  • 156
  • 200
  • 1
    Just note that you need to import `System.Reflection`. – Alvin Wong Jan 31 '13 at 01:27
  • 2
    Say you had `[assembly: AssemblyVersion("1.0.*.*")]` VS will auto-increment the build and revision for you. – Brad Christie Jan 31 '13 at 01:28
  • 2
    See http://stackoverflow.com/questions/826777/how-to-have-an-auto-incrementing-version-number-visual-studio – Alvin Wong Jan 31 '13 at 01:28
  • Basically, if you even tried to add an `About Box` you can see this code used to get the version to be displayed in it. – Alvin Wong Jan 31 '13 at 01:29
  • 1
    @Jeagr: Did you figure it out? – Brad Christie Jan 31 '13 at 01:50
  • No....but I am not familiar with adding in things like [assembly: AssemblyVersion("1.0.*.*")]... somewhat of a nub. – Jeagr Jan 31 '13 at 01:58
  • 1
    @Jeagr: Shouldn't have to add it. within visual studio, under your project, is a Properties node (above References node). inside is `AssemblyInfo.cs` which is where that line is. Make the last or last two values `*` and the version will change with each build. – Brad Christie Jan 31 '13 at 02:02
  • ok..getting this: Error 1 Error emitting 'System.Reflection.AssemblyVersionAttribute' attribute -- 'The version specified '1.0.*.*' is invalid' I:\___VS Projects\Keyworqs WPF\test1\Properties\AssemblyInfo.cs 35 12 KeyworqsWPF – Jeagr Jan 31 '13 at 02:10
  • Figured it out...it was a syntax error. This worked: [assembly: AssemblyVersion("1.0.*")] – Jeagr Jan 31 '13 at 03:04