none
How to get WPF version?

    Question

  • Is there a way to get the current WPF version? e.g., 3.0, 3.0 SP1, 3.5, (whatever others there are)? As part of the diagnostics bit of my application I'd like to report this information.

    Wednesday, October 17, 2007 5:27 PM

Answers

  • All future releases of WPF will be part of the .NET Framework.

    Here is the official way to detect which versions of the framework are installed: http://msdn2.microsoft.com/en-us/library/aa480198.aspx#netfx30_topic15 .

    SP1 will not be supported as a distinct "release" applications can target. However, for diagnostic purposes, it may help to know whether it's installed. You can deduce this in different ways:

      - Check for presence of key HKLM\SOFTWARE\Microsoft\.NETFramework\v3.0 SP1

      - Check the last component of Environment.Version. Currently I get 2.0.50727.1426. I don't know what the final version will be, but you can assume something >= 1426. And most likely any future service packs will be cumulative, so this number will keep growing.

      - Check the file (not assembly) version of PresentationFramework.dll. The .NET v3 file version is 3.0.6920.0. The last component will not be zero for SP1.

      - Use Reflection to check whether the Application class has a property called ResourceAssembly. This is officially provided by .NET v3.5, but it happens to be in a v3 assembly.

    Again, all these SP1 detection methods are valid only for diagnostic purposes.

    Sunday, October 21, 2007 1:00 AM

All replies

  • Hi,

       Try the below code:

     

    Code Block

    System.Runtime.InteropServices.RuntimeEnvironment.GetSystemVersion() ;

     

     

    This will return a string. If you want a System.Version object then use:

     

    Code Block
    Environment.Version;

     

     

    But I am not sure what the result is when there are multiple framework installed !!!

     

    Hope this helps.

     

    ~Ram
    Wednesday, October 17, 2007 5:40 PM
  • Right - this returns the framework version. I guess I could ask a related question, then: will the framework version change along with the WPF version? If I have an XP machine with WPF and then install WPF 3.0 SP1 (assuming there will be one - I've only heard it mentioned on some blogs), will the framework version change?

    Wednesday, October 17, 2007 5:45 PM
  • Hi,

       Hmm kinda a twisted me a bit.. well if @ all they change there MIGHT be some minor value changes to the version. Maybe some one from MS can answer this...

     

    Sorry... not much of an help on this ah...

     

     

    ~Ram

    Wednesday, October 17, 2007 7:44 PM
  • That's ok Smile

    The reason I'm asking is that I've noticed some differences between 3.0 and 3.5b2 (certain things work on my 3.5b2 dev box, but not on other 3.0 machines), and once 3.5 is released and there are people out there running my app with both versions, it'd be nice to know what they are running so I can try to reproduce it.

    Wednesday, October 17, 2007 7:48 PM
  • Hey Ben,

     

     One quick qtn.. did u try running this in Multple framework installed machine... I wanna know what the result is under that case.. does it give out the latest one... ????

     

    In VS2008 you can set the Framework that code shld run under... What happens under that case... do u know...?

     

    ~Ram

     

    Wednesday, October 17, 2007 7:53 PM
  • Environment.Version gives you the version of the CLR that is running your code.

    Wednesday, October 17, 2007 7:56 PM
  • Thanks Ben. It is gud to know...

     

    Wednesday, October 17, 2007 8:04 PM
  • All future releases of WPF will be part of the .NET Framework.

    Here is the official way to detect which versions of the framework are installed: http://msdn2.microsoft.com/en-us/library/aa480198.aspx#netfx30_topic15 .

    SP1 will not be supported as a distinct "release" applications can target. However, for diagnostic purposes, it may help to know whether it's installed. You can deduce this in different ways:

      - Check for presence of key HKLM\SOFTWARE\Microsoft\.NETFramework\v3.0 SP1

      - Check the last component of Environment.Version. Currently I get 2.0.50727.1426. I don't know what the final version will be, but you can assume something >= 1426. And most likely any future service packs will be cumulative, so this number will keep growing.

      - Check the file (not assembly) version of PresentationFramework.dll. The .NET v3 file version is 3.0.6920.0. The last component will not be zero for SP1.

      - Use Reflection to check whether the Application class has a property called ResourceAssembly. This is officially provided by .NET v3.5, but it happens to be in a v3 assembly.

    Again, all these SP1 detection methods are valid only for diagnostic purposes.

    Sunday, October 21, 2007 1:00 AM
  • Thanks for the information! This is exactly what I was looking for.

    Sunday, October 21, 2007 1:26 AM