2

I have to display build version automatically without entering manually in windows form application, I have tried something like [assembly: AssemblyVersion("1.0.*")] in assemblyInfo.cs but its show like below,

{1.0.7145.41554} its looks awkward

I want show something like this [1.0.0.13] after published, but it always takes [1.0.0.1]

see the below image I want to show that version in view page actually enter image description here

This is how I'm getting version; but it is returning [1.0.0.1]

 //Get Version of the currently executing Assembly
 var anm = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
 ExistingVersion = String.Format("{0}", anm);
 EMajor = anm.Major;
 EMinor = anm.Minor;
 EBuildNo = anm.Build;
 ERevisionNo = anm.Revision;

 lblVersionv.Text = String.Format("Current Version : {0}", anm);

How I can do that?

PK-1825
  • 1,431
  • 19
  • 39

2 Answers2

2

It is a bit convoluted but you can reach this info from your own code and then decide to display it how you like.

First step is the most critical, you need to get a Type from one of your own classes.
You can use your main form class for example

Type myApp = Type.GetType("your-full-qualified-class-name-here");

So suppose your namespace is "MyApplication" and your main form class is named "MyStartupForm" then you should replace the string above with "MyApplication.MyStartupForm" (be precise with upper/lowercase letters)

Now with the type you could get the the Version information with

Version v = myApp.Assembly.GetName().Version;

And finally the version variable will have all the info you need.
(Look at the property Build, Version, Revision, MinorRevision, MajorRevision)

Note also that the override for the ToString method will return to you a single string with all the information required

Steve
  • 213,761
  • 22
  • 232
  • 286
0

I solve this by adding below code

 if (ApplicationDeployment.IsNetworkDeployed)
  {
     lblVersionv.Text = string.Format("Version : {0}",ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString(4));
  }
PK-1825
  • 1,431
  • 19
  • 39