update uwp app from usb drive on raspberry pi

99封情书 提交于 2019-11-28 10:59:21

问题


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.


回答1:


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.

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

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.

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.



来源:https://stackoverflow.com/questions/53585879/update-uwp-app-from-usb-drive-on-raspberry-pi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!