views:

57

answers:

2

In C# one can use System.Version.Assembly to get the version of a running app. However this doesn't appear to exist in Silverlight for Windows Phone. Is there an alternative?

+3  A: 

You can use the GetExecutingAssembly method and the AssemblyName class to find this information.


  var nameHelper = new AssemblyName(Assembly.GetExecutingAssembly().FullName);

  var version = nameHelper.Version;
  var full = nameHelper.FullName;
  var name = nameHelper.Name;

Walt Ritscher
This doesn't work on Windows Phone because none of these properties are exposed.
henry
I'm not sure what phone you have, but this code works on the Windows Phone 7.
Walt Ritscher
+1  A: 

On Phone 7 there is no clean way to get the version. The best thing to do is parse the Full Name (which is the only exposed property) for the version string:

String appVersion = System.Reflection.Assembly.GetExecutingAssembly().FullName.Split('=')[1].Split(',')[0];

henry