PackageManager.AddPackageAsync Method

Definition

Overloads

AddPackageAsync(Uri, IIterable<Uri>, DeploymentOptions)

Adds a Package (the main package) and its dependency packages for the current user, using the specified deployment options.

AddPackageAsync(Uri, IIterable<Uri>, DeploymentOptions, PackageVolume)

Adds a Package (the main package) and its dependency packages to the specified volume for the current user, using the specified deployment options.

AddPackageAsync(Uri, IIterable<Uri>, DeploymentOptions, PackageVolume, IIterable<String>, IIterable<Uri>)

Adds a Package and its dependency packages to the specified volume for the current user, using the specified deployment options.

AddPackageAsync(Uri, IIterable<Uri>, DeploymentOptions, PackageVolume, IIterable<String>, IIterable<Uri>, IIterable<Uri>)

Adds a Package (the main package) and its dependency packages for the current user, using the specified deployment options.

AddPackageAsync(Uri, IIterable<Uri>, DeploymentOptions)

Adds a Package (the main package) and its dependency packages for the current user, using the specified deployment options.

public:
 virtual IAsyncOperationWithProgress<DeploymentResult ^, DeploymentProgress> ^ AddPackageAsync(Uri ^ packageUri, IIterable<Uri ^> ^ dependencyPackageUris, DeploymentOptions deploymentOptions) = AddPackageAsync;
/// [Windows.Foundation.Metadata.Overload("AddPackageAsync")]
IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> AddPackageAsync(Uri const& packageUri, IIterable<Uri> const& dependencyPackageUris, DeploymentOptions const& deploymentOptions);
[Windows.Foundation.Metadata.Overload("AddPackageAsync")]
public IAsyncOperationWithProgress<DeploymentResult,DeploymentProgress> AddPackageAsync(System.Uri packageUri, IEnumerable<System.Uri> dependencyPackageUris, DeploymentOptions deploymentOptions);
function addPackageAsync(packageUri, dependencyPackageUris, deploymentOptions)
Public Function AddPackageAsync (packageUri As Uri, dependencyPackageUris As IEnumerable(Of Uri), deploymentOptions As DeploymentOptions) As IAsyncOperationWithProgress(Of DeploymentResult, DeploymentProgress)

Parameters

packageUri
Uri Uri

The Uri of the package to add. The URI must follow the file URI scheme (file://) since the only supported URI schemes are local file paths and local network paths.

dependencyPackageUris

IIterable<Uri>

IEnumerable<Uri>

The Uris of the dependency packages to add. If there are no dependency packages or if the dependency packages are already registered, this parameter can be null.

deploymentOptions
DeploymentOptions

A bitwise combination of enumeration values from the DeploymentOptions enumeration. ForceApplicationShutdown and None are the only valid options for this method. Specifying any other option results in an E_INVALIDARG return value.

Returns

IAsyncOperationWithProgress<DeploymentResult,DeploymentProgress>

The status of the deployment request. The DeploymentResult contains the final returned value of the deployment operation, once it is completed. The DeploymentProgress can be used to obtain the percentage of completion over the entire course of the deployment operation.

Attributes

Windows requirements

App capabilities
packageManagement

Examples

The following example uses the PackageManager.AddPackageAsync method to install a package that has no dependencies or whose dependencies are already installed. Note that the path of the main package is passed as an argument in the example. AddPackageAsync returns an object that can be used to manage the asynchronous operation. The example uses the Completed property to set the delegate and checks the Status property to determine the status of the deployment operation. If the status is Error, the example calls the GetResults method to get additional error information.

using Windows.Foundation;
using Windows.Management.Deployment;

public static int Main(string[] args)
{
    string inputPackageUri = args[0];
    int returnValue=0;

    Uri packageUri = new Uri(inputPackageUri);            

    PackageManager packageManager = new PackageManager();

    IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> deploymentOperation = 
        packageManager.AddPackageAsync(
            packageUri, 
            null, 
            DeploymentOptions.None);

    // This event is signaled when the operation completes
    ManualResetEvent opCompletedEvent = new ManualResetEvent(false); 

    // Define the delegate using a statement lambda
    deploymentOperation.Completed = (depProgress, status) => { opCompletedEvent.Set(); };

    // Wait until the operation completes
    opCompletedEvent.WaitOne();

    // Check the status of the operation
    if (deploymentOperation.Status == AsyncStatus.Error)
    {
        DeploymentResult deploymentResult = deploymentOperation.GetResults();
        Console.WriteLine("Error code: {0}", deploymentOperation.ErrorCode);
        Console.WriteLine("Error text: {0}", deploymentResult.ErrorText);
        returnValue = 1;
    }
    else if (deploymentOperation.Status == AsyncStatus.Canceled)
    {
        Console.WriteLine("Installation canceled");
    }
    else if (deploymentOperation.Status == AsyncStatus.Completed)
    {
        Console.WriteLine("Installation succeeded");
    }
    else
    {
        returnValue = 1;
        Console.WriteLine("Installation status unknown");
    }

    return returnValue;
}

Also see Visual Studio support for C++/WinRT.

// main.cpp : In Visual Studio, create a new Windows Console Application (C++/WinRT).
#include "pch.h"

#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Management.Deployment.h>
#include <iostream>

using namespace winrt;
using namespace Windows::Foundation;
using namespace Windows::Management::Deployment;

int wmain(int /* argc */, wchar_t *argv[], wchar_t * /* envp[] */)
{
    winrt::init_apartment();

    int returnValue{ 0 };

    std::wstring packageUriString{ argv[1] };
    Uri packageUri{ packageUriString };
    PackageManager packageManager;

    auto deploymentOperation{ packageManager.AddPackageAsync(packageUri, nullptr, DeploymentOptions::None) };
    deploymentOperation.get();

    // Check the status of the operation
    if (deploymentOperation.Status() == AsyncStatus::Error)
    {
        auto deploymentResult{ deploymentOperation.GetResults() };
        std::wcout << L"Error code: " << deploymentOperation.ErrorCode() << std::endl;
        std::wcout << L"Error text: " << deploymentResult.ErrorText().c_str() << std::endl;
        returnValue = 1;
    }
    else if (deploymentOperation.Status() == AsyncStatus::Canceled)
    {
        std::wcout << L"Installation canceled" << std::endl;
    }
    else if (deploymentOperation.Status() == AsyncStatus::Completed)
    {
        std::wcout << L"Installation succeeded" << std::endl;
    }
    else
    {
        std::wcout << L"Installation status unknown" << std::endl;
        returnValue = 1;
    }
    return returnValue;
}
using namespace Windows::Foundation;
using namespace Windows::Management::Deployment;

[STAThread]
int __cdecl main(Platform::Array<String^>^ args)
{  
    String^ inputPackageUri = args[1];
    int returnValue=0;

    Uri^ packageUri = ref new Uri(inputPackageUri);

    PackageManager^ packageManager = ref new PackageManager();

    auto deploymentOperation = packageManager->AddPackageAsync(
        packageUri, 
        nullptr, 
        DeploymentOptions::None);

    DeploymentResult^ deploymentOperationResult;

    // This event is signaled when the operation completes
    opCompletedEvent = CreateEvent(NULL, TRUE, FALSE, NULL);

    // Define the delegate
    deploymentOperation->Completed = 
        ref new AsyncOperationWithProgressCompletedHandler<DeploymentResult^, DeploymentProgress>(
        [&](IAsyncOperationWithProgress<DeploymentResult^, DeploymentProgress>^ operation, AsyncStatus)
    {
        SetEvent(opCompletedEvent);
    });

    // Wait until the operation completes
    WaitForSingleObject(opCompletedEvent, INFINITE);

    // Check the status of the operation
    if ( deploymentOperation->Status == AsyncStatus::Error )
    {
        auto deploymentResult = deploymentOperation->GetResults();
        wcout << L"Error code: " << deploymentOperation->ErrorCode.Value << endl;
        wcout << L"Error text: " << deploymentResult->ErrorText->Data() << endl;
        returnValue = 1;
    }
    else if ( deploymentOperation->Status == AsyncStatus::Canceled )
    {
        wcout << L"Installation canceled" << endl;
    }
    else if ( deploymentOperation->Status == AsyncStatus::Completed )
    {
        wcout << L"Installation succeeded" << endl;
    }
    else
    {
        wcout << L"Installation status unknown" << endl;
        returnValue = 1;
    }
    return returnValue;
}

See also

Applies to

AddPackageAsync(Uri, IIterable<Uri>, DeploymentOptions, PackageVolume)

Adds a Package (the main package) and its dependency packages to the specified volume for the current user, using the specified deployment options.

public:
 virtual IAsyncOperationWithProgress<DeploymentResult ^, DeploymentProgress> ^ AddPackageAsync(Uri ^ packageUri, IIterable<Uri ^> ^ dependencyPackageUris, DeploymentOptions deploymentOptions, PackageVolume ^ targetVolume) = AddPackageAsync;
/// [Windows.Foundation.Metadata.Overload("AddPackageToVolumeAsync")]
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> AddPackageAsync(Uri const& packageUri, IIterable<Uri> const& dependencyPackageUris, DeploymentOptions const& deploymentOptions, PackageVolume const& targetVolume);
[Windows.Foundation.Metadata.Overload("AddPackageToVolumeAsync")]
[Windows.Foundation.Metadata.RemoteAsync]
public IAsyncOperationWithProgress<DeploymentResult,DeploymentProgress> AddPackageAsync(System.Uri packageUri, IEnumerable<System.Uri> dependencyPackageUris, DeploymentOptions deploymentOptions, PackageVolume targetVolume);
function addPackageAsync(packageUri, dependencyPackageUris, deploymentOptions, targetVolume)
Public Function AddPackageAsync (packageUri As Uri, dependencyPackageUris As IEnumerable(Of Uri), deploymentOptions As DeploymentOptions, targetVolume As PackageVolume) As IAsyncOperationWithProgress(Of DeploymentResult, DeploymentProgress)

Parameters

packageUri
Uri Uri

The Uri of the package to add. The URI must follow the file URI scheme (file://) since the only supported URI schemes are local file paths and local network paths.

dependencyPackageUris

IIterable<Uri>

IEnumerable<Uri>

The Uris of the dependency packages to add. If there are no dependency packages or if the dependency packages are already registered, this parameter can be null.

deploymentOptions
DeploymentOptions

A bitwise combination of enumeration values from the DeploymentOptions enumeration. ForceApplicationShutdown and None are the only valid options for this method. Specifying any other option results in an E_INVALIDARG return value.

targetVolume
PackageVolume

The volume to which the package is added.

Returns

IAsyncOperationWithProgress<DeploymentResult,DeploymentProgress>

The status of the deployment request. The DeploymentResult contains the final returned value of the deployment operation, once it is completed. The DeploymentProgress can be used to obtain the percentage of completion over the entire course of the deployment operation.

Attributes

Windows requirements

App capabilities
packageManagement

See also

Applies to

AddPackageAsync(Uri, IIterable<Uri>, DeploymentOptions, PackageVolume, IIterable<String>, IIterable<Uri>)

Adds a Package and its dependency packages to the specified volume for the current user, using the specified deployment options.

public:
 virtual IAsyncOperationWithProgress<DeploymentResult ^, DeploymentProgress> ^ AddPackageAsync(Uri ^ packageUri, IIterable<Uri ^> ^ dependencyPackageUris, DeploymentOptions deploymentOptions, PackageVolume ^ targetVolume, IIterable<Platform::String ^> ^ optionalPackageFamilyNames, IIterable<Uri ^> ^ externalPackageUris) = AddPackageAsync;
/// [Windows.Foundation.Metadata.DefaultOverload]
/// [Windows.Foundation.Metadata.Overload("AddPackageToVolumeAndOptionalPackagesAsync")]
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> AddPackageAsync(Uri const& packageUri, IIterable<Uri> const& dependencyPackageUris, DeploymentOptions const& deploymentOptions, PackageVolume const& targetVolume, IIterable<winrt::hstring> const& optionalPackageFamilyNames, IIterable<Uri> const& externalPackageUris);
[Windows.Foundation.Metadata.DefaultOverload]
[Windows.Foundation.Metadata.Overload("AddPackageToVolumeAndOptionalPackagesAsync")]
[Windows.Foundation.Metadata.RemoteAsync]
public IAsyncOperationWithProgress<DeploymentResult,DeploymentProgress> AddPackageAsync(System.Uri packageUri, IEnumerable<System.Uri> dependencyPackageUris, DeploymentOptions deploymentOptions, PackageVolume targetVolume, IEnumerable<string> optionalPackageFamilyNames, IEnumerable<System.Uri> externalPackageUris);
function addPackageAsync(packageUri, dependencyPackageUris, deploymentOptions, targetVolume, optionalPackageFamilyNames, externalPackageUris)
Public Function AddPackageAsync (packageUri As Uri, dependencyPackageUris As IEnumerable(Of Uri), deploymentOptions As DeploymentOptions, targetVolume As PackageVolume, optionalPackageFamilyNames As IEnumerable(Of String), externalPackageUris As IEnumerable(Of Uri)) As IAsyncOperationWithProgress(Of DeploymentResult, DeploymentProgress)

Parameters

packageUri
Uri Uri

The Uri of the source package to add. The URI must follow the file URI scheme (file://) since the only supported URI schemes are local file paths and local network paths.

dependencyPackageUris

IIterable<Uri>

IEnumerable<Uri>

The Uris of the dependency packages to add. If there are no dependency packages or if the dependency packages are already registered, this parameter can be null.

deploymentOptions
DeploymentOptions

A bitwise combination of enumeration values from the DeploymentOptions enumeration. ForceApplicationShutdown and None are the only valid options for this method. Specifying any other option results in an E_INVALIDARG return value.

targetVolume
PackageVolume

The volume that the package is added to.

optionalPackageFamilyNames

IIterable<String>

IEnumerable<String>

The package family names from the main bundle to be registered.

externalPackageUris

IIterable<Uri>

IEnumerable<Uri>

The URIs of the other packages in the main bundle to be registered.

Returns

IAsyncOperationWithProgress<DeploymentResult,DeploymentProgress>

The DeploymentProgress percentage of completion over the entire course of the deployment operation.

Attributes

Windows requirements

Device family
Windows 10 Creators Update (introduced in 10.0.15063.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v4.0)

See also

Applies to

AddPackageAsync(Uri, IIterable<Uri>, DeploymentOptions, PackageVolume, IIterable<String>, IIterable<Uri>, IIterable<Uri>)

Adds a Package (the main package) and its dependency packages for the current user, using the specified deployment options.

public:
 virtual IAsyncOperationWithProgress<DeploymentResult ^, DeploymentProgress> ^ AddPackageAsync(Uri ^ packageUri, IIterable<Uri ^> ^ dependencyPackageUris, DeploymentOptions options, PackageVolume ^ targetVolume, IIterable<Platform::String ^> ^ optionalPackageFamilyNames, IIterable<Uri ^> ^ packageUrisToInstall, IIterable<Uri ^> ^ relatedPackageUris) = AddPackageAsync;
/// [Windows.Foundation.Metadata.Overload("AddPackageToVolumeAndRelatedSetAsync")]
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> AddPackageAsync(Uri const& packageUri, IIterable<Uri> const& dependencyPackageUris, DeploymentOptions const& options, PackageVolume const& targetVolume, IIterable<winrt::hstring> const& optionalPackageFamilyNames, IIterable<Uri> const& packageUrisToInstall, IIterable<Uri> const& relatedPackageUris);
[Windows.Foundation.Metadata.Overload("AddPackageToVolumeAndRelatedSetAsync")]
[Windows.Foundation.Metadata.RemoteAsync]
public IAsyncOperationWithProgress<DeploymentResult,DeploymentProgress> AddPackageAsync(System.Uri packageUri, IEnumerable<System.Uri> dependencyPackageUris, DeploymentOptions options, PackageVolume targetVolume, IEnumerable<string> optionalPackageFamilyNames, IEnumerable<System.Uri> packageUrisToInstall, IEnumerable<System.Uri> relatedPackageUris);
function addPackageAsync(packageUri, dependencyPackageUris, options, targetVolume, optionalPackageFamilyNames, packageUrisToInstall, relatedPackageUris)
Public Function AddPackageAsync (packageUri As Uri, dependencyPackageUris As IEnumerable(Of Uri), options As DeploymentOptions, targetVolume As PackageVolume, optionalPackageFamilyNames As IEnumerable(Of String), packageUrisToInstall As IEnumerable(Of Uri), relatedPackageUris As IEnumerable(Of Uri)) As IAsyncOperationWithProgress(Of DeploymentResult, DeploymentProgress)

Parameters

packageUri
Uri Uri

The URI of the package to add. The URI must follow the file URI scheme (file://) since the only supported URI schemes are local file paths and local network paths.

dependencyPackageUris

IIterable<Uri>

IEnumerable<Uri>

The URIs of framework dependencies to add. If there are no dependency packages or if the dependency packages are already registered, this parameter can be null.

options
DeploymentOptions

The deployment options for the package.

targetVolume
PackageVolume

The volume to which the package is added.

optionalPackageFamilyNames

IIterable<String>

IEnumerable<String>

The package family names from the main bundle to be registered.

packageUrisToInstall

IIterable<Uri>

IEnumerable<Uri>

The URIs of optional packages to be installed with the main app package.

relatedPackageUris

IIterable<Uri>

IEnumerable<Uri>

URIs of related optional packages to be updated to the same version as the new optional packages.

Returns

IAsyncOperationWithProgress<DeploymentResult,DeploymentProgress>

The DeploymentProgress percentage of completion over the entire course of the deployment operation.

Attributes

Windows requirements

Device family
Windows 10 Fall Creators Update (introduced in 10.0.16299.0)
API contract
Windows.Foundation.UniversalApiContract (introduced in v5.0)

See also

Applies to