Skip to content

Instantly share code, notes, and snippets.

@FrayxRulez
Last active August 28, 2016 23:58
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save FrayxRulez/f23672d5fbbe6b89cba2 to your computer and use it in GitHub Desktop.
Save FrayxRulez/f23672d5fbbe6b89cba2 to your computer and use it in GitHub Desktop.
Deploy UWP apps to Windows 10 Mobile
// Initializes MultiTargetingConnectivity with current PC culture
var connectivity = new MultiTargetingConnectivity(Thread.CurrentThread.CurrentUICulture.LCID);
var devices = connectivity.GetConnectableDevices();
// Gets the first physical device attached to PC.
// WARNING: if more than a single device is connected to the PC deploy will fail.
var phone = devices.FirstOrDefault(x => !x.IsEmulator());
// PhoneProductId of the app, you can find it in your Package.appxmanifest
var package = Guid.Parse("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX");
var device = phone.Connect(true);
try
{
// If application is already installed simply uninstall it.
if (device.IsApplicationInstalled(package))
{
device.GetApplication(package).Uninstall();
}
}
catch { }
try
{
// Installs the app to the device.
// Parameters are:
// Guid productId = PhoneProductId
// Guid instanceId = PhoneProductId
// string applicationGenre = "32", that means "Sideload"
// string iconPath = "2" if the package extension is "appx"
// string xapPackage = absolute path of the package
var app = device.InstallApplication(package, package, "32", "2", full_path_to_the_file);
}
finally
{
// Disconnect to the current device.
// IMPORTANT: call this method or you have to reboot the phone to apply changes.
device.Disconnect();
}
@FrayxRulez
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment