Using PowerShell To Find An Assemblies Framework Version

0 Flares Twitter 0 Facebook 0 StumbleUpon 0 Google+ 0 LinkedIn 0 0 Flares ×

I was trying to install a 3rd party assembly to the gac today and was having some issues. I needed to find out what version of the .net framework the dll was built against – normally I’d break out the visual studio command prompt and use ildasm.exe, but as powershell has become my new best friend I decided to give it a try – and it all worked very nicely!

The single line of powershell script to get this running is:

Ref: http://stackoverflow.com/questions/2094694/launch-powershell-under-net-4

This simple script returns the .net framework version number the assembly was built against. The only wrinkle being that as the powershell console was built against .net 2.0/3.5, if you run this against a .net 4.0 assembly you get an exception. Here you have 2 options:

  1. Assume its .net 4.0 if the exception is thrown (this is fiar enough)
  2. Add a supportedRuntime element to the powershell console config (see below)

To add the config, you first need to find the powershell console root directory, you can find this by executing $psHome. Navigate to this folder and create either powershell.exe.config or powershell_ise.exe.config with the following contents:

Obviously, if you already have a config file you just need to add the relevant element.

Matt

,

The Essential App Marketing Kit
Subscribe To My Newsletter To Get an Entire Chapter From The Book for FREE
Never display this again
0 Flares Twitter 0 Facebook 0 StumbleUpon 0 Google+ 0 LinkedIn 0 0 Flares ×