问题
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);
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."
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.
回答1:
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.
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();
}
When I try to run this the APPX is successfully deployed on my machine everything works fine and the app is installed as expected.
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,
}
}
来源:https://stackoverflow.com/questions/26303604/how-to-deploy-an-appx-into-windows-phone-8-1