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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…