How to deploy an .appx into Windows Phone 8.1

北战南征 提交于 2019-12-06 13:17:55

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,
  }
}

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!