PackageManager.AddPackageAsync PackageManager.AddPackageAsync PackageManager.AddPackageAsync PackageManager.AddPackageAsync Method

Definition

Overloads

AddPackageAsync(Uri, IIterable<Uri>, DeploymentOptions) AddPackageAsync(Uri, IIterable<Uri>, DeploymentOptions) AddPackageAsync(Uri, IIterable<Uri>, DeploymentOptions) 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) AddPackageAsync(Uri, IIterable<Uri>, DeploymentOptions, PackageVolume) AddPackageAsync(Uri, IIterable<Uri>, DeploymentOptions, PackageVolume) 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>) AddPackageAsync(Uri, IIterable<Uri>, DeploymentOptions, PackageVolume, IIterable<String>, IIterable<Uri>) AddPackageAsync(Uri, IIterable<Uri>, DeploymentOptions, PackageVolume, IIterable<String>, IIterable<Uri>) 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>) AddPackageAsync(Uri, IIterable<Uri>, DeploymentOptions, PackageVolume, IIterable<String>, IIterable<Uri>, IIterable<Uri>) AddPackageAsync(Uri, IIterable<Uri>, DeploymentOptions, PackageVolume, IIterable<String>, IIterable<Uri>, IIterable<Uri>) 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) AddPackageAsync(Uri, IIterable<Uri>, DeploymentOptions) AddPackageAsync(Uri, IIterable<Uri>, DeploymentOptions) 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 : IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> AddPackageAsync(Uri packageUri, IIterable<Uri> dependencyPackageUris, DeploymentOptions deploymentOptions)
IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> AddPackageAsync(Uri packageUri, IIterable<Uri> dependencyPackageUris, DeploymentOptions deploymentOptions) const;
public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> AddPackageAsync(Uri packageUri, IEnumerable<Uri> dependencyPackageUris, DeploymentOptions deploymentOptions)
Public Function AddPackageAsync(packageUri As Uri, dependencyPackageUris As IEnumerable(Of Uri), deploymentOptions As DeploymentOptions) As IAsyncOperationWithProgress(Of DeploymentResultDeploymentProgress)

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
IEnumerable<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 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

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.

Additional features and requirements

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

AddPackageAsync(Uri, IIterable<Uri>, DeploymentOptions, PackageVolume) AddPackageAsync(Uri, IIterable<Uri>, DeploymentOptions, PackageVolume) AddPackageAsync(Uri, IIterable<Uri>, DeploymentOptions, PackageVolume) 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 : IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> AddPackageAsync(Uri packageUri, IIterable<Uri> dependencyPackageUris, DeploymentOptions deploymentOptions, PackageVolume targetVolume)
IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> AddPackageAsync(Uri packageUri, IIterable<Uri> dependencyPackageUris, DeploymentOptions deploymentOptions, PackageVolume targetVolume) const;
public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> AddPackageAsync(Uri packageUri, IEnumerable<Uri> dependencyPackageUris, DeploymentOptions deploymentOptions, PackageVolume targetVolume)
Public Function AddPackageAsync(packageUri As Uri, dependencyPackageUris As IEnumerable(Of Uri), deploymentOptions As DeploymentOptions, targetVolume As PackageVolume) As IAsyncOperationWithProgress(Of DeploymentResultDeploymentProgress)

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
IEnumerable<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 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 PackageVolume

The volume to which the package is added.

Returns

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.

Additional features and requirements

Capabilities
packageManagement
See also

AddPackageAsync(Uri, IIterable<Uri>, DeploymentOptions, PackageVolume, IIterable<String>, IIterable<Uri>) AddPackageAsync(Uri, IIterable<Uri>, DeploymentOptions, PackageVolume, IIterable<String>, IIterable<Uri>) AddPackageAsync(Uri, IIterable<Uri>, DeploymentOptions, PackageVolume, IIterable<String>, IIterable<Uri>) 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 : IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> AddPackageAsync(Uri packageUri, IIterable<Uri> dependencyPackageUris, DeploymentOptions deploymentOptions, PackageVolume targetVolume, IIterable<Platform::String> optionalPackageFamilyNames, IIterable<Uri> externalPackageUris)
IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> AddPackageAsync(Uri packageUri, IIterable<Uri> dependencyPackageUris, DeploymentOptions deploymentOptions, PackageVolume targetVolume, IIterable<winrt::hstring> optionalPackageFamilyNames, IIterable<Uri> externalPackageUris) const;
public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> AddPackageAsync(Uri packageUri, IEnumerable<Uri> dependencyPackageUris, DeploymentOptions deploymentOptions, PackageVolume targetVolume, IEnumerable<String> optionalPackageFamilyNames, IEnumerable<Uri> 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 DeploymentResultDeploymentProgress)

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
IEnumerable<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 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 PackageVolume

The volume that the package is added to.

optionalPackageFamilyNames
IEnumerable<String> IEnumerable<String>

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

externalPackageUris
IEnumerable<Uri> IEnumerable<Uri>

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

Returns

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

Additional features and requirements

Device family
Windows 10 Creators Update (introduced v10.0.15063.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v4)
See also

AddPackageAsync(Uri, IIterable<Uri>, DeploymentOptions, PackageVolume, IIterable<String>, IIterable<Uri>, IIterable<Uri>) AddPackageAsync(Uri, IIterable<Uri>, DeploymentOptions, PackageVolume, IIterable<String>, IIterable<Uri>, IIterable<Uri>) AddPackageAsync(Uri, IIterable<Uri>, DeploymentOptions, PackageVolume, IIterable<String>, IIterable<Uri>, IIterable<Uri>) 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 : IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> AddPackageAsync(Uri packageUri, IIterable<Uri> dependencyPackageUris, DeploymentOptions options, PackageVolume targetVolume, IIterable<Platform::String> optionalPackageFamilyNames, IIterable<Uri> packageUrisToInstall, IIterable<Uri> relatedPackageUris)
IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> AddPackageAsync(Uri packageUri, IIterable<Uri> dependencyPackageUris, DeploymentOptions options, PackageVolume targetVolume, IIterable<winrt::hstring> optionalPackageFamilyNames, IIterable<Uri> packageUrisToInstall, IIterable<Uri> relatedPackageUris) const;
public IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> AddPackageAsync(Uri packageUri, IEnumerable<Uri> dependencyPackageUris, DeploymentOptions options, PackageVolume targetVolume, IEnumerable<String> optionalPackageFamilyNames, IEnumerable<Uri> packageUrisToInstall, IEnumerable<Uri> 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 DeploymentResultDeploymentProgress)

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
IEnumerable<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 DeploymentOptions

The deployment options for the package.

targetVolume
PackageVolume PackageVolume

The volume to which the package is added.

optionalPackageFamilyNames
IEnumerable<String> IEnumerable<String>

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

packageUrisToInstall
IEnumerable<Uri> IEnumerable<Uri>

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

relatedPackageUris
IEnumerable<Uri> IEnumerable<Uri>

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

Returns

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

Additional features and requirements

Device family
Windows 10 Fall Creators Update (introduced v10.0.16299.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v5)