Windows Dev Center

EN
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.

Syntax


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

Parameters

packageUri

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.

dependencyPackageUris

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.

deploymentOptions

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.

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;
}

Requirements (Windows 10 device family)

Device family

Universal

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0

Namespace

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

Metadata

Windows.Foundation.UniversalApiContract.winmd

See also

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

 

 

Mostrar:
© 2015 Microsoft