PackageManager.AddPackageAsync method

Applies to Windows only

Adds a package (main package) and its dependencies for the current logged-in user.

Syntax


public:
IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress>^ AddPackageAsync(
  Uri^ packageUri, 
  IIterable<Uri^>^ dependencyPackageUris, 
  DeploymentOptions deploymentOptions
)

Parameters

packageUri

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

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

dependencyPackageUris

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

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

deploymentOptions

Type: DeploymentOptions

One of the permitted enumeration values from the deployment options. ForceApplicationShutdown and None are the only valid options for this method and specifying any other option will result 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 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;
}

Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

None supported

Namespace

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

Metadata

Windows.winmd

See also

Samples
Add app package sample
Reference
PackageManager

 

 

Show:
© 2014 Microsoft