Asad Iqbal
Asad Iqbal

Reputation: 304

Application.ProductVersion is not working

Application.ProductVersion is not showing the incremental version. can anybody help me how to perform this, using C# ?

Upvotes: 0

Views: 9109

Answers (3)

user8128167
user8128167

Reputation: 7706

I have found that it works well to simply display the date of the last build using the following wherever a product version is needed:

System.IO.File.GetLastWriteTime(System.Reflection.Assembly.GetExecutingAssembly().Location).ToString("yyyy.MM.dd.HHMM")

Rather than attempting to get the version from something like the following:

System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
object[] attributes = assembly.GetCustomAttributes(typeof(System.Reflection.AssemblyFileVersionAttribute), false);
object attribute = null;

if (attributes.Length > 0)
{
    attribute = attributes[0] as System.Reflection.AssemblyFileVersionAttribute;
}

Upvotes: 1

Rune FS
Rune FS

Reputation: 21752

You can have build and revision incremented for you but not major and minor.

Simply substitute

[assembly: AssemblyVersion("1.0.0.0")]

with

[assembly: AssemblyVersion("1.0.*")]

in the AssemblyInfo.cs

Upvotes: 4

user725913
user725913

Reputation:

Have you tried grabbing the Assembly's version?

System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;

Perhaps this is what you are looking for.

Also check out this other SO post - I think this is what you are looking for.

Automatically update version number

Below is a second link to a .Net add-in that automatically increments the:

  • Major
  • Minor
  • Build
  • Revision

http://testdox.wordpress.com/versionupdater/

Upvotes: 4

Related Questions