Removing Optional Packages


Optional packages provide a great way to componentize and distribute pieces of your application as separate entities allowing users to pick parts of your application to install. So how does a user remove these optional packages once installed? If your optional package has an entry in the AppList, well then users can right click and uninstall the optional packages like they uninstall other apps. Uninstalling the main application would remove its optional packages as well.  But if your optional package does not have an entry in the AppList, for example in the case of a content only optional package, then users would have to drill into 'Apps and Features' settings and click on Advanced options to manage the optional packages.

 

We received feedback from our developers that the apps would like to provide a removal experience from within the app itself. For example, there is shiny new content available for the app but the user does not have enough disk space for new content. So the app would like to allow the user to  remove old content and then download new content.

With the Fall Creators Update SDK (10.0.16229.0) , I am excited to announce that we added a new API RemoveOptionalPackageAsync where you can pass in a list of optional packages that need to be removed.

Here is a code snippet.

    PackageCatalog catalog = PackageCatalog.OpenForCurrentPackage();
    List<string> optionalList = new List<string>();
    optionalList.Add("FabrikamAgeAnalysis_kwpnjs8c36mz0");
    
    //Warn user that application will be restarted.
    var result = await catalog.RemoveOptionalPackagesAsync(optionalList);
    if(result.ExtendedError != null)
    {
        throw removalResult.ExtendedError;
    }

Note: In the case of a related set the platform will need to restart your main application to finalize the removal to avoid situations where your app has content that is loaded from the package you are removing. Your apps must notify the users that the application will need to be restarted before you app calls the API.

However, if your optional package is content only then, you should explicitly tell the platform that the package you are about to remove is 'not in use' by your application before you remove the optional package. This also allows you to remove the package without a restart.

Here is a snippet of how you should uninstall a content only optional package.

    //check if optional package is installed first
    var currentAppPackage = Windows.ApplicationModel.Package.Current;
    foreach (var package in currentAppPackage.Dependencies)
    {
        if (package.IsOptional && package.Id.FamilyName.Contains("FabrikamFaceFilters"))
        {
            await package.SetInUseAsync(false);
        }
    }

    PackageCatalog catalog = PackageCatalog.OpenForCurrentPackage();
    List<string> optionalList = new List<string>();
    optionalList.Add("FabrikamFaceFilters_kwpnjs8c36mz0");

    var result = await catalog.RemoveOptionalPackagesAsync(optionalList);
    if(result.ExtendedError != null)
    {
        throw removalResult.ExtendedError;
    }

 

Let us know what you think!

Cheers,
Sandeep George
Senior Program Manager

Comments (0)

Skip to main content