tags:

views:

248

answers:

1

I want to be able to display the current version of a .NET application that I have deployed using the publish wizard. There is a nice option to automatically update the version number every time I publish my application.

I found another question(Automatically update version number) that had this to get the current version.

Assembly.GetExecutingAssembly().GetName().Version

This gets you the version you set in the project properties but not the version that is automatically incremented each time you publish.

+3  A: 

I ended up using this little bit of code to get the current deployed version or if it isn't deployed the current assembly version.

private Version GetRunningVersion()
{
  try
  {
    return System.Deployment.Application.ApplicationDeployment.CurrentDeployment.CurrentVersion;
  }
  catch
  {
    return Assembly.GetExecutingAssembly().GetName().Version;
  }
}

I had to add a reference to System.Deployment.

Ed Haber