We have a .NET Core application which only will be used in-house. We changed from Click-Once to MSIX during our switch from WPF to .NET Core. In the window caption/title of our application we also "output" the current version (major, minor, ...). Previously, we took the version of our startup project (called "view"). Now using MSIX, this project has got the version number we need (the startup project is referenced to "view"). How can we read the correct version now?
Using Assembly.GetEntryAssembly
or Assembly.GetCallingAssembly
returns the wrong version - the version of the startup project. The application is not in the Windows Store, it will be side loaded as a package. Any ideas to get the "correct" version we "produce" when deploying our package?
Open the Package. appxmanifest file. In Microsoft Visual Studio, open the file with the XML (Text) Editor. To do that, in Solution Explorer, right-click the file and click Open with.
Package.appxmanifest This is an XML style file that developers use to configure the details of an app, such as publisher information, logos, processor architectures, etc. This is an easily configurable, temporary version of the app package manifest used during app development.
To open an MSIX file and begin installation of the packaged app in Windows 10, simply double-click the file. App Installer opens the MSIX file and displays information about the app, such as the name, publisher, and version, as well as the capabilities requested by the app.
You need to install the Windows 10 WinRT API pack. Install from Nuget the package: Microsoft.Windows.SDK.Contracts
URL: https://www.nuget.org/packages/Microsoft.Windows.SDK.Contracts
Then you can do something like this:
var version = Windows.ApplicationModel.Package.Current.Id.Version;
applicationVersion = string.Format("{0}.{1}.{2}.{3}",
version.Major,
version.Minor,
version.Build,
version.Revision);
If you want to DEBUG or Run with the current Package available, just set your package deployment project as the Startup Project.
Additional References:
https://blogs.windows.com/windowsdeveloper/2019/09/30/windows-10-winrt-api-packs-released/
https://docs.microsoft.com/en-us/uwp/api/
https://www.thomasclaudiushuber.com/2019/04/26/calling-windows-10-apis-from-your-wpf-application/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With