如何将.appx部署到Windows Phone 8.1中

时间:2014-10-10 16:06:39

标签: windows-phone-8.1 connectivity smart-device-framework

我使用Microsoft.SmartDevice.Connectivity连接到Windows Phone 8.1操作系统,其中包含以下链接中的说明:connect to windows phone 8 using console application
现在我可以连接到Windows Phone 8.1模拟器或Windows Phone 8.1设备,我可以使用他们的ProductID启动任何应用程序。
所以现在我想通过使用这个框架来安装我开发给这些设备的应用程序。我知道WP8.1的XAP包是一个.appx文件。要在此框架中安装1个应用程序,我使用InstallApplication()方法,如下所示:

 IRemoteApplication remoteApplication = iDevice.InstallApplication(appID, appID, applicationGenre, iconPath, xapPackage);

哪个appID是ProductID,我在Package.appxmanifest页面中得到它是:
556ee9d4-5640-4120-9916-44b1ca27352f
但我得到的例外是:

"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提供的应用程序部署工具时,可以安装此应用程序,但是当我使用连接框架时,我无法安装它。
那么如何使用连接框架安装此应用程序?
 请帮我。谢谢你的帮助。

1 个答案:

答案 0 :(得分:6)

是的,SmartDevice.Connectivity的AFAIK v11无法部署APPX。您需要V12才能部署APPX。即使部署WP8.1 APPX的工具与部署WP7-WP8.0 XAP的工具不同,API也是如此不同。

XAP deployment tool vs. 8.1 APPX deployment tool

无论如何,您可以使用此C#代码部署Windows Phone 8.1 APPX:

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已在我的机器上成功部署,一切正常,应用程序按预期安装。

Foo Bar Baz Test app successfully installs

如果您希望通过Windows Phone 8.1仿真器/设备自动化(在SD卡上安装,删除,企业安装等)获得更好的体验,您可以使用不同的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,
  }
}

Works on my machine