Volearix
Volearix

Reputation: 1593

Get the published application version

My file version in my publish is displaying differently when my application executes. I'm a tad confused on this because as you can see below, my application is published as 1.0.0.2 and soon to be 1.0.0.3, but shows as 1.0.0.0. My employer has requested an assembly version, but I'm getting the wrong thing... How do I return the correct application version? Thank you!

Screen of my publish info: Publish Version

Picture of what my actual app is returning:

enter image description here

And last but not least, the code:

public void setExecutingAssembly()
{
    FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assemblyVersion.Location);
    string appVersion = fvi.FileVersion;
    this.Text = string.Format(" {0} v{1}", this.Text, appVersion);
}

Upvotes: 0

Views: 231

Answers (2)

iamthe0ne23
iamthe0ne23

Reputation: 11

I believe you can achieve this using Reflection-

Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
this.Text = (String.Format("{0}.{1}.{2}.{3}", version.Major, version.Minor,
            version.Revision, version.Build));

Upvotes: 0

Matthew Watson
Matthew Watson

Reputation: 109567

You can use ApplicationDeployment.CurrentDeployment.CurrentVersion to get at the version string:

private static string clickOnceVersion()
{
    if (ApplicationDeployment.IsNetworkDeployed)
        return ApplicationDeployment.CurrentDeployment.CurrentVersion.ToString();
    else
        return null;
}

Also, if you want to get the version number of the executable from code that is inside a class library, you can do this:

private static string programVersion()
{
    var assembly = Assembly.GetEntryAssembly(); // Version number of the calling exe, not this assembly!

    if (assembly != null)
        return Assembly.GetEntryAssembly().GetName().Version.ToString();
    else // Only happens if being called via reflection from, say, Visual Studio's Form Designer.
        return Assembly.GetExecutingAssembly().GetName().Version.ToString();
}

However, I think it's the first of those methods that you need.

Upvotes: 1

Related Questions