.netreflectioncaspartial-trust

How can I access my assembly version number in a partial trust environment (no FileIOPermission)


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?


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