Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
773 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...