TryCreatePackageDependency function (appmodel.h)
Creates an install-time reference for a framework package dependency for the current app, using the specified package family name, minimum version, and additional criteria.
HRESULT TryCreatePackageDependency( PSID user, PCWSTR packageFamilyName, PACKAGE_VERSION minVersion, PackageDependencyProcessorArchitectures packageDependencyProcessorArchitectures, PackageDependencyLifetimeKind lifetimeKind, PCWSTR lifetimeArtifact, CreatePackageDependencyOptions options, PWSTR *packageDependencyId );
The user scope of the package dependency. If NULL, the caller's user context is used. Must be NULL if CreatePackageDependencyOptions_ScopeIsSystem is specified.
The package family name of the framework package on which to take dependency.
The minimum version of the framework package on which to take dependency.
The processor architectures of the package dependency.
The type of artifact to use to define the lifetime of the package dependency. For more information, see the remarks.
The name of the artifact used to define the lifetime of the package dependency. Must be NULL if the lifetimeKind parameter is PackageDependencyLifetimeKind_Process. For more information, see the remarks.
The options to apply when creating the package dependency.
When this method returns, contains the address of a pointer to a null-terminated Unicode string that specifies the ID of the new package dependency. The caller is responsible for freeing this resource once it is no longer needed by calling HeapFree.
If the function succeeds it returns ERROR_SUCCESS. Otherwise, the function returns an error code. The possible error codes include the following.
|E_INVALIDARG||The packageDependencyId parameter is NULL on input.|
In your app's installer or during the first run of your app, call this method to specify a set of criteria for a framework package you want to use in your app. This informs the OS that your app has a dependency upon a framework package that meets the specified criteria. If one or more framework packages are installed that meet the criteria, Windows will ensure that at least one of these framework packages will remain installed until the install-time reference is deleted. For more information, see Use the dynamic dependency API to reference framework packages at run time.
This function fails if the specified dependency criteria cannot be resolved to a specific package. This package resolution check is skipped if CreatePackageDependencyOptions_DoNotVerifyDependencyResolution is specified for the options parameter. This is useful for installers running as user contexts other than the target user (for example, installers running as LocalSystem).
|Minimum supported client||Windows 11 (introduced in 10.0.22000.0)|