从树莓派上的 USB 驱动器更新 uwp 应用程序 [英] update uwp app from usb drive on raspberry pi

查看:18
本文介绍了从树莓派上的 USB 驱动器更新 uwp 应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在 Visual Studio 2017 中创建的通用 Windows 应用程序.我已经在我的树莓派上部署了这个应用程序,它运行良好.我还使用 2017 创建了一个包.我想向我的应用程序添加一个更新按钮,按下它时它会寻找一个 USB 记忆棒并检查一个文件.我看到这个文件它会更新应用程序,就像它正在寻找商店更新一样.本机未连接到互联网,仅供内部使用.但是,我想确保我可以更新这些或提供一个带有更新的 U 盘,以便同事可以更新它.

I have a Universal Windows App I created in visual studio 2017. I have deployed this app on my raspberry Pi and it is running good. I also have create a package using 2017. I want to add an update button to my app and when pressed it would look for a USB stick and check for a file. I it sees this file it will update the app just as if it was looking to the store to update. This unit has no connection to the internet and is for internal use only. But, I want to make sure that I can update these or give a USB stick with the update on it so a colleague can update it.

我不知道如何做到这一点,或者是否可能.非常感谢任何帮助.

I have no idea how to do this or if it is possible. Any assistance is greatly appreciated.

推荐答案

我想向我的应用程序添加一个更新按钮,按下它就会寻找 U 盘并检查文件.

I want to add an update button to my app and when pressed it would look for a USB stick and check for a file.

packagemanager.UpdatePackageAsync API 可以帮助您在 UWP 应用中执行此操作并自行更新.

The packagemanager.UpdatePackageAsync API can help you do this in your UWP app and update itself.

但您不能像在桌面上通过 FilePicker 那样简单地查找 U 盘并检查文件",而 Windows IoT Core 不支持.这里我展示了一个示例来指定文件位置和版本然后更新它.

But you can't simply "look for a USB stick and check for a file" like you can do on the desktop via FilePicker that not supported on Windows IoT Core. Here I show a sample to specify the file location and version then update it.

要使用此 API,您需要在 Package.appxmanifest 中添加 packageManagement 功能,如下所示:

To use this API you need to add the packageManagement capability in Package.appxmanifest like the followings:

...   
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities" 

IgnorableNamespaces="uap mp rescap">

...

  <Capabilities>
    <rescap:Capability Name="packageManagement" />
  </Capabilities>

有一个代码示例可以参考:

There is a code sample you can reference:

MainPage.xaml

<StackPanel VerticalAlignment="Center">
    <Button Content="Update" Click="Button_Click"/>
    <TextBox Name="NewVersion" PlaceholderText="For example: 1.0.5.0"/>
    <TextBox Name="PkgPath" PlaceholderText="For example: D:AppUpdate"/>
    <TextBlock Text="Install result: " Name="Result" />
</StackPanel>

MainPage.xaml.cs

    private async void Button_Click(object sender, RoutedEventArgs e)
    {
        try
        {
            string versionNum = NewVersion.Text;
            string packagePath = PkgPath.Text; 
            string packageLocation = packagePath + @"TestAppUpdate_" + versionNum + "_x86_x64_arm_Debug.appxbundle";
            PackageManager packagemanager = new PackageManager();
            await packagemanager.UpdatePackageAsync(new Uri(packageLocation), null, DeploymentOptions.ForceApplicationShutdown);
        }
        catch (Exception ex)
        {
            Result.Text = ex.Message;
        }
    }

应用将更新并自动重启到新版本.

The app will update and auto restart to the new version.

这篇关于从树莓派上的 USB 驱动器更新 uwp 应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆