Share via


PackageCatalog.OpenForPackage(Package) Method

Definition

Allows listening to any Package and its dependents (optional, resource, and hostRuntime).

public:
 static PackageCatalog ^ OpenForPackage(Package ^ package);
 static PackageCatalog OpenForPackage(Package const& package);
public static PackageCatalog OpenForPackage(Package package);
function openForPackage(package)
Public Shared Function OpenForPackage (package As Package) As PackageCatalog

Parameters

package
Package

The Package which will be monitored for notifications.

Returns

The PackageCatalog used to listen for deployment notifications.

Windows requirements

Requirements Description
Device family
Windows 11 Insider Preview (introduced in 10.0.23504.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v15.0)
App capabilities
packageManagement packageQuery

Examples

This example uses the OpenForPackage method to listen to notifications on the current package (Package.Current). The event handler acts on any optional package that has finished updating.

void RegisterForDeploymentNotifications()
{
    if (catalog == null)
    {
        catalog = PackageCatalog.OpenForPackage(Package.Current);
        catalog.PackageUpdating += OptionalPackageUpdatingCallback;
    }
}

void OptionalPackageUpdatingCallback(object sender, PackageUpdatingEventArgs args)
{
    if (args.IsComplete && args.TargetPackage.IsOptional)
    {
        // Let the user know the Optional package has updated, and can be used now
        var messageDialog = new MessageDialog(args.TargetPackage.DisplayName + 
                        " has been updated. Please restart the app to enjoy our latest features.");
    }
}

Remarks

OpenForPackage allows a package to listen to deployment notifications for another package and its dependents (like PWAs).

In terms of capability requirements, OpenForPackage requires that the caller has either the packageQuery or the packageManagement capability; or else that the caller has integrity level (IL) greater than or equal to Medium; or else that the caller's process has the same package family as the target package.

Applies to

See also