2

I want to show the current BUILD info on my title bar. (main_form.txt).

I have seen several references to finding it, but none are giving me the data I want.

My project is a fairly simple visual studio express 2015, win forms app .net 4.5

When I look in properties/publish I see that the build is currenly 1.0.0.13 and will increase each publish I do.

Where can I get those variables ?

I see in the bbox2.exe.manifest file the following line....

asmv1:assemblyIdentity name="bbox2.exe" version="1.0.0.13" publicKeyToken="1d053a5b342cefc4" language="neutral" ........

I have tried as suggested in another post the following..

    Dim ass As System.Reflection.Assembly = System.Reflection.Assembly.GetExecutingAssembly()
    Dim ver As System.Version = ass.GetName().Version
    Me.Text = ("BlacBox" & ver.Major & "." & ver.Minor & "." & ver.Revision & "." & ver.Build)

but that ALWAYS gets me 1.0.0.0 ??

Any and all advice appreciated.

Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
Willie
  • 21
  • 1
  • 2
  • 3
    Possible duplicate of [How do I get the current published version in a .NET application?](http://stackoverflow.com/questions/1248824/how-do-i-get-the-current-published-version-in-a-net-application) – sstan Jan 15 '16 at 22:39
  • The *Publish Version* is usable when you publish the application using click once, otherwise you can use the value of `AssemblyVersion` in `AssemblyInfo.vb` under *My Project* folder. Like publish version, you can set the assembly version also increase automatically using `` or `` Also you can change the major, minor, and build versions to suitable values. – Reza Aghaei Jan 16 '16 at 00:16
  • **OP: [I am not using click once.](http://stackoverflow.com/questions/34821037/i-want-to-show-the-current-build-info-on-my-title-bar#comment57389157_34821632)** So you should know If you are not using click once, surely you should use `AssemblyVersion` and also you should make it auto increment by changing `AssemblyVersion` to `AssemblyVersion("1.0.*")>` and then to get the version it's enough to use `Assembly.GetExecutingAssembly().GetName().Version.ToString()` – Reza Aghaei Jan 16 '16 at 11:19
  • @sstan While the linked question is useful but it is not a duplicate of this question. Here the op is not using click once and he need to know what's the difference between the ways he can get the version in click once or non-click once way. Also he need to make the assembly version increment automatically. I think both the question and answer in this question is totally different and useful for future readers. – Reza Aghaei Jan 16 '16 at 12:53

1 Answers1

2

The Publish Version is usable when you publish the application using click once, otherwise you can use the value of AssemblyVersion in AssemblyInfo.vb under My Project folder.

Like publish version, you can set the assembly version also increase automatically using <Assembly: AssemblyVersion("1.0.*")> or <Assembly: AssemblyVersion("1.0.0.*")> Also you can change the major, minor, and build versions to suitable values.

You can create a property that returns the version string this way:

Public ReadOnly Property ApplicationVersion As Version
    Get
        If (ApplicationDeployment.IsNetworkDeployed) Then
            Return ApplicationDeployment.CurrentDeployment.CurrentVersion
        Else
            Return Assembly.GetExecutingAssembly().GetName().Version
        End If
    End Get
End Property

Don't forget to add reference to System.Deployment assembly and add the import namespace to code:

Imports System.Deployment.Application

Then you can use:

Me.Text = ApplicationVersion.ToString()

Or to show version in custom format, you can use Major, Minor, Build and Revision, for example to show version up to build number:

Me.Text = String.Format("{0}.{1}.{2}", _
          ApplicationVersion.Major, ApplicationVersion.Minor, ApplicationVersion.Build)

EDIT

OP: I am not using click once.

So you should use AssemblyVersion in AssemblyInfo.vb under My Project folder and make it auto increment by changing it to <Assembly: AssemblyVersion("1.0.*")>. Then you can get the version this way:

Me.Text = Assembly.GetExecutingAssembly().GetName().Version.ToString()

Don't forget to Imports System.Reflection

Community
  • 1
  • 1
Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
  • Sorry, I am just a noob playing with making a small "find the target" type game. I am using some friends to do beta testing and want an easy way to see what build they are testing. I am not using click once. I did add the imports as the first line in my main_form.vb code file. also pasted in your property code. In the property I am getting an error at assembly stating not declared.. Am I doing something wrong or forgetting something? – Willie Jan 16 '16 at 04:06
  • Sorry to be a pain.. but thats not working either,,, from assemblyinfo.vb-- ' You can specify all the values or you can default the Build and Revision Numbers ' by using the '*' as shown below: ' and in main_form-- Me.Text = Assembly.GetExecutingAssembly().GetName().Version.ToString() assembly highlighted and gives error 'assembly not declared"... – Willie Jan 16 '16 at 16:22
  • Assembly is in System.Reflection namespace. Also make sure you read my comments and the edited part of answer and use correct format for assemblyversion. – Reza Aghaei Jan 16 '16 at 16:41
  • from assemblyinfo.vb-- {Imports System Imports System.Reflection Imports System.Runtime.InteropServices Imports System.Deployment.Application ' } and then in the main_form.vb...3 {Me.Text = Assembly.GetExecutingAssembly().GetName().Version.ToString()} assembly is highlighted and gives error 'assembly not declared"... – Willie Jan 16 '16 at 19:35
  • Dear @Willie the only thing you should do is following **Edit** part in answer :) The rest of answer is for future readers or when you want to know more about the version :) – Reza Aghaei Jan 17 '16 at 09:39
  • I edited the edit part to Don't forget to `Imports System.Reflection` – Reza Aghaei Jan 17 '16 at 20:41