<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Chris Sienkiewicz's Blog</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/chris/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/chris/feed.xml</link>
    <description>Random musings on a range of development subjects</description>
    <lastBuildDate>Wed, 17 Apr 2019 04:08:15 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Getting the assembly version in a Windows Store App</title>
      <link>https://docs.microsoft.com/archive/blogs/chris/getting-the-assembly-version-in-a-windows-store-app</link>
      <pubDate>Thu, 14 Feb 2013 01:52:00 GMT</pubDate>
      <dc:creator><![CDATA[Chris Sienkiewicz]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.msdn.microsoft.com/chris/2013/02/14/getting-the-assembly-version-in-a-windows-store-app/</guid>
      <description><![CDATA[Getting the version number of the executing assembly can be really useful, either to display to user...]]></description>
      <content:encoded><![CDATA[<p>Getting the version number of the executing assembly can be really useful, either to display to user in the about screen, or include in crash reports and feedback forms. Every incarnation of the framework seems to have a different way of doing this and .NET for Windows Store Apps is no exception.</p>
<p>You can get the version number from an instance of the Assembly class; Unfortunately the <code class="csharp">Assembly.GetExecutingAssembly()</code>method isn't available, so you have to get a reference to the executing assembly in a different way. In Windows Store Apps you can access the current assembly by looking at the type information for any type in that assembly.</p>
<p>Most&nbsp;members of <span style="font-family: courier new,courier;">System.Type</span> have now been moved into the <span style="font-family: courier new,courier;">System.Reflection.TypeInfo</span> class, which you can get via the <span style="font-family: courier new,courier;">Type</span><span style="font-family: courier new,courier;">.GetTypeInfo()</span> extension method. (<strong>Note</strong>: this extension method&nbsp;exists in the <span style="font-family: courier new,courier;">System.Reflection</span> namespace, so you'll need to make sure its in your <span style="font-family: courier new,courier;">using </span>list&nbsp;to get access to it.)</p>
<p>From the&nbsp;obtained TypeInfo&nbsp;you can access the Assembly property, and from that the version number:</p>
<p><span style="font-family: Courier New;">&nbsp;var assemblyVersion = this.GetType().GetTypeInfo().Assembly.GetName().Version.ToString(4);</span></p>
<p>It can also be useful to get&nbsp;the value of the&nbsp;AssemblyFileVersion&nbsp;attribute (often this version number is used rather than the assembly version as it doesn't cause the AssemblyQualifiedName to change). You can access any attribute on the Assembly by calling the <span style="font-family: courier new,courier;">Assembly</span><span style="font-family: courier new,courier;">.GetCustomAttribute&lt;T&gt;</span> method, where T is the&nbsp;attribute you want to access:</p>
<p><code class="csharp">&nbsp;var fileAssemblyVersion = this.GetType().GetTypeInfo().Assembly.GetCustomAttribute&lt;AssemblyFileVersionAttribute&gt;().Version;</code></p>
<p>Using these two snippets you can now access both the Assembly and Assembly File versions of your Windows Store App, allowing you to uniquely identify the version of the app your crash reports and feedback&nbsp;relate to.</p>
<p>Chris</p>]]></content:encoded>
    </item>
  </channel>
</rss>