1

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.

Rita Han
  • 9,574
  • 1
  • 11
  • 24
PBSnake
  • 15
  • 6

1 Answers1

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.

Rita Han
  • 9,574
  • 1
  • 11
  • 24
  • Thank you for the detailed post. Seems pretty straight forward, I will try this out later today or tomorrow and get back to you on the results. Thanks again for your assistance on this its greatly appreciated. – PBSnake Dec 03 '18 at 16:07
  • OK, I had a chance to play with this. I'm really close , I create my app bundle and it has a new version number. I then copy the files to my USB drive and place it into the USB port of the Raspberry PI and I click my update button and I get the following message. "The provided package is already installed, and reinstallation of the package was blocked" – PBSnake Dec 03 '18 at 21:48
  • @PBSnake The error indicates that you are installing the same version with currently running one. Increase app version and try again. – Rita Han Dec 04 '18 at 01:05
  • @PBSnake Note that if the currently running version is you deployed from VS2017 the update operation will fail due to the running app is unpackaged app so you can't update with packaged one. So make sure the running one is also installed with packaged appxbundle. I did this via device portal. – Rita Han Dec 04 '18 at 01:11
  • I did increase the version number several times. I installed the version with the deploy option in visual studio. What is the proper way to do it? – PBSnake Dec 04 '18 at 02:37
  • @PBSnake The operation will fail if you want to update the app which deployed from Visual Studio. It can only update the app installed with packaged appxbundle. For example, you can install it via device portal, [here](https://learn.microsoft.com/en-us/windows/iot-core/develop-your-app/appinstaller#using-windows-device-portal) is a document you can reference. – Rita Han Dec 04 '18 at 03:16
  • Rita, I wanted to get back to you on this. I have it working, and I'm extremely thankful to you for your assistance. I'm very new and sometimes I don't even know the proper things to google. You quickly assisted me and pointed me to the right literature to assist me. If I could vote I would help you out. – PBSnake Dec 04 '18 at 17:39
  • Rita; Sorry to bother you again but I figured you may have a quick answer. Is there away to rollback to a previous version? With what I have it wont let me. I have it upgrading great but if for some reason they upgrade and there's problems that were missed I thought it would be nice to go back to last version until we can resolve it. – PBSnake Dec 07 '18 at 20:46
  • @PBSnake If you have previous version copy you have a try. Ref: ["Using version numbering to roll back to a previously-shipped package for new acquisitions"](https://learn.microsoft.com/en-us/windows/uwp/publish/package-version-numbering#using-version-numbering-to-roll-back-to-a-previously-shipped-package-for-new-acquisitions) and ["Is there a way for a customer of a UWP app to rollback to a previous version?"](https://stackoverflow.com/questions/35468127/is-there-a-way-for-a-customer-of-a-uwp-app-to-rollback-to-a-previous-version) – Rita Han Dec 10 '18 at 02:05
  • Rita;I'm back as you know I have this all working like a charm. This is a industrial application and we only have one App and we never want IoT to update. With that being said we turned the unified write filter on to clean up boot problems. We would like to still have our app update from a usb stick. I beleive I have all the exclusions added for the files. However i think windows adds a couple of registry entries? How could I find what they are so I could exclude them| – PBSnake Sep 13 '19 at 18:05