13

While porting an application to the Windows Store, I noticed the .NETCore Framework does not include:

System.Reflection.Assembly.GetExecutingAssembly()

I used this to get the version information for display on the menu screen. Is there a replacement or am I forced to store the information elsewhere for retrieval?

EDIT:

I've also found that I can extract a version number out of typeof(MyType).AssemblyQualifiedName but that seems bad.

Justin Skiles
  • 9,373
  • 6
  • 50
  • 61
  • possible duplicate of [System.Reflection.Assembly.GetExecutingAssembly() in WinRT](http://stackoverflow.com/questions/7451703/system-reflection-assembly-getexecutingassembly-in-winrt) – David Basarab Nov 04 '12 at 01:37

1 Answers1

25

I am using this :

public string GetApplicationVersion()
{
  var ver = Windows.ApplicationModel.Package.Current.Id.Version;
  return ver.Major.ToString() + "." + ver.Minor.ToString() + "." + ver.Build.ToString() + "." + ver.Revision.ToString();
}

And if you want assembly version you can get it from Version attribute :

public string GetAssemblyVersion(Assembly asm)
{
  var attr = CustomAttributeExtensions.GetCustomAttribute<AssemblyFileVersionAttribute>(asm);
  if (attr != null)
    return attr.Version;
  else
    return "";
}

For example using main App's assembly :

Assembly appAsm = typeof(App).GetTypeInfo().Assembly;
string assemblyVersion = GetAssemblyVersion(appAsm);
Antonio Bakula
  • 20,445
  • 6
  • 75
  • 102