The IoT Core application I'm working on needs to know the (package) version of another application.
Is it possible to find out the version of another app (without needing the admin password as in the example below)?
Unfortunately AppDiagnosticInfo
doesn't provide this information (it provides package family name).
I know this is possible with Device Portal REST api, but this requires the device admin password which is not suitable for production scenarios.
//Import WindowsDevicePortalWrapper with NuGet
using Windows.System.Diagnostics.DevicePortal;
(...)
var devicePortalConnection1 = new DefaultDevicePortalConnection(
"http://127.0.0.1:8080",
"administrator",
"my device administrator password");
var portal = new DevicePortal(devicePortalConnection1);
var packages = await portal.GetInstalledAppPackagesAsync();
You can use PackageManager to get the installed packages version. It does not need username and password,but it runs on device locally. Please refer to below code.
Windows.Management.Deployment.PackageManager packageManager = new Windows.Management.Deployment.PackageManager();
IEnumerable<Windows.ApplicationModel.Package> packages = (IEnumerable<Windows.ApplicationModel.Package>)packageManager.FindPackages();
foreach(var pkg in packages)
{
var version = pkg.Id.Version;
Debug.WriteLine(string.Format("{0}.{1}.{2}.{3}", version.Major, version.Minor, version.Build, version.Revision));
}
To run above code, you also need to add a restricted capability to the Package.appxmanifest. Had to add a new namespace at the top of the file:
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
and add the following to the Capabilties tag.
<rescap:Capability Name="packageQuery" />
You may need to add the 'rescap' namespace to the Ignorable list as per this information.