3

I'm trying to access the Version number of my assembly at runtime.

The code I'm using for that requires a FileIOPermission, which I don't want to grant (I'm in the Internet Zone)

this.GetType().Assembly.GetName().Version;

Is there another way to access the version number which doesn't require elevation?

Brann
  • 31,689
  • 32
  • 113
  • 162

2 Answers2

3

It's not quite the same version number (It's the "AssemblyFileVersion" rather than the "AssemblyVersion" attribute) but you can use the following line of code:

System.Windows.Forms.Application.ProductVersion

That returns a string.

If you're doing automated builds, then you have to remember to increment both numbers.

Alternatively

If you are doing this as a ClickOnce application, the version number is found in:

System.Deployment.Application.ApplicationDeployment.CurrentDeployment.CurrentVersion

Hope that helps

Matthew Steeples
  • 7,858
  • 4
  • 34
  • 49
1

If you need the AssemblyVersion without FileIOPermission you will have to parse Assembly::FullName.

Jakob Christensen
  • 14,826
  • 2
  • 51
  • 81