实现packageManager.AddPackageAsync时出错 [英] Error while implementing packageManager.AddPackageAsync
问题描述
你好,
我打算使用后台应用程序(UWP)安装Application。我的代码看起来像这样:
private static async Task InstallPackageAsync(string packagePath)
{
Debug.WriteLine(" Install Package");
string fullNamePackage =" cd08eb5f-bd86-4694-96c8-5d8e9fb32eed_jfasm645wnjtr" ;;
var packageManager = new PackageManager();
var packages = packageManager.FindPackagesForUser(string.Empty).ToList();
Debug.WriteLine(" packages:" + packages [0]);
URI packageUri =新URI(" 跨度> C:\\Users\\mahes\\CityTireTimeClock_1.0.2.0_ARM_Debug.appx的");
  ;     VAR updateInsteadOfInstall = packages.Any(P => p.Id.FullName == fullNamePackage);
          &NBSP ; if(updateInsteadOfInstall)
{
的Debug.WriteLine([更新安装软件包"); 跨度>
您好  mahesh_Pochamreddy,
>>> 我打算使用后台应用程序(UWP)安装应用程序
所以我假设您正在运行
后台应用程序。在Windows IoT Core上有这样的路径: C:\ Users。正确的路径是C:\ Data \Users。
>>> 抛出异常:System.Private.CoreLib.dll中的'System.Exception'
WinRT信息:错误0x80070003:从位置打开包
由于我上面说的无效文件路径导致此错误。
>>> 串fullNamePackage = QUOT; cd08eb5f-bd86-4694-96c8-5d8e9fb32eed_jfasm645wnjtr英寸; 跨度>
完整的包名称中包含这样的版本信息:  db0c5c3b-d107-435a-A257-a26fa8f966d2_1.0.0.0_arm__a48w6404kk2ea
下面的代码对我的作品。你可以尝试一下:
private static async Task InstallPackageAsync()
{
Debug.WriteLine(" Install Package");
string fullNamePackage =" db0c5c3b-d107-435a-a257-a26fa8f966d2_1.0.0.0_arm__a48w6404kk2ea" ;;
var packageManager = new PackageManager();
var packages = packageManager.FindPackagesForUser(string.Empty).ToList();
Debug.WriteLine(" packages:" + packages [0]);
var updateInsteadOfInstall = packages.Any(p => p.Id.FullName == fullNamePackage);
如果(updateInsteadOfInstall)
{
乌里packageUri =新URI(" C:\\Data\\Users\\DefaultAccount\\updateTest\\\ \\CityTireTimeClock_1.0.1.0_x86_x64_arm_Debug.appxbundle");
Debug.WriteLine(" update Install Package");
var result = await packageManager.UpdatePackageAsync
(packageUri,null,DeploymentOptions.ForceApplicationShutdown);
}
else
{
Uri packageUri = new Uri(" C:\\Data\\Users\\DefaultAccount\\CityTireTimeClock_1。 0.0.0_x86_x64_arm_Debug.appxbundle");
Debug.WriteLine(" else Install Package");
await packageManager.AddPackageAsync
(packageUri,null,DeploymentOptions.ForceApplicationShutdown);
}
}
我放在路径下的第一个版本:C:\ Data\Users \DefaultAccount。
我放在路径下的更新包: C:\ Data \ Users\DefaultAccount\updateTest。
确保添加包管理功能:
xmlns:rescap = " HTTP://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces =" uap mp iot rescap">
// ... ...
< rescap:Capability Name =" packageManagement" />
如果有帮助请告诉我。
祝你好运,
Rita
Hello,
I am planning to install Application using background application (UWP). my code looks like this:
{
Debug.WriteLine("Install Package");
string fullNamePackage = "cd08eb5f-bd86-4694-96c8-5d8e9fb32eed_jfasm645wnjtr";
var packageManager = new PackageManager();
var packages = packageManager.FindPackagesForUser(string.Empty).ToList();
Debug.WriteLine("packages :"+ packages[0]);
Uri packageUri = new Uri("C:\\Users\\mahes\\CityTireTimeClock_1.0.2.0_ARM_Debug.appx");
var updateInsteadOfInstall = packages.Any(p => p.Id.FullName == fullNamePackage);
if (updateInsteadOfInstall)
{
Debug.WriteLine(" update Install Package");
Hello mahesh_Pochamreddy,
>>>I am planning to install Application using background application (UWP)
So I assume you running the background application on Windows IoT Core device. While on Windows IoT Core there is on such path: C:\Users. The right path will be C:\Data\Users.
>>>Exception thrown: 'System.Exception' in System.Private.CoreLib.dll
WinRT information: error 0x80070003: Opening the package from locationThis error caused by the invalid file path like I said above.
>>>string fullNamePackage = "cd08eb5f-bd86-4694-96c8-5d8e9fb32eed_jfasm645wnjtr";
The full package name contains version information like this: db0c5c3b-d107-435a-a257-a26fa8f966d2_1.0.0.0_arm__a48w6404kk2ea.
The following code works for me. You can have a try:
private static async Task InstallPackageAsync() { Debug.WriteLine("Install Package"); string fullNamePackage = "db0c5c3b-d107-435a-a257-a26fa8f966d2_1.0.0.0_arm__a48w6404kk2ea"; var packageManager = new PackageManager(); var packages = packageManager.FindPackagesForUser(string.Empty).ToList(); Debug.WriteLine("packages :" + packages[0]); var updateInsteadOfInstall = packages.Any(p => p.Id.FullName == fullNamePackage); if (updateInsteadOfInstall) { Uri packageUri = new Uri("C:\\Data\\Users\\DefaultAccount\\updateTest\\CityTireTimeClock_1.0.1.0_x86_x64_arm_Debug.appxbundle"); Debug.WriteLine(" update Install Package"); var result = await packageManager.UpdatePackageAsync (packageUri, null, DeploymentOptions.ForceApplicationShutdown); } else { Uri packageUri = new Uri("C:\\Data\\Users\\DefaultAccount\\CityTireTimeClock_1.0.0.0_x86_x64_arm_Debug.appxbundle"); Debug.WriteLine(" else Install Package"); await packageManager.AddPackageAsync (packageUri, null, DeploymentOptions.ForceApplicationShutdown); } }
The first version I put under path: C:\Data\Users\DefaultAccount.
The update package I put under path: C:\Data\Users\DefaultAccount\updateTest.
Make sure add package management capability:
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" IgnorableNamespaces="uap mp iot rescap"> //... <rescap:Capability Name="packageManagement" />Please let me know if it helps.
Best regards,
Rita
这篇关于实现packageManager.AddPackageAsync时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!