AddPackageDependency function (appmodel.h)

Adds a run-time reference for the framework package dependency you created earlier by using the TryCreatePackageDependency method, with the specified options. After this method successfully returns, your app can activate types and use content from the framework package.

Syntax

HRESULT AddPackageDependency(
  PCWSTR                      packageDependencyId,
  INT32                       rank,
  AddPackageDependencyOptions options,
  PACKAGEDEPENDENCY_CONTEXT   *packageDependencyContext,
  PWSTR                       *packageFullName
);

Parameters

packageDependencyId

Type: PCWSTR

The ID of the package dependency to be resolved and added to the invoking process' package graph. This parameter must match a package dependency defined by using the TryCreatePackageDependency function for the calling user or the system (via the CreatePackageDependencyOptions_ScopeIsSystem option), or else an error is returned.

rank

Type: INT32

The rank to use to add the resolved package to the caller's package graph. For more information, see the remarks.

options

Type: AddPackageDependencyOptions

The options to apply when adding the package dependency.

packageDependencyContext

Type: PACKAGEDEPENDENCY_CONTEXT*

The handle of the added package dependency. This handle is valid until it is passed to RemovePackageDependency.

packageFullName

Type: PCWSTR*

When this method returns, contains the address of a pointer to a null-terminated Unicode string that specifies the full name of the package to which the dependency has been resolved. The caller is responsible for freeing this resource once it is no longer needed by calling HeapFree.

Return value

Type: HRESULT

If the function succeeds it returns ERROR_SUCCESS. Otherwise, the function returns an error code. The possible error codes include the following.

Return code Description
E_INVALIDARG The packageDependencyId or packageDependencyContext parameter is NULL on input.

Remarks

Calling this method resolves the framework package dependency to a specific package on the system. It also informs the OS that the framework package is in active use and to handle any version updates in a side-by-side manner (effectively delay uninstalling or otherwise servicing the older version until after your app is done using it). Package resolution is specific to a user and can return different values for different users on a system.

Each successful AddPackageDependency call adds the resolved package to the calling process' package graph, even if already present. There is no duplicate detection or filtering applied by the API (that is, multiple references from a package is not harmful). After resolution is complete, the package dependency stays resolved for that user until the last reference across all processes for that user is removed via RemovePackageDependency or the process is terminated.

After this method successfully returns, your app can activate types and use content from the framework package until RemovePackageDependency is called.

If multiple packages are present in the package graph with the same rank as the call to AddPackageDependency, the resolved package is (by default) added after others of the same rank. To add a package before others of the same rank, specify AddPackageDependencyOptions_PrependIfRankCollision for the options parameter.

For more information, see Use the dynamic dependency API to reference MSIX packages at run time.

Requirements

Requirement Value
Minimum supported client Windows 11 (introduced in 10.0.22000.0)
Header appmodel.h

See also

RemovePackageDependency

TryCreatePackageDependency

Use the dynamic dependency API to reference MSIX packages at run time