2

I want to read the version info of a Strong Named .NET (built using v4.0) assembly using Powershell v2. I am using two different ways to do this, but the 2nd method always gives me the correct version information [although the 1st method was the obvious natural choice] :-

Method 1: [Reflection.AssemblyName]::GetAssemblyName("C:\ManagedAssembly.exe").Version.ToString()

gives the value as "50.0.0.0"

Method 2: [System.Diagnostics.FileVersionInfo]::GetVersionInfo("C:\ManagedAssembly.exe").FileVersion

gives the version correctly as "50.0.0.93"

Any idea why such a behaviour ?

4
  • 1
    How do you know that the above is wrong? Windows Explorer on Win 7 doesn't show the assembly version by default and instead shows the file version. Your two values for file and assembly versions look sensible. Commented May 23, 2012 at 9:45
  • 2
    Assembly Version and File Version can be set different in solution properties from Visual studio. Commented May 23, 2012 at 9:45
  • Got it. I just opened the AssemblyVersionInfo.cs file and observed the following entries - [assembly: AssemblyVersion("50.0.0.0")] & [assembly: AssemblyFileVersion("50.0.0.93")] --- which makes sense. Commented May 23, 2012 at 9:48
  • +1 for the OP for using [Reflection.AssemblyName]::GetAssemblyName which gets the version info without loading the assembly into the current app domain. Most examples use [Assembly]::Loadxxx(), which can be problematic. Commented Jul 2, 2013 at 3:34

1 Answer 1

1

My Mistake & Ignorance. The AssemblyVersionInfo.cs file contains two entries -

[assembly: AssemblyVersion("50.0.0.0")]

&

[assembly: AssemblyFileVersion("50.0.0.93")] 

So, the above code is absolutely fine.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.