Hi

I'm trying to display the version number of my application on the screen using the code below.

Version = My.Application.Info.Version.ToString

When ever this line of code runs Version always ends up being but my publish version number is

Is the My.Application.Info.Version not the same as the publish version number?

Can some one tell me what I'm doing wrong

Thanks

Simon

Dani AI

Generated

What you are seeing is the difference between three version concepts in .NET and Visual Studio: the assembly version, the file/product version, and the ClickOnce Publish (deployment) version. My.Application.Info.Version returns the assembly version embedded in your assembly metadata, not the ClickOnce Publish version. That value comes from AssemblyInfo and remains 1.0.0.0 unless you change it. See AssemblyInfo.Version.

If you want the assembly version to auto-increment at build time, set a wildcard in AssemblyInfo. This increments build/revision automatically. Note that changing assembly version affects binding; keep it stable for shared libraries.

' In My Project\AssemblyInfo.vb
<Assembly: AssemblyVersion("1.0.*")>          ' auto-increment build/revision
<Assembly: AssemblyFileVersion("1.0.0.0")>    ' stays fixed for file/product version

If you specifically need the ClickOnce Publish version (the number you set on the Publish tab), read it at runtime via ClickOnce APIs: System.Deployment.Application.ApplicationDeployment.CurrentDeployment.CurrentVersion when the app is network deployed. Docs: ApplicationDeployment.CurrentVersion and IsNetworkDeployed.

For full assembly metadata (company, product, file version), you can also query System.Diagnostics.FileVersionInfo for the executable path, which exposes ProductVersion, FileVersion, CompanyName, etc. Reference: FileVersionInfo.

Recommended Answers

All 7 Replies

Did you set the version number by going to Project/Properties/Assembly Information and typing it into the dialog? That's where My.Application.Info.Version gets it from.

Did you set the version number by going to Project/Properties/Assembly Information and typing it into the dialog? That's where My.Application.Info.Version gets it from.

Ah ok, I was hoping that each time I published my code after making changes the version number would auto increment without me having to do anything. Looks like

My.Application.Info.Version

is not going to do what I want it to do:(

There is a quick way to do this, set your (Solution)/(Project)/My Project/app.manifest to always copy to the output dir. then in your code use a simple XML reader to grab the version out of that file:

Try
            Dim m_xmld = New XmlDocument()
            m_xmld.Load(Application.ExecutablePath & ".manifest")
            Label14.Text = "v" & m_xmld.ChildNodes.Item(1).ChildNodes.Item(0).Attributes.GetNamedItem("version").Value
        Catch ex As Exception
        Finally
        End Try

does someone knows how to get the whole assembly information using a similar code like the one posted in this Thread??

thanks...

as far as i know that is all you can get...

I have found a way to set the My.Application.Info.Version successfully in VB.NET using Microsoft Visual Basic 2010 Expres.

Navigate to your Projects Properties. (I do this by going to View > [projectname] Properties...) Then make sure you have the "Application" tab selected. Click on the button "Assembly Information". In here you can set the "Assembly version:" fields and they can then be referenced in your application by calling My.Application.Info.Version. This number will not auto-increment, you will have to change it manually.

The numbers seen in [projectname] Properties > Publish tab > Publish Version are always ingored ignored.

Hi,
I use this code when I publish applications.

Imports System.Deployment.Application

If (ApplicationDeployment.IsNetworkDeployed) Then
Dim AD As ApplicationDeployment = ApplicationDeployment.CurrentDeployment
Label2.Text = "v " & AD.CurrentVersion.ToString
Else
Label2.Text = "v " & My.Application.Info.Version.ToString
End If

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.