从树莓派上的USB驱动器更新uwp应用 [英] update uwp app from usb drive on raspberry pi
问题描述
我有一个在Visual Studio 2017中创建的通用Windows应用程序.我已将此应用程序部署在我的树莓派上,并且运行良好.我还使用2017创建了一个程序包.我想向我的应用程序添加一个更新按钮,当按下该按钮时,它将查找USB记忆棒并检查文件.我看到该文件将更新应用程序,就像正在寻找商店进行更新一样.本机没有互联网连接,仅供内部使用.但是,我想确保可以更新这些文件,或者提供带有更新的USB记忆棒,以便同事可以对其进行更新.
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.
推荐答案
我想在我的应用程序中添加一个更新按钮,当按下它时, 寻找USB记忆棒并检查文件.
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.
但是您不能像在Windows IoT核心版上不支持的FilePicker那样简单地寻找USB记忆棒并检查文件".在这里,我显示了一个示例来指定文件位置和版本,然后对其进行更新.
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屋!