8

I am looking for a more userfriendly way to make an installer for my UWP Application. I don't want to distribute through the store and I am aware that you need to set the developer setting to enable sideloading of applications.

Is it possible, in C#, to mimic the execution of the PowerShell script which deploys an appx package into the system? And if so, how does this work when you want to update the appx package instead of a new install?

It seems a bit weird for my users to have to execute a powershell script by hand to install an application. So I would like to create an installer instead.

EDIT: to elaborate, I am looking for a way in C# to install an appx package. I don't want to use any command line / external tools

Thanks

WJM
  • 1,137
  • 1
  • 15
  • 30
  • 1
    Possible duplicate of [Deploy Windows Apps to Family and Friends without store, enterprise or development-tools](http://stackoverflow.com/questions/33017016/deploy-windows-apps-to-family-and-friends-without-store-enterprise-or-developme) – Joshua Shearer Oct 28 '15 at 19:15
  • Hi Joshua, I am looking for a way to mimic the functionality which is mentioned in your link, but in C# – WJM Oct 28 '15 at 19:18
  • Will it suffice if you just execute the powershell script *via* your C# code? – Joshua Shearer Oct 28 '15 at 19:20
  • Yes I think so, if it also allows the user to update an appx package and for the installer to get error information if the powershell script failed for some reason – WJM Oct 28 '15 at 19:23
  • So the trivial google query is "run powershell script from c#". Looky there, that first hit tells you exactly what to do. – Hans Passant Oct 28 '15 at 19:31

2 Answers2

7

You can install an appx package from code with the Windows.Management.Deployment.PackageManager object's AddPackageAsync method. This is demonstrated for C++ and C# in the Add app package sample on MSDN.

To update an existing package call PackageManager.UpdatePackageAsync

Rob Caplan - MSFT
  • 21,714
  • 3
  • 32
  • 54
  • Thanks Rob. Is this only accessible through a UWP? Or can I access this from WPF also? – WJM Nov 01 '15 at 00:03
  • It is available only from desktop apps (such as WPF). It is not available to Windows Store apps – Rob Caplan - MSFT Nov 01 '15 at 00:06
  • Do I have to make a reference to System.Runtime and Windows.Management.Deployment through the TargetPlatformVersion adjustment in the VS project file? The class does not seem accessible just by trying to find the right reference in VS. – WJM Nov 01 '15 at 01:21
  • Does this apply to UWP (Windows IoT-Core RaspberryPi)? I guess it should, but? Alternatively, is the a way to simply start the Add-AppxDevPackage.ps1 -Force script on the IoT-Core device from a headless app running on the device? – GGleGrand Jan 16 '16 at 17:49
  • Still looking for a way to do this with UWP! – GGleGrand May 06 '16 at 20:34
  • Hi Rob, thanks for your answer but the sample is not found. i am not sure what type of project or script should i create to manage UWP packages. Is this similar to App Installer that comes with UWP? – Ali123 Jun 03 '20 at 07:59
  • can anyone support me with this? any documentation will be highly appreciated. – Ali123 Jul 07 '20 at 09:12
3

Microsoft has now adds its own graphical installer. You can simply double click the appxbundle file.

If you use a self signed cert it must be set as trusted in the system. The cer file is also in the zip archive with is created by Visual Studio.

blacksheep_2011
  • 1,083
  • 3
  • 11
  • 22
  • will this work if powershell is disabled by the admin? We are allowed to install apps like .exe but access to powershell is not allowed. – Ali123 Jun 03 '20 at 07:54
  • does anyone know if this works without admin access or powershell? i am getting the following error Appinstaller operation failed with error code 0x80190191. Detail: Unauthorized – Ali123 Jul 07 '20 at 09:13