Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top