When creating a Windows Phone application that will be submitted and hopefully published in the Marketplace, is always a good idea to have an "About" page where users can find information about the application, the author and even support contact information. When doing this, you should always include the application version number, so you know which version of your application the user has. This will save you a lot of time when trying to solve issues or when trying to replicate certain behaviours.
Here is how you retrieve the application's assembly version number:
The code assumes you are running the method on the MainPage.xaml.cs and that's why it uses its type when retrieving the current assembly. If you were running this on the about page (called AboutPage.xaml) then you should use that as the type to get the assembly. When calling ToString() on the assembly returned, you will get the assembly properties (you can modify this on the project's assembly properties):
TestApp, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
Remember that the assembly number is not related to the Marketplace application version number, but it is a good idea to keep both in sync, so make sure to review/update the assembly version number when you are publishing your app and choosing the version number for the Marketplace in the App Hub portal.
Please do this instead: http://arktronic.com/weblog/2012-05-16/how-properly-get-windows-phone-apps-assembly-version
ReplyDeleteThanks for taking the time to leave your comment.
DeleteI'm aware of the reflection approach, however I'm not sure if this is the "correct way" of doing it. Seems to me that this might be slower and maybe overkill. I'll test both approaches and publish the results.
I think too that "new System.Reflection.AssemblyName(System.Reflection.Assembly.GetExecutingAssembly().FullName).Version" is better
ReplyDeleteThanks for stopping by. Do you have any performance and code insights? I just want to prove whether one way or another is actually better, and not just a style based opinion.
Delete