Skip to content

Commit 9247357

Browse files
committed
Add PackageManagement.RemoveAppxProvisionedPackageAsync().
1 parent 8d1de2e commit 9247357

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

src/PSADT/PSADT.WindowsRuntime/Management/Deployment/PackageManagement.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,26 @@ public static async Task AddAppxProvisionedPackageAsync(Uri packageUri, IEnumera
6060
}
6161
}
6262

63+
/// <summary>
64+
/// Removes the provisioned package with the specified family name from all users on the system using the PackageManager API. Validates the input package family name before attempting to remove the provisioned package. Throws exceptions if the input package family name is invalid or if the removal process fails.
65+
/// </summary>
66+
/// <param name="packageFamilyName">The family name of the package to remove.</param>
67+
/// <param name="cancellationToken">A token to monitor for cancellation requests.</param>
68+
/// <returns>A task that represents the asynchronous operation.</returns>
69+
/// <exception cref="ArgumentException">Thrown if the package family name is null or whitespace.</exception>
70+
/// <exception cref="Exception">Thrown if the removal process fails.</exception>
71+
public static async Task RemoveAppxProvisionedPackageAsync(string packageFamilyName, CancellationToken cancellationToken = default)
72+
{
73+
if (string.IsNullOrWhiteSpace(packageFamilyName))
74+
{
75+
throw new ArgumentException("Value cannot be null or whitespace.", nameof(packageFamilyName));
76+
}
77+
if ((await new PackageManager().DeprovisionPackageForAllUsersAsync(packageFamilyName).AsTask(cancellationToken).ConfigureAwait(false)).ExtendedErrorCode is Exception deprovisioningException)
78+
{
79+
throw deprovisioningException;
80+
}
81+
}
82+
6383
/// <summary>
6484
/// Retrieves the manifest information from the specified package file by determining the package type and reading the appropriate manifest file within the package archive.
6585
/// </summary>

0 commit comments

Comments
 (0)