Read msix package appxmanifest version
Asked Answered
P

2

7

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?

Piecedyed answered 2/6, 2020 at 21:51 Comment(0)
V
4

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://learn.microsoft.com/en-us/uwp/api/

https://www.thomasclaudiushuber.com/2019/04/26/calling-windows-10-apis-from-your-wpf-application/

Vange answered 3/7, 2020 at 16:0 Comment(3)
Sorry for my late responding. Thanks, this solution works like a charm, so I accepted this answer :)Piecedyed
For .Net 5 there's no need to install anything, just change in csproj TargetFramework from (for example) net5.0-windows to net5.0-windows10.0.17763 or net5.0-windows10.0.19041.1 or whatever version you need.Stannic
Note: This works in .NET Core but not in .NET 5.Haman
M
1

Call Windows Runtime APIs in desktop apps

For .NET 6 and later:

Modify TargetFramework in project file.

<TargetFramework>net6.0</TargetFramework>

To

<TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>

Or any of the below versions.

net6.0-windows10.0.17763.0: If your app targets Windows 10, version 1809.

net6.0-windows10.0.18362.0: If your app targets Windows 10, version 1903.

net6.0-windows10.0.19041.0: If your app targets Windows 10, version 2004.

net6.0-windows10.0.22000.0: If your app targets Windows 11.

https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/desktop-to-uwp-enhance

Maculation answered 10/1, 2023 at 20:30 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.