PackageDeploymentManager.EnsurePackageReadyAsync Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Asynchronously determines whether the target package(s) is/are present (installed, registered) and ready for use; and, if not, puts them in that state. That can involve downloading the target, registering it for the user, and remediating a package in an unhealthy state.
public:
virtual IAsyncOperationWithProgress<PackageDeploymentResult ^, PackageDeploymentProgress> ^ EnsurePackageReadyAsync(Platform::String ^ package, EnsureReadyOptions ^ options) = EnsurePackageReadyAsync;
IAsyncOperationWithProgress<PackageDeploymentResult, PackageDeploymentProgress> EnsurePackageReadyAsync(winrt::hstring const& package, EnsureReadyOptions const& options);
public IAsyncOperationWithProgress<PackageDeploymentResult,PackageDeploymentProgress> EnsurePackageReadyAsync(string package, EnsureReadyOptions options);
function ensurePackageReadyAsync(package, options)
Public Function EnsurePackageReadyAsync (package As String, options As EnsureReadyOptions) As IAsyncOperationWithProgress(Of PackageDeploymentResult, PackageDeploymentProgress)
Parameters
- package
-
String
Platform::String
winrt::hstring
The target package(s) to query about.
- options
- EnsureReadyOptions
Ensure-ready options for the operation.
Returns
An asynchronous operation object which, when it completes, contains a value representing the result of the operation.
Examples
A Fabrikam app installing Contoso's Example1 and Example2 packages, if necessary, via a PackageSet.
void Install()
{
var packageSet = new PackageSet() {
Items = { new PackageSetItem() { PackageFamilyName = "contoso.example1_1234567890abc",
MinVersion = ToVersion(1, 2, 3, 4),
PackageUri = new Uri("c:\\contoso\\example1-1.2.3.4.msix") },
{ new PackageSetItem() { PackageFamilyName = "contoso.example2_1234567890abc",
MinVersion = ToVersion(2, 4, 6, 8),
PackageUri = new Uri("https://contoso.com/example2-2.4.6.8.msix") } };
var packageDeploymentManager = PackageDeploymentManager.GetDefault();
var options = new EnsureReadyOptions();
var deploymentResult = await packageDeploymentManager.EnsurePackageSetReadyAsync(packageSet, options);
if (deplymentResult.Status == PackageDeploymentStatus.CompletedSuccess)
{
Console.WriteLine("OK");
}
else
{
Console.WriteLine("Error:{} ExtendedError:{} {}",
deploymentResult.Error.HResult, deploymentResult.ExtendedError.HResult, deploymentResult.ErrorText);
}
}
PackageVersion ToVersion(uint major, uint minor, uint build, uint revision) =>
new PackageVersion {
Major = checked((ushort)major),
Minor = checked((ushort)minor),
Build = checked((ushort)build),
Revision = checked((ushort)revision)
};
Remarks
In terms of implementation, calling EnsurePackageReady(pkg, options)
is functionally equivalent to:
var pdm = PackageDeploymentManager().GetDefault();
if (!pdm.IsPackageReady(pkg))
{
var result = await pdm.AddPackageAsync(pkg, options);
}
As you can see, EnsurePackageReadyAsync calls IsPackageReady, and returns early if all is ready. So there's no efficiency reason to call IsPackageReady yourself before you call EnsurePackageReadyAsync.