Windows Dev Center

Este conteúdo não está disponível em seu idioma, mas aqui está a versão em inglês.

PackageManager.AddPackageAsync(Uri, IIterable(Uri), DeploymentOptions) | addPackageAsync(Uri, IIterable(Uri), DeploymentOptions) method

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


packageManager.addPackageAsync(packageUri, dependencyPackageUris, deploymentOptions).done( /* Your success and error handlers */ );



Type: Windows.Foundation.Uri [JavaScript] | System.Uri [.NET] | Windows::Foundation::Uri [C++]

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.


Type: IIterable<Uri> [JavaScript/C++] | System.Collections.Generic.IEnumerable<Uri> [.NET]

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.


Type: 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.

Return value

Type: 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.


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 = 

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

    // 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");
        returnValue = 1;
        Console.WriteLine("Installation status unknown");

    return returnValue;

Requirements (Windows 10 device family)

Device family


API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0


Windows::Management::Deployment [C++]



See also

Add app package sample
AddPackageAsync(Uri, IIterable(Uri), DeploymentOptions, PackageVolume)



© 2015 Microsoft