PackageManager.AddPackageByAppInstallerFileAsync Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
public:
virtual IAsyncOperationWithProgress<DeploymentResult ^, DeploymentProgress> ^ AddPackageByAppInstallerFileAsync(Uri ^ appInstallerFileUri, AddPackageByAppInstallerOptions options, PackageVolume ^ targetVolume) = AddPackageByAppInstallerFileAsync;
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> AddPackageByAppInstallerFileAsync(Uri const& appInstallerFileUri, AddPackageByAppInstallerOptions const& options, PackageVolume const& targetVolume);
[Windows.Foundation.Metadata.RemoteAsync]
public IAsyncOperationWithProgress<DeploymentResult,DeploymentProgress> AddPackageByAppInstallerFileAsync(System.Uri appInstallerFileUri, AddPackageByAppInstallerOptions options, PackageVolume targetVolume);
function addPackageByAppInstallerFileAsync(appInstallerFileUri, options, targetVolume)
Public Function AddPackageByAppInstallerFileAsync (appInstallerFileUri As Uri, options As AddPackageByAppInstallerOptions, targetVolume As PackageVolume) As IAsyncOperationWithProgress(Of DeploymentResult, DeploymentProgress)
Paramètres
- options
- AddPackageByAppInstallerOptions
Options spécifiées dans AddPackageByAppInstallerOptions.
- targetVolume
- PackageVolume
Volume sur lequel le package est installé.
Retours
IAsyncOperationWithProgress avec un DeploymentResult qui indique si le déploiement a réussi et DeploymentProgress qui fournit des mises à jour de progression pendant l’installation.
- Attributs
Configuration requise pour Windows
| Configuration requise | Description |
|---|---|
| Famille d’appareils |
Windows 10 Fall Creators Update (introduit dans 10.0.16299.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduit dans v5.0)
|
| Fonctionnalités de l’application |
packageManagement
|
Exemples
L’exemple suivant utilise AddPackageByAppInstallerFileAsync pour installer des packages définis dans un fichier .appinstaller. Notez que l’IAsyncOperationWithProgress retourné est affecté à une variable avant de surveiller sa fin. L’échec de la conservation d’une référence à l’opération peut entraîner le garbage-collected et ne jamais être terminé.
using System;
using System.Threading;
using Windows.Foundation;
using Windows.Management.Deployment;
public static int Main(string[] args)
{
string inputFileUri = args[0];
int returnValue = 0;
Uri appInstallerFileUri = new Uri(inputFileUri);
PackageManager packageManager = new PackageManager();
PackageVolume packageVolume = packageManager.GetDefaultPackageVolume();
// Important: assign the operation to a variable to prevent it from
// being garbage-collected before completion.
IAsyncOperationWithProgress<DeploymentResult, DeploymentProgress> deploymentOperation =
packageManager.AddPackageByAppInstallerFileAsync(
appInstallerFileUri,
AddPackageByAppInstallerOptions.ForceTargetAppShutdown,
packageVolume);
// This event is signaled when the operation completes
ManualResetEvent opCompletedEvent = new ManualResetEvent(false);
// Define the delegate using a statement lambda
deploymentOperation.Completed = (operation, 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;
}
Remarques
Cette méthode n’est pas prise en charge en JavaScript. Toutefois, vous pouvez créer un composant Windows Runtime qui appelle cette méthode, puis appeler ce composant à partir d’une application UWP JavaScript. Pour plus d’informations, consultez Problèmes liés à l’API du fichier d’installation d’application.