Reputation: 1638
In my AssemblyInfo.cs
file, I have attributes like:
[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyCopyright("Copyright © 2015")]
Now i want to get this informations in my OnLaunched(LaunchActivatedEventArgs e)
Method in my App.xaml.cs
.
When I search for this in the internet and on SO I always solutions like:
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
string version = fvi.FileVersion;
But this doesn´t work for Windows 10. So is there something similar for Windows 10?
Edit:
I am developing an Windows 10 UWP application.
Upvotes: 0
Views: 1102
Reputation: 516
You can find attributes using this code:
var currentAsembly = typeof(App).GetTypeInfo().Assembly;
var customAttributes = currentAssembly.CustomAttributes;
CustomAttributes is IEnumerable object of available atttributes among them you can find information abut assembly and file version
Edit:
Here is complete code:
var currentAssembly = typeof(App).GetTypeInfo().Assembly;
var customAttributes = currentAssembly.CustomAttributes;
var list = customAttributes.ToList();
var res = list[0];
var result = list.FirstOrDefault(x => x.AttributeType.Name == "AssemblyFileVersionAttribute");
var ver = result.ConstructorArguments[0].Value;
Upvotes: 1
Reputation: 674
If you need to get information about app version in general, you can use Package.Current property.
using Windows.ApplicationModel;
Package package = Package.Current;
PackageId packageId = package.Id;
PackageVersion version = packageId.Version;
String output = String.Format(
"Name: \"{0}\"\n" +
"Version: {1}.{2}.{3}.{4}\n" +
"Architecture: {5}\n" +
"ResourceId: \"{6}\"\n" +
"Publisher: \"{7}\"\n" +
"PublisherId: \"{8}\"\n" +
"FullName: \"{9}\"\n" +
"FamilyName: \"{10}\"\n" +
"IsFramework: {11}",
packageId.Name,
version.Major, version.Minor, version.Build, version.Revision,
packageId.Architecture,
packageId.ResourceId,
packageId.Publisher,
packageId.PublisherId,
packageId.FullName,
packageId.FamilyName,
package.IsFramework);
Upvotes: 4