问题描述
我使用 Microsoft.SmartDevice.Connectivity 按照以下链接中的说明连接到 Windows Phone 8.1 操作系统:使用控制台应用程序连接到 windows phone 8
现在我可以连接到 Windows Phone 8.1 模拟器或 Windows Phone 8.1 设备,我可以使用它们的 ProductID 启动任何应用程序.
所以现在我想使用这个框架将我开发的应用程序安装到这些设备上.我知道 WP8.1 的 XAP 包是一个 .appx 文件.要在此框架中安装 1 个应用程序,我使用 InstallApplication() 方法,如下所示:
I use the Microsoft.SmartDevice.Connectivity to connect to Windows Phone 8.1 OS with the instruction in this link: connect to windows phone 8 using console application
Now I can connect to both Windows Phone 8.1 Emulator or Windows Phone 8.1 Device, and I can launch any application by using their ProductID.
So now I would like to install my apps which I developed to these device by using this framework. I know that the XAP package for WP8.1 is an .appx file. To install 1 apps in this framework I use the InstallApplication() method like this:
IRemoteApplication remoteApplication = iDevice.InstallApplication(appID, appID, applicationGenre, iconPath, xapPackage);
哪个appID是ProductID,我在Package.appxmanifest页面得到的是:556ee9d4-5640-4120-9916-44b1ca27352f
但我得到的例外是:
Which appID is the ProductID, I got it in the Package.appxmanifest page is: 556ee9d4-5640-4120-9916-44b1ca27352f
But I got the exception is:
"An unhandled exception of type 'Microsoft.SmartDevice.Connectivity.SmartDeviceException' occurred in Microsoft.Smartdevice.Connectivity.dll
Additional information: An attempt was made to move the file pointer before the beginning of the file."
当我使用Visual Studio提供的应用部署工具时,可以安装这个应用,但是当我使用连接框架时,我无法安装它.
那么如何使用 Connectivity Framework 安装此应用程序?
请帮我.感谢您的帮助.
When I use the Application Deployment tool provided by Visual Studio, this app can be installed, but when I use connectivity framework, I can't install it.
So how can I install this app by using Connectivity Framework?
Please help me. Thank you for your help.
推荐答案
是的,SmartDevice.Connectivity 的 AFAIK v11 将无法部署 APPX.您需要 V12 才能部署 APPX.API 是如此不同,即使部署 WP8.1 APPX 的工具是一种与部署 WP7-WP8.0 XAP 的工具不同的工具.
Yeah, AFAIK v11 of SmartDevice.Connectivity won't be able to deploy APPX. You'll need V12 to deploy APPX. The APIs are so different even the tool to deploy WP8.1 APPX is a different tool then the one to deploy WP7-WP8.0 XAPs.
无论如何,您可以使用以下 C# 代码部署 Windows Phone 8.1 APPX:
Anyway, you can deploy a Windows Phone 8.1 APPX using this C# code:
static void Main(string[] args)
{
// step #1: Add refrences.
// - Add DLL reference to: C:\Program Files (x86)\Microsoft SDKs\Windows Phone\v8.1\Tools\AppDeploy\Microsoft.Phone.Tools.Deploy.dll
// GAC references are implicit on computers with VS2013/VS2014 installed alongside WP8.1 dev tools.
// - GAC reference to: Microsoft.Phone.Tools.Common, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
// - GAC reference to: Microsoft.SmartDevice.Connectivity.Interface, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
// - GAC reference to: Microsoft.SmartDevice.MultiTargeting.Connectivity, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
try
{
// Step #2: Get devices
var devices = Utils.GetDevices();
Console.WriteLine("Possible Devices for deployment: ");
foreach (var deviceInfo in devices)
{
Console.WriteLine("\t" + deviceInfo.ToString());
}
// Step #3: choose a device
var device = devices.FirstOrDefault(d => d.ToString() == "Emulator 8.1 1080P 6 inch");
if (device == null)
return;
Console.WriteLine("Using device: " + device.ToString());
// step #4: Select XAP, DeploymentOptions and Manifest
string appxFileUri = @"D:\Users\Justin Angel\Documents\Visual Studio 2013\Projects\App15\App15\AppPackages\App15_1.1.0.0_AnyCPU_Test\App15_1.1.0.0_AnyCPU.appx";
IAppManifestInfo manifestInfo = Utils.ReadAppManifestInfoFromPackage(appxFileUri); ;
DeploymentOptions deploymentOptions = DeploymentOptions.None;
// Step #5: deploy
Console.WriteLine("Attempting to deploy: " + manifestInfo.Name + " from " + appxFileUri);
Utils.InstallApplication(device, manifestInfo, deploymentOptions, appxFileUri);
Console.WriteLine("deployed successfully");
}
catch (Exception ex)
{
Console.WriteLine("Failed to deploy");
}
Console.ReadKey();
}
当我尝试运行此程序时,APPX 已成功部署在我的机器上,一切正常,并且应用程序已按预期安装.
When I try to run this the APPX is successfully deployed on my machine everything works fine and the app is installed as expected.
如果您想更熟练地使用 Windows Phone 8.1 模拟器/设备自动化(在 SD 卡上安装、删除、企业安装等),您可以使用不同的部署选项:
If you want to get fancier with Windows Phone 8.1 Emulator/Device automation (install on SD card, delete, enterprise installation, etc), you can play around with different DeploymentOptions:
namespace Microsoft.Phone.Tools.Deploy
{
[Flags]
public enum DeploymentOptions
{
None = 0,
PA = 1,
Debug = 2,
Infused = 4,
Lightup = 8,
Enterprise = 16,
Sideload = 32,
TypeMask = 255,
UninstallDisabled = 256,
SkipUpdateAppInForeground = 512,
DeleteXap = 1024,
InstallOnSD = 65536,
OptOutSD = 131072,
}
}
这篇关于如何将 .appx 部署到 Windows Phone 8.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!