Compartir a través de


Extend your application using Optional Packages

What is an optional package?

So you have a Universal Windows App. Over a period of time you added more and more functionality to the app. Now instead of bloating your base app, wouldn’t it be awesome if you could ship another app(s) that seamlessly plugs into your base app giving you the ability to componentize your Universal app? For example, let's say that you built a Piano app that lets users play their favorite tunes on their tablet or phones. Over time, you might want to add more functionality for example, add a song pack that let's users learn to play popular songs. Being able to customize that list of songs outside of your primary app and being able to monetize that separately would be awesome, right! Now you might think, well I could use other means to distribute a song pack such as your website, but what if there was a way to separate content out into its own appx package that gives you the benefit of being able to distribute it via the Windows Store or your choice of distribution and the Windows platform knows how to install the package and offers users a first class way to manage content on their device via Settings, so you can focus on building your app and getting the content ready. If you are trying to do this, componentizing portions of your base app into optional packages could be your solution!

Now you may be thinking about another UWP technology to extend your application - app extensions. The key difference is the level of trust. App extensions are meant for 3rd parties to build add-on experiences to your application which you may not trust fully. With optional packages the trust model is very different. The optional packages that you build all run with the identity of your base app. This makes it possible to load content from your optional packages in the process of your base app, making it very performant. Also optional packages is not just for content, you also have the ability to code in-proc!

In terms of distribution, given this is a separate package, you can license the app separate from your main app making this a great way to monetize your suite of apps. The platform also exposes APIs that allow you to download optional packages from within your app making it possible to provide an in-app purchase experience. Users are in control of the optional packages and can manage the optional packages i.e. uninstall them or move them to a separate drive via the Storage settings. Since optional packages is really part of your main application, uninstalling the main application also uninstalls the related optional packages.

What are the different scenarios where you would consider creating an optional package?

Loading Content

Back to our piano app example, distributing the song pack as an optional packages makes sense as you want to load the songs in your base app process giving you the ability to synchronize two audio channels in a performant way. As the base app and optional all have the same identity, your app has full access to the contents of the optional package as though the app is accessing files from its own install location making the interaction seamless.

Loading code & Related Sets

Let's say that now you want to add another feature to your piano app - a music synthesizer giving users the ability to modulate piano tones to create funky music! Optional packages let's you do that! You can load code from an optional package and load it in the main app process. If you are trying to load code out of an optional packages however, the platform requires a strict versioning between the main app and its optional packages we call this related sets. We will cover the specifics of how to define this tight relationship in an up coming blog but if you do not do this, you cannot load code from an optional package. If your main and optional packages are in a related set, the platform will enforce this relationship while it installs and updates the packages, ensuring that the versioning that you defined is always true. To illustrate, in the diagram below, your piano app and the music synthesizer are part of a related set and this lets you define a tight versioning construct that you may have when you need to load code. The content only song pack remains untouched and continues to work with your piano app.

 

atomicupdate

Note that optional package cannot be managed code in the current release and has to be native code due to a .Net limitation. The related sets is not limited to just code optional packages. You can also decide that you have content optional packages that must be in sync with the main application.

Optional Packages targeting multiple apps

You can also produce optional packages that work with more than one main application. This is limited to content only optional packages. Back to the piano app example, you can make your song pack optional package work with another base app that you could build - for example a  guitar app!

Cross Publisher Scenarios

Taking this a step further the platform supports the ability for the optional package and base package to be from different publishers if you want to co-develop with other publishers. I want to high light that these are publishers that you trust and the base app controls what optional packages it works with as you are loading content/ code in proc. 

 

Optional packages are hence an amazing way for you to componentize your app. To drive users to your optional packages, you can build an in app install experience. For the Windows Store, the platform exposes StoreContext.RequestDownloadAndInstallStorePackagesAsync that lets you enumerate optional packages that are on the Store and install them. If you are installing optional packages deployed on http or a UNC file share, you can use PackageCatalog.AddOptionalPackageAsync()

Note that Optional packages is only open to a managed list of partners on the Windows Store today, however these scenarios are fully supported for sideloading or line of business apps! 

Related topics

Check out the following links for more advanced topics

Sandeep George
Senior Program Manager

Comments

  • Anonymous
    April 05, 2017
    Glad to see that UWP is finally evolving to enable scenarios like this.
    • Anonymous
      April 11, 2017
      Thank you Iuri! We look forward to working with you on your scenario.
  • Anonymous
    April 09, 2017
    can you shed more light as to why Optional Packages "cannot be managed code" .. What limitations in .NET is causing this ?! I would love to drive attention to the relevant .NET teams in GitHub to fix this This is critical for managed projects to have first class support in optional packages!!!
    • Anonymous
      April 11, 2017
      Thank you for reading! All Store apps are compiled via .Net Native and hence is the default build chain when you build your app locally in release mode - see https://msdn.microsoft.com/en-us/library/dn584397(v=vs.110).aspx. Since the app is precompiled, all the referenced dlls must be available at compile time and are statically linked. Optional packages by design can have dlls that are only loaded at run time, hence we have this issue. We are working with the .NET teams to have a solution for this problem.
  • Anonymous
    May 08, 2017
    This is great, where is the next blog where you cover how to get started and build an optional package?
    • Anonymous
      May 09, 2017
      Hey Dan,Happy to see you're excited about Optional Packages! The next blog should be coming out soon (within the next week or so).Stay tuned!Thanks,Jason
      • Anonymous
        May 10, 2017
        Thanks Jason!
  • Anonymous
    December 05, 2017
    Is there any way to utilize optional sets to "bundle" separate apps together? We have a suite of apps (some paid, some free) that stand on their own, but we'd like to be able to bundle them together to make the acquisition experience easier for our users.But the way optional packages seem to be presented is more like an add-on, so am I correct in assuming an add-on can't also be a standalone app?
    • Anonymous
      December 05, 2017
      Hello Tyler. Yes optional packages are more similar to add-ons. For bundling apps together, the Windows Store may have a feature in one of the upcoming releases to do what you are asking for. I have forwarded your ask to a colleague who will reach out to you about this.
  • Anonymous
    February 15, 2018
    I would like to ask how to set a content only optional package manifest to target multiply apps?The MainPackageDependency allows only to specify one package.
    • Anonymous
      February 20, 2018
      This is available in the uap4 namespace
      • Anonymous
        August 08, 2018
        Is this feature released? - while I can not find it in the uap4 namespace