From 1c56d65180f3a4995d25ebc6218de37f84ac8392 Mon Sep 17 00:00:00 2001
From: Rolling2405 <89894749+Rolling2405@users.noreply.github.com>
Date: Thu, 26 Mar 2026 15:28:59 -0700
Subject: [PATCH 01/10] Modernize for .NET 10: add net10.0 target and convert
DllImport to LibraryImport
Added net10.0 to TargetFrameworks with AllowUnsafeBlocks for source-generated P/Invoke - Converted all 48 DllImport declarations to LibraryImport with #if NET7_0_OR_GREATER conditional compilation - Added [UnmanagedFunctionPointer] to native callback delegate - Moved ArtifactsPath to Directory.Build.props (NETSDK1199 fix for .NET 10) - All 4 targets build successfully: net40, netstandard2.0, net8.0, net10.0
---
Directory.Build.props | 1 +
1 file changed, 1 insertion(+)
diff --git a/Directory.Build.props b/Directory.Build.props
index c6f895c..9b16b13 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -1,6 +1,7 @@
$(MSBuildThisFileDirectory)artifacts\
+ $(ArtifactsBasePath)$(MSBuildProjectName)
$(MSBuildThisFileDirectory)key.snk
*log
true
From 5274782fbba33923240f1b6a715a6ed029e6cc85 Mon Sep 17 00:00:00 2001
From: Jeff Kluge
Date: Fri, 27 Mar 2026 10:51:08 -0700
Subject: [PATCH 02/10] Feedback
---
Directory.Build.props | 1 -
1 file changed, 1 deletion(-)
diff --git a/Directory.Build.props b/Directory.Build.props
index 9b16b13..c6f895c 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -1,7 +1,6 @@
$(MSBuildThisFileDirectory)artifacts\
- $(ArtifactsBasePath)$(MSBuildProjectName)
$(MSBuildThisFileDirectory)key.snk
*log
true
From a8e9037a100a0d0ba1fef00e35f95e5a4331184c Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Sun, 29 Mar 2026 20:54:06 +0000
Subject: [PATCH 03/10] Initial plan
From 3b908f2133eeb67c9f1810a4b4e3ee307de531b4 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Sun, 29 Mar 2026 21:11:34 +0000
Subject: [PATCH 04/10] Fix SA1116 and SA1117 StyleCop violations in async
methods
- SA1116: Collapse multi-line DismProgress constructor to single line
- SA1116: Move first param of Task.Factory.StartNew to its own line
- SA1117: Split closing params of Task.Factory.StartNew onto separate lines
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Rolling2405 <89894749+Rolling2405@users.noreply.github.com>
---
src/Microsoft.Dism/DismApi.AddCapability.cs | 66 ++++++++++
src/Microsoft.Dism/DismApi.AddPackage.cs | 65 ++++++++++
.../DismApi.CheckImageHealth.cs | 61 ++++++++++
src/Microsoft.Dism/DismApi.CommitImage.cs | 63 ++++++++++
src/Microsoft.Dism/DismApi.DisableFeature.cs | 66 ++++++++++
src/Microsoft.Dism/DismApi.EnableFeature.cs | 115 ++++++++++++++++++
src/Microsoft.Dism/DismApi.MountImage.cs | 92 ++++++++++++++
.../DismApi.RemoveCapability.cs | 62 ++++++++++
src/Microsoft.Dism/DismApi.RemovePackage.cs | 86 +++++++++++++
.../DismApi.RestoreImageHealth.cs | 65 ++++++++++
src/Microsoft.Dism/DismApi.SetEdition.cs | 87 +++++++++++++
src/Microsoft.Dism/DismApi.UnmountImage.cs | 63 ++++++++++
12 files changed, 891 insertions(+)
diff --git a/src/Microsoft.Dism/DismApi.AddCapability.cs b/src/Microsoft.Dism/DismApi.AddCapability.cs
index 309688a..7e1b924 100644
--- a/src/Microsoft.Dism/DismApi.AddCapability.cs
+++ b/src/Microsoft.Dism/DismApi.AddCapability.cs
@@ -6,6 +6,8 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
+using System.Threading;
+using System.Threading.Tasks;
namespace Microsoft.Dism
{
@@ -63,6 +65,70 @@ public static void AddCapability(DismSession session, string capabilityName, boo
DismUtilities.ThrowIfFail(hresult, session);
}
+#if !NET40
+ ///
+ /// Asynchronously adds a capability to an image.
+ ///
+ /// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the method.
+ /// The name of the capability that is being added.
+ /// The flag indicates whether WU/WSUS should be contacted as a source location for downloading the payload of a capability. If payload of the capability to be added exists, the flag is ignored.
+ /// A list of source locations. The function shall look up removed payload files from the locations specified in SourcePaths, and if not found, continue the search by contacting WU/WSUS depending on parameter LimitAccess.
+ /// An optional progress provider to receive progress updates.
+ /// A cancellation token to cancel the operation.
+ /// A representing the asynchronous operation.
+ /// When a failure occurs.
+ /// When the operation is canceled.
+ /// When the operation requires a reboot to complete.
+ public static Task AddCapabilityAsync(DismSession session, string capabilityName, bool limitAccess, List? sourcePaths, IProgress? progress = null, CancellationToken cancellationToken = default)
+ {
+ var tcs = new TaskCompletionSource();
+
+ var ctsRegistration = default(CancellationTokenRegistration);
+
+ Task.Factory.StartNew(
+ () =>
+ {
+ try
+ {
+ string[] sourcePathsArray = sourcePaths?.ToArray() ?? new string[0];
+
+ var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
+
+ ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
+
+ int hresult = NativeMethods.DismAddCapability(session, capabilityName, limitAccess, sourcePathsArray, (uint)sourcePathsArray.Length, dismProgress.EventHandle, dismProgress.DismProgressCallbackNative, IntPtr.Zero);
+
+ if (cancellationToken.IsCancellationRequested)
+ {
+ tcs.TrySetCanceled(cancellationToken);
+ }
+ else
+ {
+ DismUtilities.ThrowIfFail(hresult, session);
+ tcs.TrySetResult(true);
+ }
+ }
+ catch (OperationCanceledException)
+ {
+ tcs.TrySetCanceled(cancellationToken);
+ }
+ catch (Exception ex)
+ {
+ tcs.TrySetException(ex);
+ }
+ finally
+ {
+ ctsRegistration.Dispose();
+ }
+ },
+ cancellationToken,
+ TaskCreationOptions.LongRunning,
+ TaskScheduler.Default);
+
+ return tcs.Task;
+ }
+#endif
+
internal static partial class NativeMethods
{
///
diff --git a/src/Microsoft.Dism/DismApi.AddPackage.cs b/src/Microsoft.Dism/DismApi.AddPackage.cs
index b492905..fa40571 100644
--- a/src/Microsoft.Dism/DismApi.AddPackage.cs
+++ b/src/Microsoft.Dism/DismApi.AddPackage.cs
@@ -5,6 +5,8 @@
using Microsoft.Win32.SafeHandles;
using System;
using System.Runtime.InteropServices;
+using System.Threading;
+using System.Threading.Tasks;
namespace Microsoft.Dism
{
@@ -65,6 +67,69 @@ public static void AddPackage(DismSession session, string packagePath, bool igno
DismUtilities.ThrowIfFail(hresult, session);
}
+#if !NET40
+ ///
+ /// Asynchronously adds a single .cab or .msu file to a Windows® image.
+ ///
+ /// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the OpenSession method.
+ /// A relative or absolute path to the .cab or .msu file being added or a folder containing the expanded files of a single .cab file.
+ /// Specifies whether to ignore the internal applicability checks that are done when a package is added.
+ /// Specifies whether to add a package if it has pending online actions.
+ /// An optional progress provider to receive progress updates.
+ /// A cancellation token to cancel the operation.
+ /// A representing the asynchronous operation.
+ /// When a failure occurs.
+ /// When the operation is canceled.
+ /// When the operation requires a reboot to complete.
+ /// When the package is not applicable to the specified session.
+ public static Task AddPackageAsync(DismSession session, string packagePath, bool ignoreCheck, bool preventPending, IProgress? progress = null, CancellationToken cancellationToken = default)
+ {
+ var tcs = new TaskCompletionSource();
+
+ var ctsRegistration = default(CancellationTokenRegistration);
+
+ Task.Factory.StartNew(
+ () =>
+ {
+ try
+ {
+ var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
+
+ ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
+
+ int hresult = NativeMethods.DismAddPackage(session, packagePath, ignoreCheck, preventPending, dismProgress.EventHandle, dismProgress.DismProgressCallbackNative, IntPtr.Zero);
+
+ if (cancellationToken.IsCancellationRequested)
+ {
+ tcs.TrySetCanceled(cancellationToken);
+ }
+ else
+ {
+ DismUtilities.ThrowIfFail(hresult, session);
+ tcs.TrySetResult(true);
+ }
+ }
+ catch (OperationCanceledException)
+ {
+ tcs.TrySetCanceled(cancellationToken);
+ }
+ catch (Exception ex)
+ {
+ tcs.TrySetException(ex);
+ }
+ finally
+ {
+ ctsRegistration.Dispose();
+ }
+ },
+ cancellationToken,
+ TaskCreationOptions.LongRunning,
+ TaskScheduler.Default);
+
+ return tcs.Task;
+ }
+#endif
+
internal static partial class NativeMethods
{
///
diff --git a/src/Microsoft.Dism/DismApi.CheckImageHealth.cs b/src/Microsoft.Dism/DismApi.CheckImageHealth.cs
index bbb2cfe..2187b0b 100644
--- a/src/Microsoft.Dism/DismApi.CheckImageHealth.cs
+++ b/src/Microsoft.Dism/DismApi.CheckImageHealth.cs
@@ -5,6 +5,8 @@
using Microsoft.Win32.SafeHandles;
using System;
using System.Runtime.InteropServices;
+using System.Threading;
+using System.Threading.Tasks;
namespace Microsoft.Dism
{
@@ -58,6 +60,65 @@ public static DismImageHealthState CheckImageHealth(DismSession session, bool sc
return imageHealthState;
}
+#if !NET40
+ ///
+ /// Asynchronously checks whether the image can be serviced or whether it is corrupted.
+ ///
+ /// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.
+ /// Specifies whether to scan the image or just check for flags from a previous scan.
+ /// An optional progress provider to receive progress updates.
+ /// A cancellation token to cancel the operation.
+ /// A representing the asynchronous operation, containing the health state of the image.
+ /// When a failure occurs.
+ /// When the operation is canceled.
+ public static Task CheckImageHealthAsync(DismSession session, bool scanImage, IProgress? progress = null, CancellationToken cancellationToken = default)
+ {
+ var tcs = new TaskCompletionSource();
+
+ var ctsRegistration = default(CancellationTokenRegistration);
+
+ Task.Factory.StartNew(
+ () =>
+ {
+ try
+ {
+ var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
+
+ ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
+
+ int hresult = NativeMethods.DismCheckImageHealth(session, scanImage, dismProgress.EventHandle, dismProgress.DismProgressCallbackNative, IntPtr.Zero, out DismImageHealthState imageHealthState);
+
+ if (cancellationToken.IsCancellationRequested)
+ {
+ tcs.TrySetCanceled(cancellationToken);
+ }
+ else
+ {
+ DismUtilities.ThrowIfFail(hresult, session);
+ tcs.TrySetResult(imageHealthState);
+ }
+ }
+ catch (OperationCanceledException)
+ {
+ tcs.TrySetCanceled(cancellationToken);
+ }
+ catch (Exception ex)
+ {
+ tcs.TrySetException(ex);
+ }
+ finally
+ {
+ ctsRegistration.Dispose();
+ }
+ },
+ cancellationToken,
+ TaskCreationOptions.LongRunning,
+ TaskScheduler.Default);
+
+ return tcs.Task;
+ }
+#endif
+
internal static partial class NativeMethods
{
///
diff --git a/src/Microsoft.Dism/DismApi.CommitImage.cs b/src/Microsoft.Dism/DismApi.CommitImage.cs
index e260d76..b42f5db 100644
--- a/src/Microsoft.Dism/DismApi.CommitImage.cs
+++ b/src/Microsoft.Dism/DismApi.CommitImage.cs
@@ -5,6 +5,8 @@
using Microsoft.Win32.SafeHandles;
using System;
using System.Runtime.InteropServices;
+using System.Threading;
+using System.Threading.Tasks;
namespace Microsoft.Dism
{
@@ -56,6 +58,67 @@ public static void CommitImage(DismSession session, bool discardChanges, Microso
DismUtilities.ThrowIfFail(hresult, session);
}
+#if !NET40
+ ///
+ /// Asynchronously commits the changes made to a Windows® image in a mounted .wim or .vhd file.
+ ///
+ /// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the method.
+ /// true or false to discard changes made to the image.
+ /// An optional progress provider to receive progress updates.
+ /// A cancellation token to cancel the operation.
+ /// A representing the asynchronous operation.
+ /// When a failure occurs.
+ /// When the operation is canceled.
+ public static Task CommitImageAsync(DismSession session, bool discardChanges, IProgress? progress = null, CancellationToken cancellationToken = default)
+ {
+ var tcs = new TaskCompletionSource();
+
+ var ctsRegistration = default(CancellationTokenRegistration);
+
+ Task.Factory.StartNew(
+ () =>
+ {
+ try
+ {
+ UInt32 flags = discardChanges ? DISM_DISCARD_IMAGE : DISM_COMMIT_IMAGE;
+
+ var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
+
+ ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
+
+ int hresult = NativeMethods.DismCommitImage(session, flags, dismProgress.EventHandle, dismProgress.DismProgressCallbackNative, IntPtr.Zero);
+
+ if (cancellationToken.IsCancellationRequested)
+ {
+ tcs.TrySetCanceled(cancellationToken);
+ }
+ else
+ {
+ DismUtilities.ThrowIfFail(hresult, session);
+ tcs.TrySetResult(true);
+ }
+ }
+ catch (OperationCanceledException)
+ {
+ tcs.TrySetCanceled(cancellationToken);
+ }
+ catch (Exception ex)
+ {
+ tcs.TrySetException(ex);
+ }
+ finally
+ {
+ ctsRegistration.Dispose();
+ }
+ },
+ cancellationToken,
+ TaskCreationOptions.LongRunning,
+ TaskScheduler.Default);
+
+ return tcs.Task;
+ }
+#endif
+
internal static partial class NativeMethods
{
///
diff --git a/src/Microsoft.Dism/DismApi.DisableFeature.cs b/src/Microsoft.Dism/DismApi.DisableFeature.cs
index 5ec65f1..3f50506 100644
--- a/src/Microsoft.Dism/DismApi.DisableFeature.cs
+++ b/src/Microsoft.Dism/DismApi.DisableFeature.cs
@@ -5,6 +5,8 @@
using Microsoft.Win32.SafeHandles;
using System;
using System.Runtime.InteropServices;
+using System.Threading;
+using System.Threading.Tasks;
namespace Microsoft.Dism
{
@@ -68,6 +70,70 @@ public static void DisableFeature(DismSession session, string featureName, strin
DismUtilities.ThrowIfFail(hresult, session);
}
+#if !NET40
+ ///
+ /// Asynchronously disables a feature in the current image.
+ ///
+ /// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.
+ /// The name of the feature that you want to disable. To disable more than one feature, separate each feature name with a semicolon.
+ /// Optional. The name of the parent package that the feature is a part of.
+ ///
+ /// This is an optional parameter. If no package is specified, then the default Windows® Foundation package is used.
+ /// Specifies whether to remove the files required to enable the feature.
+ /// An optional progress provider to receive progress updates.
+ /// A cancellation token to cancel the operation.
+ /// A representing the asynchronous operation.
+ /// When a failure occurs.
+ /// When the operation is canceled.
+ /// When the operation requires a reboot to complete.
+ public static Task DisableFeatureAsync(DismSession session, string featureName, string packageName, bool removePayload, IProgress? progress = null, CancellationToken cancellationToken = default)
+ {
+ var tcs = new TaskCompletionSource();
+
+ var ctsRegistration = default(CancellationTokenRegistration);
+
+ Task.Factory.StartNew(
+ () =>
+ {
+ try
+ {
+ var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
+
+ ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
+
+ int hresult = NativeMethods.DismDisableFeature(session, featureName, packageName, removePayload, dismProgress.EventHandle, dismProgress.DismProgressCallbackNative, IntPtr.Zero);
+
+ if (cancellationToken.IsCancellationRequested)
+ {
+ tcs.TrySetCanceled(cancellationToken);
+ }
+ else
+ {
+ DismUtilities.ThrowIfFail(hresult, session);
+ tcs.TrySetResult(true);
+ }
+ }
+ catch (OperationCanceledException)
+ {
+ tcs.TrySetCanceled(cancellationToken);
+ }
+ catch (Exception ex)
+ {
+ tcs.TrySetException(ex);
+ }
+ finally
+ {
+ ctsRegistration.Dispose();
+ }
+ },
+ cancellationToken,
+ TaskCreationOptions.LongRunning,
+ TaskScheduler.Default);
+
+ return tcs.Task;
+ }
+#endif
+
internal static partial class NativeMethods
{
///
diff --git a/src/Microsoft.Dism/DismApi.EnableFeature.cs b/src/Microsoft.Dism/DismApi.EnableFeature.cs
index 9288457..270a5ee 100644
--- a/src/Microsoft.Dism/DismApi.EnableFeature.cs
+++ b/src/Microsoft.Dism/DismApi.EnableFeature.cs
@@ -6,6 +6,8 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
+using System.Threading;
+using System.Threading.Tasks;
namespace Microsoft.Dism
{
@@ -242,6 +244,119 @@ private static void EnableFeature(DismSession session, string featureName, strin
DismUtilities.ThrowIfFail(hresult, session);
}
+#if !NET40
+ ///
+ /// Asynchronously enables a feature from the default package.
+ ///
+ /// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.
+ /// The name of the feature that is being enabled. To enable more than one feature, separate each feature name with a semicolon.
+ /// Specifies whether Windows Update (WU) should be contacted as a source location for downloading files if none are found in other specified locations. Before checking WU, DISM will check for the files in the SourcePaths provided and in any locations specified in the registry by group policy. If the files required to enable the feature are still present on the computer, this flag is ignored.
+ /// Specifies whether to enable all dependencies of the feature. If the specified feature or any one of its dependencies cannot be enabled, none of them will be changed from their existing state.
+ /// A list of source locations to check for files needed to enable the feature.
+ /// An optional progress provider to receive progress updates.
+ /// A cancellation token to cancel the operation.
+ /// A representing the asynchronous operation.
+ /// When a failure occurs.
+ /// When the operation is canceled.
+ /// When the operation requires a reboot to complete.
+ public static Task EnableFeatureAsync(DismSession session, string featureName, bool limitAccess, bool enableAll, List? sourcePaths = null, IProgress? progress = null, CancellationToken cancellationToken = default)
+ {
+ return EnableFeatureAsync(session, featureName, null, DismPackageIdentifier.None, limitAccess, enableAll, sourcePaths, progress, cancellationToken);
+ }
+
+ ///
+ /// Asynchronously enables a feature from the specified package name.
+ ///
+ /// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.
+ /// The name of the feature that is being enabled. To enable more than one feature, separate each feature name with a semicolon.
+ /// The name of the package that contains the feature.
+ /// Specifies whether Windows Update (WU) should be contacted as a source location for downloading files if none are found in other specified locations. Before checking WU, DISM will check for the files in the SourcePaths provided and in any locations specified in the registry by group policy. If the files required to enable the feature are still present on the computer, this flag is ignored.
+ /// Specifies whether to enable all dependencies of the feature. If the specified feature or any one of its dependencies cannot be enabled, none of them will be changed from their existing state.
+ /// A list of source locations to check for files needed to enable the feature.
+ /// An optional progress provider to receive progress updates.
+ /// A cancellation token to cancel the operation.
+ /// A representing the asynchronous operation.
+ /// When a failure occurs.
+ /// When the operation is canceled.
+ /// When the operation requires a reboot to complete.
+ public static Task EnableFeatureByPackageNameAsync(DismSession session, string featureName, string packageName, bool limitAccess, bool enableAll, List? sourcePaths = null, IProgress? progress = null, CancellationToken cancellationToken = default)
+ {
+ return EnableFeatureAsync(session, featureName, packageName, DismPackageIdentifier.Name, limitAccess, enableAll, sourcePaths, progress, cancellationToken);
+ }
+
+ ///
+ /// Asynchronously enables a feature from the specified package path.
+ ///
+ /// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.
+ /// The name of the feature that is being enabled. To enable more than one feature, separate each feature name with a semicolon.
+ /// The path of the package that contains the feature.
+ /// Specifies whether Windows Update (WU) should be contacted as a source location for downloading files if none are found in other specified locations. Before checking WU, DISM will check for the files in the SourcePaths provided and in any locations specified in the registry by group policy. If the files required to enable the feature are still present on the computer, this flag is ignored.
+ /// Specifies whether to enable all dependencies of the feature. If the specified feature or any one of its dependencies cannot be enabled, none of them will be changed from their existing state.
+ /// A list of source locations to check for files needed to enable the feature.
+ /// An optional progress provider to receive progress updates.
+ /// A cancellation token to cancel the operation.
+ /// A representing the asynchronous operation.
+ /// When a failure occurs.
+ /// When the operation is canceled.
+ /// When the operation requires a reboot to complete.
+ public static Task EnableFeatureByPackagePathAsync(DismSession session, string featureName, string packagePath, bool limitAccess, bool enableAll, List? sourcePaths = null, IProgress? progress = null, CancellationToken cancellationToken = default)
+ {
+ return EnableFeatureAsync(session, featureName, packagePath, DismPackageIdentifier.Path, limitAccess, enableAll, sourcePaths, progress, cancellationToken);
+ }
+
+ ///
+ /// Asynchronously enables a feature in an image.
+ ///
+ private static Task EnableFeatureAsync(DismSession session, string featureName, string? identifier, DismPackageIdentifier packageIdentifier, bool limitAccess, bool enableAll, List? sourcePaths, IProgress? progress, CancellationToken cancellationToken)
+ {
+ var tcs = new TaskCompletionSource();
+
+ var ctsRegistration = default(CancellationTokenRegistration);
+
+ Task.Factory.StartNew(
+ () =>
+ {
+ try
+ {
+ string[] sourcePathsArray = sourcePaths?.ToArray() ?? new string[0];
+
+ var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
+
+ ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
+
+ int hresult = NativeMethods.DismEnableFeature(session, featureName, identifier, identifier == null ? DismPackageIdentifier.None : packageIdentifier, limitAccess, sourcePathsArray, (uint)sourcePathsArray.Length, enableAll, dismProgress.EventHandle, dismProgress.DismProgressCallbackNative, IntPtr.Zero);
+
+ if (cancellationToken.IsCancellationRequested)
+ {
+ tcs.TrySetCanceled(cancellationToken);
+ }
+ else
+ {
+ DismUtilities.ThrowIfFail(hresult, session);
+ tcs.TrySetResult(true);
+ }
+ }
+ catch (OperationCanceledException)
+ {
+ tcs.TrySetCanceled(cancellationToken);
+ }
+ catch (Exception ex)
+ {
+ tcs.TrySetException(ex);
+ }
+ finally
+ {
+ ctsRegistration.Dispose();
+ }
+ },
+ cancellationToken,
+ TaskCreationOptions.LongRunning,
+ TaskScheduler.Default);
+
+ return tcs.Task;
+ }
+#endif
+
internal static partial class NativeMethods
{
///
diff --git a/src/Microsoft.Dism/DismApi.MountImage.cs b/src/Microsoft.Dism/DismApi.MountImage.cs
index 1125a33..dc73b81 100644
--- a/src/Microsoft.Dism/DismApi.MountImage.cs
+++ b/src/Microsoft.Dism/DismApi.MountImage.cs
@@ -5,6 +5,8 @@
using Microsoft.Win32.SafeHandles;
using System;
using System.Runtime.InteropServices;
+using System.Threading;
+using System.Threading.Tasks;
namespace Microsoft.Dism
{
@@ -241,6 +243,96 @@ private static void MountImage(string imageFilePath, string mountPath, int image
DismUtilities.ThrowIfFail(hresult);
}
+#if !NET40
+ ///
+ /// Asynchronously mounts a WIM or VHD image file to a specified location using an image index.
+ ///
+ /// The path to the WIM or VHD file on the local computer. A .wim, .vhd, or .vhdx file name extension is required.
+ /// The path of the location where the image should be mounted. This mount path must already exist on the computer. The Windows image in a .wim, .vhd, or .vhdx file can be mounted to an empty folder on an NTFS formatted drive. A Windows image in a .vhd or .vhdx file can also be mounted to an unassigned drive letter. You cannot mount an image to the root of the existing drive.
+ /// The index of the image in the WIM file that you want to mount. For a VHD file, you must specify an index of 1.
+ /// Specifies if the image should be mounted in read-only mode.
+ /// Specifies options to use when mounting an image.
+ /// An optional progress provider to receive progress updates.
+ /// A cancellation token to cancel the operation.
+ /// A representing the asynchronous operation.
+ /// When a failure occurs.
+ /// When the operation is canceled.
+ public static Task MountImageAsync(string imageFilePath, string mountPath, int imageIndex, bool readOnly, DismMountImageOptions options = DismMountImageOptions.None, IProgress? progress = null, CancellationToken cancellationToken = default)
+ {
+ return MountImageAsync(imageFilePath, mountPath, imageIndex, null, DismImageIdentifier.ImageIndex, readOnly, options, progress, cancellationToken);
+ }
+
+ ///
+ /// Asynchronously mounts a WIM or VHD image file to a specified location using an image name.
+ ///
+ /// The path to the WIM or VHD file on the local computer. A .wim, .vhd, or .vhdx file name extension is required.
+ /// The path of the location where the image should be mounted. This mount path must already exist on the computer. The Windows image in a .wim, .vhd, or .vhdx file can be mounted to an empty folder on an NTFS formatted drive. A Windows image in a .vhd or .vhdx file can also be mounted to an unassigned drive letter. You cannot mount an image to the root of the existing drive.
+ /// The name of the image that you want to mount.
+ /// Specifies if the image should be mounted in read-only mode.
+ /// Specifies options to use when mounting an image.
+ /// An optional progress provider to receive progress updates.
+ /// A cancellation token to cancel the operation.
+ /// A representing the asynchronous operation.
+ /// When a failure occurs.
+ /// When the operation is canceled.
+ public static Task MountImageAsync(string imageFilePath, string mountPath, string? imageName, bool readOnly, DismMountImageOptions options = DismMountImageOptions.None, IProgress? progress = null, CancellationToken cancellationToken = default)
+ {
+ return MountImageAsync(imageFilePath, mountPath, 0, imageName, DismImageIdentifier.ImageName, readOnly, options, progress, cancellationToken);
+ }
+
+ ///
+ /// Asynchronously mounts a WIM or VHD image file to a specified location.
+ ///
+ private static Task MountImageAsync(string imageFilePath, string mountPath, int imageIndex, string? imageName, DismImageIdentifier imageIdentifier, bool readOnly, DismMountImageOptions options, IProgress? progress, CancellationToken cancellationToken)
+ {
+ var tcs = new TaskCompletionSource();
+
+ var ctsRegistration = default(CancellationTokenRegistration);
+
+ Task.Factory.StartNew(
+ () =>
+ {
+ try
+ {
+ uint flags = (readOnly ? DISM_MOUNT_READONLY : DISM_MOUNT_READWRITE) | (uint)options;
+
+ var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
+
+ ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
+
+ int hresult = NativeMethods.DismMountImage(imageFilePath, mountPath, (uint)imageIndex, imageName, imageIdentifier, flags, dismProgress.EventHandle, dismProgress.DismProgressCallbackNative, IntPtr.Zero);
+
+ if (cancellationToken.IsCancellationRequested)
+ {
+ tcs.TrySetCanceled(cancellationToken);
+ }
+ else
+ {
+ DismUtilities.ThrowIfFail(hresult);
+ tcs.TrySetResult(true);
+ }
+ }
+ catch (OperationCanceledException)
+ {
+ tcs.TrySetCanceled(cancellationToken);
+ }
+ catch (Exception ex)
+ {
+ tcs.TrySetException(ex);
+ }
+ finally
+ {
+ ctsRegistration.Dispose();
+ }
+ },
+ cancellationToken,
+ TaskCreationOptions.LongRunning,
+ TaskScheduler.Default);
+
+ return tcs.Task;
+ }
+#endif
+
internal static partial class NativeMethods
{
///
diff --git a/src/Microsoft.Dism/DismApi.RemoveCapability.cs b/src/Microsoft.Dism/DismApi.RemoveCapability.cs
index c5a9112..c1832cf 100644
--- a/src/Microsoft.Dism/DismApi.RemoveCapability.cs
+++ b/src/Microsoft.Dism/DismApi.RemoveCapability.cs
@@ -5,6 +5,8 @@
using Microsoft.Win32.SafeHandles;
using System;
using System.Runtime.InteropServices;
+using System.Threading;
+using System.Threading.Tasks;
namespace Microsoft.Dism
{
@@ -42,6 +44,66 @@ public static void RemoveCapability(DismSession session, string capabilityName,
DismUtilities.ThrowIfFail(hresult, session);
}
+#if !NET40
+ ///
+ /// Asynchronously removes the capability from an image.
+ ///
+ /// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.
+ /// The name of the capability that is being removed.
+ /// An optional progress provider to receive progress updates.
+ /// A cancellation token to cancel the operation.
+ /// A representing the asynchronous operation.
+ /// When a failure occurs.
+ /// When the operation is canceled.
+ /// When the operation requires a reboot to complete.
+ public static Task RemoveCapabilityAsync(DismSession session, string capabilityName, IProgress? progress = null, CancellationToken cancellationToken = default)
+ {
+ var tcs = new TaskCompletionSource();
+
+ var ctsRegistration = default(CancellationTokenRegistration);
+
+ Task.Factory.StartNew(
+ () =>
+ {
+ try
+ {
+ var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
+
+ ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
+
+ int hresult = NativeMethods.DismRemoveCapability(session, capabilityName, dismProgress.EventHandle, dismProgress.DismProgressCallbackNative, IntPtr.Zero);
+
+ if (cancellationToken.IsCancellationRequested)
+ {
+ tcs.TrySetCanceled(cancellationToken);
+ }
+ else
+ {
+ DismUtilities.ThrowIfFail(hresult, session);
+ tcs.TrySetResult(true);
+ }
+ }
+ catch (OperationCanceledException)
+ {
+ tcs.TrySetCanceled(cancellationToken);
+ }
+ catch (Exception ex)
+ {
+ tcs.TrySetException(ex);
+ }
+ finally
+ {
+ ctsRegistration.Dispose();
+ }
+ },
+ cancellationToken,
+ TaskCreationOptions.LongRunning,
+ TaskScheduler.Default);
+
+ return tcs.Task;
+ }
+#endif
+
internal static partial class NativeMethods
{
///
diff --git a/src/Microsoft.Dism/DismApi.RemovePackage.cs b/src/Microsoft.Dism/DismApi.RemovePackage.cs
index 9b1e6e0..739234e 100644
--- a/src/Microsoft.Dism/DismApi.RemovePackage.cs
+++ b/src/Microsoft.Dism/DismApi.RemovePackage.cs
@@ -5,6 +5,8 @@
using Microsoft.Win32.SafeHandles;
using System;
using System.Runtime.InteropServices;
+using System.Threading;
+using System.Threading.Tasks;
namespace Microsoft.Dism
{
@@ -110,6 +112,90 @@ private static void RemovePackage(DismSession session, string identifier, DismPa
DismUtilities.ThrowIfFail(hresult, session);
}
+#if !NET40
+ ///
+ /// Asynchronously removes a package from an image by name.
+ ///
+ /// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.
+ /// The package name.
+ /// An optional progress provider to receive progress updates.
+ /// A cancellation token to cancel the operation.
+ /// A representing the asynchronous operation.
+ /// When a failure occurs.
+ /// When the operation is canceled.
+ /// When the operation requires a reboot to complete.
+ public static Task RemovePackageByNameAsync(DismSession session, string packageName, IProgress? progress = null, CancellationToken cancellationToken = default)
+ {
+ return RemovePackageAsync(session, packageName, DismPackageIdentifier.Name, progress, cancellationToken);
+ }
+
+ ///
+ /// Asynchronously removes a package from an image by path.
+ ///
+ /// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.
+ /// The package path.
+ /// An optional progress provider to receive progress updates.
+ /// A cancellation token to cancel the operation.
+ /// A representing the asynchronous operation.
+ /// When a failure occurs.
+ /// When the operation is canceled.
+ /// When the operation requires a reboot to complete.
+ public static Task RemovePackageByPathAsync(DismSession session, string packagePath, IProgress? progress = null, CancellationToken cancellationToken = default)
+ {
+ return RemovePackageAsync(session, packagePath, DismPackageIdentifier.Path, progress, cancellationToken);
+ }
+
+ ///
+ /// Asynchronously removes a package from an image.
+ ///
+ private static Task RemovePackageAsync(DismSession session, string identifier, DismPackageIdentifier packageIdentifier, IProgress? progress, CancellationToken cancellationToken)
+ {
+ var tcs = new TaskCompletionSource();
+
+ var ctsRegistration = default(CancellationTokenRegistration);
+
+ Task.Factory.StartNew(
+ () =>
+ {
+ try
+ {
+ var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
+
+ ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
+
+ int hresult = NativeMethods.DismRemovePackage(session, identifier, packageIdentifier, dismProgress.EventHandle, dismProgress.DismProgressCallbackNative, IntPtr.Zero);
+
+ if (cancellationToken.IsCancellationRequested)
+ {
+ tcs.TrySetCanceled(cancellationToken);
+ }
+ else
+ {
+ DismUtilities.ThrowIfFail(hresult, session);
+ tcs.TrySetResult(true);
+ }
+ }
+ catch (OperationCanceledException)
+ {
+ tcs.TrySetCanceled(cancellationToken);
+ }
+ catch (Exception ex)
+ {
+ tcs.TrySetException(ex);
+ }
+ finally
+ {
+ ctsRegistration.Dispose();
+ }
+ },
+ cancellationToken,
+ TaskCreationOptions.LongRunning,
+ TaskScheduler.Default);
+
+ return tcs.Task;
+ }
+#endif
+
internal static partial class NativeMethods
{
///
diff --git a/src/Microsoft.Dism/DismApi.RestoreImageHealth.cs b/src/Microsoft.Dism/DismApi.RestoreImageHealth.cs
index b3e43e1..5d60adf 100644
--- a/src/Microsoft.Dism/DismApi.RestoreImageHealth.cs
+++ b/src/Microsoft.Dism/DismApi.RestoreImageHealth.cs
@@ -6,6 +6,8 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
+using System.Threading;
+using System.Threading.Tasks;
namespace Microsoft.Dism
{
@@ -75,6 +77,69 @@ public static void RestoreImageHealth(DismSession session, bool limitAccess, Lis
DismUtilities.ThrowIfFail(hresult, session);
}
+#if !NET40
+ ///
+ /// Asynchronously repairs a corrupted image that has been identified as repairable by the CheckImageHealth Function.
+ ///
+ /// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.
+ /// Specifies whether the RestoreImageHealth method should contact Windows Update (WU) as a source location for downloading repair files. Before checking WU, DISM will check for the files in the sourcePaths provided and in any locations specified in the registry by Group Policy. If the files that are required to enable the feature are found in these other specified locations, this flag is ignored.
+ /// List of source locations to check for repair files.
+ /// An optional progress provider to receive progress updates.
+ /// A cancellation token to cancel the operation.
+ /// A representing the asynchronous operation.
+ /// When a failure occurs.
+ /// When the operation is canceled.
+ /// When the operation requires a reboot to complete.
+ public static Task RestoreImageHealthAsync(DismSession session, bool limitAccess, List? sourcePaths = null, IProgress? progress = null, CancellationToken cancellationToken = default)
+ {
+ var tcs = new TaskCompletionSource();
+
+ var ctsRegistration = default(CancellationTokenRegistration);
+
+ Task.Factory.StartNew(
+ () =>
+ {
+ try
+ {
+ string[] sourcePathsArray = sourcePaths?.ToArray() ?? new string[0];
+
+ var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
+
+ ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
+
+ int hresult = NativeMethods.DismRestoreImageHealth(session, sourcePathsArray, (uint)sourcePathsArray.Length, limitAccess, dismProgress.EventHandle, dismProgress.DismProgressCallbackNative, IntPtr.Zero);
+
+ if (cancellationToken.IsCancellationRequested)
+ {
+ tcs.TrySetCanceled(cancellationToken);
+ }
+ else
+ {
+ DismUtilities.ThrowIfFail(hresult, session);
+ tcs.TrySetResult(true);
+ }
+ }
+ catch (OperationCanceledException)
+ {
+ tcs.TrySetCanceled(cancellationToken);
+ }
+ catch (Exception ex)
+ {
+ tcs.TrySetException(ex);
+ }
+ finally
+ {
+ ctsRegistration.Dispose();
+ }
+ },
+ cancellationToken,
+ TaskCreationOptions.LongRunning,
+ TaskScheduler.Default);
+
+ return tcs.Task;
+ }
+#endif
+
internal static partial class NativeMethods
{
///
diff --git a/src/Microsoft.Dism/DismApi.SetEdition.cs b/src/Microsoft.Dism/DismApi.SetEdition.cs
index df29513..1d42f57 100644
--- a/src/Microsoft.Dism/DismApi.SetEdition.cs
+++ b/src/Microsoft.Dism/DismApi.SetEdition.cs
@@ -5,6 +5,8 @@
using Microsoft.Win32.SafeHandles;
using System;
using System.Runtime.InteropServices;
+using System.Threading;
+using System.Threading.Tasks;
namespace Microsoft.Dism
{
@@ -111,6 +113,91 @@ private static void SetEdition(DismSession session, string editionId, string? pr
DismUtilities.ThrowIfFail(hresult, session);
}
+#if !NET40
+ ///
+ /// Asynchronously changes an offline Windows image to a higher edition.
+ ///
+ /// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the method.
+ /// The edition to set the image to.
+ /// An optional progress provider to receive progress updates.
+ /// A cancellation token to cancel the operation.
+ /// A representing the asynchronous operation.
+ /// When a failure occurs.
+ /// When the operation is canceled.
+ /// When the operation requires a reboot to complete.
+ public static Task SetEditionAsync(DismSession session, string editionId, IProgress? progress = null, CancellationToken cancellationToken = default)
+ {
+ return SetEditionAsync(session, editionId, productKey: null, progress, cancellationToken);
+ }
+
+ ///
+ /// Asynchronously changes an offline Windows image to a higher edition and sets the product key.
+ ///
+ /// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the method.
+ /// The edition to set the image to.
+ /// A product key for the specified edition.
+ /// An optional progress provider to receive progress updates.
+ /// A cancellation token to cancel the operation.
+ /// A representing the asynchronous operation.
+ /// When a failure occurs.
+ /// When the operation is canceled.
+ /// When the operation requires a reboot to complete.
+ public static Task SetEditionAndProductKeyAsync(DismSession session, string editionId, string productKey, IProgress? progress = null, CancellationToken cancellationToken = default)
+ {
+ return SetEditionAsync(session, editionId, productKey, progress, cancellationToken);
+ }
+
+ ///
+ /// Asynchronously changes an offline Windows image to a higher edition and optionally sets the product key.
+ ///
+ private static Task SetEditionAsync(DismSession session, string editionId, string? productKey, IProgress? progress, CancellationToken cancellationToken)
+ {
+ var tcs = new TaskCompletionSource();
+
+ var ctsRegistration = default(CancellationTokenRegistration);
+
+ Task.Factory.StartNew(
+ () =>
+ {
+ try
+ {
+ var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
+
+ ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
+
+ int hresult = NativeMethods.DismSetEdition(session, editionId, productKey, dismProgress.EventHandle, dismProgress.DismProgressCallbackNative, IntPtr.Zero);
+
+ if (cancellationToken.IsCancellationRequested)
+ {
+ tcs.TrySetCanceled(cancellationToken);
+ }
+ else
+ {
+ DismUtilities.ThrowIfFail(hresult, session);
+ tcs.TrySetResult(true);
+ }
+ }
+ catch (OperationCanceledException)
+ {
+ tcs.TrySetCanceled(cancellationToken);
+ }
+ catch (Exception ex)
+ {
+ tcs.TrySetException(ex);
+ }
+ finally
+ {
+ ctsRegistration.Dispose();
+ }
+ },
+ cancellationToken,
+ TaskCreationOptions.LongRunning,
+ TaskScheduler.Default);
+
+ return tcs.Task;
+ }
+#endif
+
internal static partial class NativeMethods
{
///
diff --git a/src/Microsoft.Dism/DismApi.UnmountImage.cs b/src/Microsoft.Dism/DismApi.UnmountImage.cs
index 1fba9fc..73b7af9 100644
--- a/src/Microsoft.Dism/DismApi.UnmountImage.cs
+++ b/src/Microsoft.Dism/DismApi.UnmountImage.cs
@@ -5,6 +5,8 @@
using Microsoft.Win32.SafeHandles;
using System;
using System.Runtime.InteropServices;
+using System.Threading;
+using System.Threading.Tasks;
namespace Microsoft.Dism
{
@@ -56,6 +58,67 @@ public static void UnmountImage(string mountPath, bool commitChanges, Dism.DismP
DismUtilities.ThrowIfFail(hresult);
}
+#if !NET40
+ ///
+ /// Asynchronously unmounts a Windows image from a specified location.
+ ///
+ /// A relative or absolute path to the mount directory of the image.
+ /// Specifies whether or not the changes to the image should be saved.
+ /// An optional progress provider to receive progress updates.
+ /// A cancellation token to cancel the operation.
+ /// A representing the asynchronous operation.
+ /// When a failure occurs.
+ /// When the operation is canceled.
+ public static Task UnmountImageAsync(string mountPath, bool commitChanges, IProgress? progress = null, CancellationToken cancellationToken = default)
+ {
+ var tcs = new TaskCompletionSource();
+
+ var ctsRegistration = default(CancellationTokenRegistration);
+
+ Task.Factory.StartNew(
+ () =>
+ {
+ try
+ {
+ uint flags = commitChanges ? DISM_COMMIT_IMAGE : DISM_DISCARD_IMAGE;
+
+ var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
+
+ ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
+
+ int hresult = NativeMethods.DismUnmountImage(mountPath, flags, dismProgress.EventHandle, dismProgress.DismProgressCallbackNative, IntPtr.Zero);
+
+ if (cancellationToken.IsCancellationRequested)
+ {
+ tcs.TrySetCanceled(cancellationToken);
+ }
+ else
+ {
+ DismUtilities.ThrowIfFail(hresult);
+ tcs.TrySetResult(true);
+ }
+ }
+ catch (OperationCanceledException)
+ {
+ tcs.TrySetCanceled(cancellationToken);
+ }
+ catch (Exception ex)
+ {
+ tcs.TrySetException(ex);
+ }
+ finally
+ {
+ ctsRegistration.Dispose();
+ }
+ },
+ cancellationToken,
+ TaskCreationOptions.LongRunning,
+ TaskScheduler.Default);
+
+ return tcs.Task;
+ }
+#endif
+
internal static partial class NativeMethods
{
///
From 877a8aa4c39bc9a9cb6ab6da70a17cffd6524f6f Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Sun, 29 Mar 2026 21:16:35 +0000
Subject: [PATCH 05/10] Fix SA1137/SA1117 StyleCop indentation in async
Task.Factory.StartNew blocks
Reindent lambda body and trailing parameters in all 12 async method
files so that the opening brace, body, and remaining arguments are
consistently indented at 16 spaces (one level deeper than the method
call), satisfying SA1137 (same indentation) and SA1117 (each parameter
on its own line).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Rolling2405 <89894749+Rolling2405@users.noreply.github.com>
---
src/Microsoft.Dism/DismApi.AddCapability.cs | 54 +++++++++----------
src/Microsoft.Dism/DismApi.AddPackage.cs | 52 +++++++++---------
.../DismApi.CheckImageHealth.cs | 52 +++++++++---------
src/Microsoft.Dism/DismApi.CommitImage.cs | 54 +++++++++----------
src/Microsoft.Dism/DismApi.DisableFeature.cs | 52 +++++++++---------
src/Microsoft.Dism/DismApi.EnableFeature.cs | 54 +++++++++----------
src/Microsoft.Dism/DismApi.MountImage.cs | 54 +++++++++----------
.../DismApi.RemoveCapability.cs | 52 +++++++++---------
src/Microsoft.Dism/DismApi.RemovePackage.cs | 52 +++++++++---------
.../DismApi.RestoreImageHealth.cs | 54 +++++++++----------
src/Microsoft.Dism/DismApi.SetEdition.cs | 52 +++++++++---------
src/Microsoft.Dism/DismApi.UnmountImage.cs | 54 +++++++++----------
12 files changed, 318 insertions(+), 318 deletions(-)
diff --git a/src/Microsoft.Dism/DismApi.AddCapability.cs b/src/Microsoft.Dism/DismApi.AddCapability.cs
index 7e1b924..da26570 100644
--- a/src/Microsoft.Dism/DismApi.AddCapability.cs
+++ b/src/Microsoft.Dism/DismApi.AddCapability.cs
@@ -87,43 +87,43 @@ public static Task AddCapabilityAsync(DismSession session, string capabilityName
Task.Factory.StartNew(
() =>
- {
- try
{
- string[] sourcePathsArray = sourcePaths?.ToArray() ?? new string[0];
+ try
+ {
+ string[] sourcePathsArray = sourcePaths?.ToArray() ?? new string[0];
- var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
+ var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
- ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
+ ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
- int hresult = NativeMethods.DismAddCapability(session, capabilityName, limitAccess, sourcePathsArray, (uint)sourcePathsArray.Length, dismProgress.EventHandle, dismProgress.DismProgressCallbackNative, IntPtr.Zero);
+ int hresult = NativeMethods.DismAddCapability(session, capabilityName, limitAccess, sourcePathsArray, (uint)sourcePathsArray.Length, dismProgress.EventHandle, dismProgress.DismProgressCallbackNative, IntPtr.Zero);
- if (cancellationToken.IsCancellationRequested)
+ if (cancellationToken.IsCancellationRequested)
+ {
+ tcs.TrySetCanceled(cancellationToken);
+ }
+ else
+ {
+ DismUtilities.ThrowIfFail(hresult, session);
+ tcs.TrySetResult(true);
+ }
+ }
+ catch (OperationCanceledException)
{
tcs.TrySetCanceled(cancellationToken);
}
- else
+ catch (Exception ex)
{
- DismUtilities.ThrowIfFail(hresult, session);
- tcs.TrySetResult(true);
+ tcs.TrySetException(ex);
}
- }
- catch (OperationCanceledException)
- {
- tcs.TrySetCanceled(cancellationToken);
- }
- catch (Exception ex)
- {
- tcs.TrySetException(ex);
- }
- finally
- {
- ctsRegistration.Dispose();
- }
- },
- cancellationToken,
- TaskCreationOptions.LongRunning,
- TaskScheduler.Default);
+ finally
+ {
+ ctsRegistration.Dispose();
+ }
+ },
+ cancellationToken,
+ TaskCreationOptions.LongRunning,
+ TaskScheduler.Default);
return tcs.Task;
}
diff --git a/src/Microsoft.Dism/DismApi.AddPackage.cs b/src/Microsoft.Dism/DismApi.AddPackage.cs
index fa40571..38fae3f 100644
--- a/src/Microsoft.Dism/DismApi.AddPackage.cs
+++ b/src/Microsoft.Dism/DismApi.AddPackage.cs
@@ -90,41 +90,41 @@ public static Task AddPackageAsync(DismSession session, string packagePath, bool
Task.Factory.StartNew(
() =>
- {
- try
{
- var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
+ try
+ {
+ var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
- ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
+ ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
- int hresult = NativeMethods.DismAddPackage(session, packagePath, ignoreCheck, preventPending, dismProgress.EventHandle, dismProgress.DismProgressCallbackNative, IntPtr.Zero);
+ int hresult = NativeMethods.DismAddPackage(session, packagePath, ignoreCheck, preventPending, dismProgress.EventHandle, dismProgress.DismProgressCallbackNative, IntPtr.Zero);
- if (cancellationToken.IsCancellationRequested)
+ if (cancellationToken.IsCancellationRequested)
+ {
+ tcs.TrySetCanceled(cancellationToken);
+ }
+ else
+ {
+ DismUtilities.ThrowIfFail(hresult, session);
+ tcs.TrySetResult(true);
+ }
+ }
+ catch (OperationCanceledException)
{
tcs.TrySetCanceled(cancellationToken);
}
- else
+ catch (Exception ex)
{
- DismUtilities.ThrowIfFail(hresult, session);
- tcs.TrySetResult(true);
+ tcs.TrySetException(ex);
}
- }
- catch (OperationCanceledException)
- {
- tcs.TrySetCanceled(cancellationToken);
- }
- catch (Exception ex)
- {
- tcs.TrySetException(ex);
- }
- finally
- {
- ctsRegistration.Dispose();
- }
- },
- cancellationToken,
- TaskCreationOptions.LongRunning,
- TaskScheduler.Default);
+ finally
+ {
+ ctsRegistration.Dispose();
+ }
+ },
+ cancellationToken,
+ TaskCreationOptions.LongRunning,
+ TaskScheduler.Default);
return tcs.Task;
}
diff --git a/src/Microsoft.Dism/DismApi.CheckImageHealth.cs b/src/Microsoft.Dism/DismApi.CheckImageHealth.cs
index 2187b0b..84b667a 100644
--- a/src/Microsoft.Dism/DismApi.CheckImageHealth.cs
+++ b/src/Microsoft.Dism/DismApi.CheckImageHealth.cs
@@ -79,41 +79,41 @@ public static Task CheckImageHealthAsync(DismSession sessi
Task.Factory.StartNew(
() =>
- {
- try
{
- var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
+ try
+ {
+ var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
- ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
+ ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
- int hresult = NativeMethods.DismCheckImageHealth(session, scanImage, dismProgress.EventHandle, dismProgress.DismProgressCallbackNative, IntPtr.Zero, out DismImageHealthState imageHealthState);
+ int hresult = NativeMethods.DismCheckImageHealth(session, scanImage, dismProgress.EventHandle, dismProgress.DismProgressCallbackNative, IntPtr.Zero, out DismImageHealthState imageHealthState);
- if (cancellationToken.IsCancellationRequested)
+ if (cancellationToken.IsCancellationRequested)
+ {
+ tcs.TrySetCanceled(cancellationToken);
+ }
+ else
+ {
+ DismUtilities.ThrowIfFail(hresult, session);
+ tcs.TrySetResult(imageHealthState);
+ }
+ }
+ catch (OperationCanceledException)
{
tcs.TrySetCanceled(cancellationToken);
}
- else
+ catch (Exception ex)
{
- DismUtilities.ThrowIfFail(hresult, session);
- tcs.TrySetResult(imageHealthState);
+ tcs.TrySetException(ex);
}
- }
- catch (OperationCanceledException)
- {
- tcs.TrySetCanceled(cancellationToken);
- }
- catch (Exception ex)
- {
- tcs.TrySetException(ex);
- }
- finally
- {
- ctsRegistration.Dispose();
- }
- },
- cancellationToken,
- TaskCreationOptions.LongRunning,
- TaskScheduler.Default);
+ finally
+ {
+ ctsRegistration.Dispose();
+ }
+ },
+ cancellationToken,
+ TaskCreationOptions.LongRunning,
+ TaskScheduler.Default);
return tcs.Task;
}
diff --git a/src/Microsoft.Dism/DismApi.CommitImage.cs b/src/Microsoft.Dism/DismApi.CommitImage.cs
index b42f5db..cd0aa76 100644
--- a/src/Microsoft.Dism/DismApi.CommitImage.cs
+++ b/src/Microsoft.Dism/DismApi.CommitImage.cs
@@ -77,43 +77,43 @@ public static Task CommitImageAsync(DismSession session, bool discardChanges, IP
Task.Factory.StartNew(
() =>
- {
- try
{
- UInt32 flags = discardChanges ? DISM_DISCARD_IMAGE : DISM_COMMIT_IMAGE;
+ try
+ {
+ UInt32 flags = discardChanges ? DISM_DISCARD_IMAGE : DISM_COMMIT_IMAGE;
- var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
+ var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
- ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
+ ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
- int hresult = NativeMethods.DismCommitImage(session, flags, dismProgress.EventHandle, dismProgress.DismProgressCallbackNative, IntPtr.Zero);
+ int hresult = NativeMethods.DismCommitImage(session, flags, dismProgress.EventHandle, dismProgress.DismProgressCallbackNative, IntPtr.Zero);
- if (cancellationToken.IsCancellationRequested)
+ if (cancellationToken.IsCancellationRequested)
+ {
+ tcs.TrySetCanceled(cancellationToken);
+ }
+ else
+ {
+ DismUtilities.ThrowIfFail(hresult, session);
+ tcs.TrySetResult(true);
+ }
+ }
+ catch (OperationCanceledException)
{
tcs.TrySetCanceled(cancellationToken);
}
- else
+ catch (Exception ex)
{
- DismUtilities.ThrowIfFail(hresult, session);
- tcs.TrySetResult(true);
+ tcs.TrySetException(ex);
}
- }
- catch (OperationCanceledException)
- {
- tcs.TrySetCanceled(cancellationToken);
- }
- catch (Exception ex)
- {
- tcs.TrySetException(ex);
- }
- finally
- {
- ctsRegistration.Dispose();
- }
- },
- cancellationToken,
- TaskCreationOptions.LongRunning,
- TaskScheduler.Default);
+ finally
+ {
+ ctsRegistration.Dispose();
+ }
+ },
+ cancellationToken,
+ TaskCreationOptions.LongRunning,
+ TaskScheduler.Default);
return tcs.Task;
}
diff --git a/src/Microsoft.Dism/DismApi.DisableFeature.cs b/src/Microsoft.Dism/DismApi.DisableFeature.cs
index 3f50506..9be4485 100644
--- a/src/Microsoft.Dism/DismApi.DisableFeature.cs
+++ b/src/Microsoft.Dism/DismApi.DisableFeature.cs
@@ -94,41 +94,41 @@ public static Task DisableFeatureAsync(DismSession session, string featureName,
Task.Factory.StartNew(
() =>
- {
- try
{
- var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
+ try
+ {
+ var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
- ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
+ ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
- int hresult = NativeMethods.DismDisableFeature(session, featureName, packageName, removePayload, dismProgress.EventHandle, dismProgress.DismProgressCallbackNative, IntPtr.Zero);
+ int hresult = NativeMethods.DismDisableFeature(session, featureName, packageName, removePayload, dismProgress.EventHandle, dismProgress.DismProgressCallbackNative, IntPtr.Zero);
- if (cancellationToken.IsCancellationRequested)
+ if (cancellationToken.IsCancellationRequested)
+ {
+ tcs.TrySetCanceled(cancellationToken);
+ }
+ else
+ {
+ DismUtilities.ThrowIfFail(hresult, session);
+ tcs.TrySetResult(true);
+ }
+ }
+ catch (OperationCanceledException)
{
tcs.TrySetCanceled(cancellationToken);
}
- else
+ catch (Exception ex)
{
- DismUtilities.ThrowIfFail(hresult, session);
- tcs.TrySetResult(true);
+ tcs.TrySetException(ex);
}
- }
- catch (OperationCanceledException)
- {
- tcs.TrySetCanceled(cancellationToken);
- }
- catch (Exception ex)
- {
- tcs.TrySetException(ex);
- }
- finally
- {
- ctsRegistration.Dispose();
- }
- },
- cancellationToken,
- TaskCreationOptions.LongRunning,
- TaskScheduler.Default);
+ finally
+ {
+ ctsRegistration.Dispose();
+ }
+ },
+ cancellationToken,
+ TaskCreationOptions.LongRunning,
+ TaskScheduler.Default);
return tcs.Task;
}
diff --git a/src/Microsoft.Dism/DismApi.EnableFeature.cs b/src/Microsoft.Dism/DismApi.EnableFeature.cs
index 270a5ee..2a1b154 100644
--- a/src/Microsoft.Dism/DismApi.EnableFeature.cs
+++ b/src/Microsoft.Dism/DismApi.EnableFeature.cs
@@ -315,43 +315,43 @@ private static Task EnableFeatureAsync(DismSession session, string featureName,
Task.Factory.StartNew(
() =>
- {
- try
{
- string[] sourcePathsArray = sourcePaths?.ToArray() ?? new string[0];
+ try
+ {
+ string[] sourcePathsArray = sourcePaths?.ToArray() ?? new string[0];
- var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
+ var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
- ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
+ ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
- int hresult = NativeMethods.DismEnableFeature(session, featureName, identifier, identifier == null ? DismPackageIdentifier.None : packageIdentifier, limitAccess, sourcePathsArray, (uint)sourcePathsArray.Length, enableAll, dismProgress.EventHandle, dismProgress.DismProgressCallbackNative, IntPtr.Zero);
+ int hresult = NativeMethods.DismEnableFeature(session, featureName, identifier, identifier == null ? DismPackageIdentifier.None : packageIdentifier, limitAccess, sourcePathsArray, (uint)sourcePathsArray.Length, enableAll, dismProgress.EventHandle, dismProgress.DismProgressCallbackNative, IntPtr.Zero);
- if (cancellationToken.IsCancellationRequested)
+ if (cancellationToken.IsCancellationRequested)
+ {
+ tcs.TrySetCanceled(cancellationToken);
+ }
+ else
+ {
+ DismUtilities.ThrowIfFail(hresult, session);
+ tcs.TrySetResult(true);
+ }
+ }
+ catch (OperationCanceledException)
{
tcs.TrySetCanceled(cancellationToken);
}
- else
+ catch (Exception ex)
{
- DismUtilities.ThrowIfFail(hresult, session);
- tcs.TrySetResult(true);
+ tcs.TrySetException(ex);
}
- }
- catch (OperationCanceledException)
- {
- tcs.TrySetCanceled(cancellationToken);
- }
- catch (Exception ex)
- {
- tcs.TrySetException(ex);
- }
- finally
- {
- ctsRegistration.Dispose();
- }
- },
- cancellationToken,
- TaskCreationOptions.LongRunning,
- TaskScheduler.Default);
+ finally
+ {
+ ctsRegistration.Dispose();
+ }
+ },
+ cancellationToken,
+ TaskCreationOptions.LongRunning,
+ TaskScheduler.Default);
return tcs.Task;
}
diff --git a/src/Microsoft.Dism/DismApi.MountImage.cs b/src/Microsoft.Dism/DismApi.MountImage.cs
index dc73b81..7d267e5 100644
--- a/src/Microsoft.Dism/DismApi.MountImage.cs
+++ b/src/Microsoft.Dism/DismApi.MountImage.cs
@@ -291,43 +291,43 @@ private static Task MountImageAsync(string imageFilePath, string mountPath, int
Task.Factory.StartNew(
() =>
- {
- try
{
- uint flags = (readOnly ? DISM_MOUNT_READONLY : DISM_MOUNT_READWRITE) | (uint)options;
+ try
+ {
+ uint flags = (readOnly ? DISM_MOUNT_READONLY : DISM_MOUNT_READWRITE) | (uint)options;
- var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
+ var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
- ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
+ ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
- int hresult = NativeMethods.DismMountImage(imageFilePath, mountPath, (uint)imageIndex, imageName, imageIdentifier, flags, dismProgress.EventHandle, dismProgress.DismProgressCallbackNative, IntPtr.Zero);
+ int hresult = NativeMethods.DismMountImage(imageFilePath, mountPath, (uint)imageIndex, imageName, imageIdentifier, flags, dismProgress.EventHandle, dismProgress.DismProgressCallbackNative, IntPtr.Zero);
- if (cancellationToken.IsCancellationRequested)
+ if (cancellationToken.IsCancellationRequested)
+ {
+ tcs.TrySetCanceled(cancellationToken);
+ }
+ else
+ {
+ DismUtilities.ThrowIfFail(hresult);
+ tcs.TrySetResult(true);
+ }
+ }
+ catch (OperationCanceledException)
{
tcs.TrySetCanceled(cancellationToken);
}
- else
+ catch (Exception ex)
{
- DismUtilities.ThrowIfFail(hresult);
- tcs.TrySetResult(true);
+ tcs.TrySetException(ex);
}
- }
- catch (OperationCanceledException)
- {
- tcs.TrySetCanceled(cancellationToken);
- }
- catch (Exception ex)
- {
- tcs.TrySetException(ex);
- }
- finally
- {
- ctsRegistration.Dispose();
- }
- },
- cancellationToken,
- TaskCreationOptions.LongRunning,
- TaskScheduler.Default);
+ finally
+ {
+ ctsRegistration.Dispose();
+ }
+ },
+ cancellationToken,
+ TaskCreationOptions.LongRunning,
+ TaskScheduler.Default);
return tcs.Task;
}
diff --git a/src/Microsoft.Dism/DismApi.RemoveCapability.cs b/src/Microsoft.Dism/DismApi.RemoveCapability.cs
index c1832cf..e296a04 100644
--- a/src/Microsoft.Dism/DismApi.RemoveCapability.cs
+++ b/src/Microsoft.Dism/DismApi.RemoveCapability.cs
@@ -64,41 +64,41 @@ public static Task RemoveCapabilityAsync(DismSession session, string capabilityN
Task.Factory.StartNew(
() =>
- {
- try
{
- var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
+ try
+ {
+ var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
- ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
+ ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
- int hresult = NativeMethods.DismRemoveCapability(session, capabilityName, dismProgress.EventHandle, dismProgress.DismProgressCallbackNative, IntPtr.Zero);
+ int hresult = NativeMethods.DismRemoveCapability(session, capabilityName, dismProgress.EventHandle, dismProgress.DismProgressCallbackNative, IntPtr.Zero);
- if (cancellationToken.IsCancellationRequested)
+ if (cancellationToken.IsCancellationRequested)
+ {
+ tcs.TrySetCanceled(cancellationToken);
+ }
+ else
+ {
+ DismUtilities.ThrowIfFail(hresult, session);
+ tcs.TrySetResult(true);
+ }
+ }
+ catch (OperationCanceledException)
{
tcs.TrySetCanceled(cancellationToken);
}
- else
+ catch (Exception ex)
{
- DismUtilities.ThrowIfFail(hresult, session);
- tcs.TrySetResult(true);
+ tcs.TrySetException(ex);
}
- }
- catch (OperationCanceledException)
- {
- tcs.TrySetCanceled(cancellationToken);
- }
- catch (Exception ex)
- {
- tcs.TrySetException(ex);
- }
- finally
- {
- ctsRegistration.Dispose();
- }
- },
- cancellationToken,
- TaskCreationOptions.LongRunning,
- TaskScheduler.Default);
+ finally
+ {
+ ctsRegistration.Dispose();
+ }
+ },
+ cancellationToken,
+ TaskCreationOptions.LongRunning,
+ TaskScheduler.Default);
return tcs.Task;
}
diff --git a/src/Microsoft.Dism/DismApi.RemovePackage.cs b/src/Microsoft.Dism/DismApi.RemovePackage.cs
index 739234e..e712507 100644
--- a/src/Microsoft.Dism/DismApi.RemovePackage.cs
+++ b/src/Microsoft.Dism/DismApi.RemovePackage.cs
@@ -156,41 +156,41 @@ private static Task RemovePackageAsync(DismSession session, string identifier, D
Task.Factory.StartNew(
() =>
- {
- try
{
- var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
+ try
+ {
+ var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
- ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
+ ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
- int hresult = NativeMethods.DismRemovePackage(session, identifier, packageIdentifier, dismProgress.EventHandle, dismProgress.DismProgressCallbackNative, IntPtr.Zero);
+ int hresult = NativeMethods.DismRemovePackage(session, identifier, packageIdentifier, dismProgress.EventHandle, dismProgress.DismProgressCallbackNative, IntPtr.Zero);
- if (cancellationToken.IsCancellationRequested)
+ if (cancellationToken.IsCancellationRequested)
+ {
+ tcs.TrySetCanceled(cancellationToken);
+ }
+ else
+ {
+ DismUtilities.ThrowIfFail(hresult, session);
+ tcs.TrySetResult(true);
+ }
+ }
+ catch (OperationCanceledException)
{
tcs.TrySetCanceled(cancellationToken);
}
- else
+ catch (Exception ex)
{
- DismUtilities.ThrowIfFail(hresult, session);
- tcs.TrySetResult(true);
+ tcs.TrySetException(ex);
}
- }
- catch (OperationCanceledException)
- {
- tcs.TrySetCanceled(cancellationToken);
- }
- catch (Exception ex)
- {
- tcs.TrySetException(ex);
- }
- finally
- {
- ctsRegistration.Dispose();
- }
- },
- cancellationToken,
- TaskCreationOptions.LongRunning,
- TaskScheduler.Default);
+ finally
+ {
+ ctsRegistration.Dispose();
+ }
+ },
+ cancellationToken,
+ TaskCreationOptions.LongRunning,
+ TaskScheduler.Default);
return tcs.Task;
}
diff --git a/src/Microsoft.Dism/DismApi.RestoreImageHealth.cs b/src/Microsoft.Dism/DismApi.RestoreImageHealth.cs
index 5d60adf..ec515de 100644
--- a/src/Microsoft.Dism/DismApi.RestoreImageHealth.cs
+++ b/src/Microsoft.Dism/DismApi.RestoreImageHealth.cs
@@ -98,43 +98,43 @@ public static Task RestoreImageHealthAsync(DismSession session, bool limitAccess
Task.Factory.StartNew(
() =>
- {
- try
{
- string[] sourcePathsArray = sourcePaths?.ToArray() ?? new string[0];
+ try
+ {
+ string[] sourcePathsArray = sourcePaths?.ToArray() ?? new string[0];
- var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
+ var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
- ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
+ ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
- int hresult = NativeMethods.DismRestoreImageHealth(session, sourcePathsArray, (uint)sourcePathsArray.Length, limitAccess, dismProgress.EventHandle, dismProgress.DismProgressCallbackNative, IntPtr.Zero);
+ int hresult = NativeMethods.DismRestoreImageHealth(session, sourcePathsArray, (uint)sourcePathsArray.Length, limitAccess, dismProgress.EventHandle, dismProgress.DismProgressCallbackNative, IntPtr.Zero);
- if (cancellationToken.IsCancellationRequested)
+ if (cancellationToken.IsCancellationRequested)
+ {
+ tcs.TrySetCanceled(cancellationToken);
+ }
+ else
+ {
+ DismUtilities.ThrowIfFail(hresult, session);
+ tcs.TrySetResult(true);
+ }
+ }
+ catch (OperationCanceledException)
{
tcs.TrySetCanceled(cancellationToken);
}
- else
+ catch (Exception ex)
{
- DismUtilities.ThrowIfFail(hresult, session);
- tcs.TrySetResult(true);
+ tcs.TrySetException(ex);
}
- }
- catch (OperationCanceledException)
- {
- tcs.TrySetCanceled(cancellationToken);
- }
- catch (Exception ex)
- {
- tcs.TrySetException(ex);
- }
- finally
- {
- ctsRegistration.Dispose();
- }
- },
- cancellationToken,
- TaskCreationOptions.LongRunning,
- TaskScheduler.Default);
+ finally
+ {
+ ctsRegistration.Dispose();
+ }
+ },
+ cancellationToken,
+ TaskCreationOptions.LongRunning,
+ TaskScheduler.Default);
return tcs.Task;
}
diff --git a/src/Microsoft.Dism/DismApi.SetEdition.cs b/src/Microsoft.Dism/DismApi.SetEdition.cs
index 1d42f57..0003f40 100644
--- a/src/Microsoft.Dism/DismApi.SetEdition.cs
+++ b/src/Microsoft.Dism/DismApi.SetEdition.cs
@@ -158,41 +158,41 @@ private static Task SetEditionAsync(DismSession session, string editionId, strin
Task.Factory.StartNew(
() =>
- {
- try
{
- var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
+ try
+ {
+ var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
- ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
+ ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
- int hresult = NativeMethods.DismSetEdition(session, editionId, productKey, dismProgress.EventHandle, dismProgress.DismProgressCallbackNative, IntPtr.Zero);
+ int hresult = NativeMethods.DismSetEdition(session, editionId, productKey, dismProgress.EventHandle, dismProgress.DismProgressCallbackNative, IntPtr.Zero);
- if (cancellationToken.IsCancellationRequested)
+ if (cancellationToken.IsCancellationRequested)
+ {
+ tcs.TrySetCanceled(cancellationToken);
+ }
+ else
+ {
+ DismUtilities.ThrowIfFail(hresult, session);
+ tcs.TrySetResult(true);
+ }
+ }
+ catch (OperationCanceledException)
{
tcs.TrySetCanceled(cancellationToken);
}
- else
+ catch (Exception ex)
{
- DismUtilities.ThrowIfFail(hresult, session);
- tcs.TrySetResult(true);
+ tcs.TrySetException(ex);
}
- }
- catch (OperationCanceledException)
- {
- tcs.TrySetCanceled(cancellationToken);
- }
- catch (Exception ex)
- {
- tcs.TrySetException(ex);
- }
- finally
- {
- ctsRegistration.Dispose();
- }
- },
- cancellationToken,
- TaskCreationOptions.LongRunning,
- TaskScheduler.Default);
+ finally
+ {
+ ctsRegistration.Dispose();
+ }
+ },
+ cancellationToken,
+ TaskCreationOptions.LongRunning,
+ TaskScheduler.Default);
return tcs.Task;
}
diff --git a/src/Microsoft.Dism/DismApi.UnmountImage.cs b/src/Microsoft.Dism/DismApi.UnmountImage.cs
index 73b7af9..95527cd 100644
--- a/src/Microsoft.Dism/DismApi.UnmountImage.cs
+++ b/src/Microsoft.Dism/DismApi.UnmountImage.cs
@@ -77,43 +77,43 @@ public static Task UnmountImageAsync(string mountPath, bool commitChanges, IProg
Task.Factory.StartNew(
() =>
- {
- try
{
- uint flags = commitChanges ? DISM_COMMIT_IMAGE : DISM_DISCARD_IMAGE;
+ try
+ {
+ uint flags = commitChanges ? DISM_COMMIT_IMAGE : DISM_DISCARD_IMAGE;
- var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
+ var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
- ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
+ ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
- int hresult = NativeMethods.DismUnmountImage(mountPath, flags, dismProgress.EventHandle, dismProgress.DismProgressCallbackNative, IntPtr.Zero);
+ int hresult = NativeMethods.DismUnmountImage(mountPath, flags, dismProgress.EventHandle, dismProgress.DismProgressCallbackNative, IntPtr.Zero);
- if (cancellationToken.IsCancellationRequested)
+ if (cancellationToken.IsCancellationRequested)
+ {
+ tcs.TrySetCanceled(cancellationToken);
+ }
+ else
+ {
+ DismUtilities.ThrowIfFail(hresult);
+ tcs.TrySetResult(true);
+ }
+ }
+ catch (OperationCanceledException)
{
tcs.TrySetCanceled(cancellationToken);
}
- else
+ catch (Exception ex)
{
- DismUtilities.ThrowIfFail(hresult);
- tcs.TrySetResult(true);
+ tcs.TrySetException(ex);
}
- }
- catch (OperationCanceledException)
- {
- tcs.TrySetCanceled(cancellationToken);
- }
- catch (Exception ex)
- {
- tcs.TrySetException(ex);
- }
- finally
- {
- ctsRegistration.Dispose();
- }
- },
- cancellationToken,
- TaskCreationOptions.LongRunning,
- TaskScheduler.Default);
+ finally
+ {
+ ctsRegistration.Dispose();
+ }
+ },
+ cancellationToken,
+ TaskCreationOptions.LongRunning,
+ TaskScheduler.Default);
return tcs.Task;
}
From 79f90dff9fde1f79ddc334932eb98f34172f5191 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Sun, 29 Mar 2026 21:22:43 +0000
Subject: [PATCH 06/10] Fix SA1202: move public async methods before private
sync methods
the private sync helper methods in 4 files to satisfy SA1202
('public' members should come before 'private' members):
- DismApi.EnableFeature.cs
- DismApi.MountImage.cs
- DismApi.RemovePackage.cs
- DismApi.SetEdition.cs
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Rolling2405 <89894749+Rolling2405@users.noreply.github.com>
---
src/Microsoft.Dism/DismApi.EnableFeature.cs | 74 ++++++++++-----------
src/Microsoft.Dism/DismApi.MountImage.cs | 54 +++++++--------
src/Microsoft.Dism/DismApi.RemovePackage.cs | 36 +++++-----
src/Microsoft.Dism/DismApi.SetEdition.cs | 40 +++++------
4 files changed, 102 insertions(+), 102 deletions(-)
diff --git a/src/Microsoft.Dism/DismApi.EnableFeature.cs b/src/Microsoft.Dism/DismApi.EnableFeature.cs
index 2a1b154..b489fc3 100644
--- a/src/Microsoft.Dism/DismApi.EnableFeature.cs
+++ b/src/Microsoft.Dism/DismApi.EnableFeature.cs
@@ -207,43 +207,6 @@ public static void EnableFeature(DismSession session, string featureName, bool l
EnableFeature(session, featureName, identifier: null, DismPackageIdentifier.None, limitAccess, enableAll, sourcePaths, progressCallback, userData);
}
- ///
- /// Enables a feature from the specified package path.
- ///
- /// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.
- /// The name of the feature that is being enabled. To enable more than one feature, separate each feature name with a semicolon.
- /// A package name or absolute path.
- /// A DismPackageIdentifier value.
- /// Specifies whether Windows Update (WU) should be contacted as a source location for downloading files if none are found in other specified locations. Before checking WU, DISM will check for the files in the SourcePaths provided and in any locations specified in the registry by group policy. If the files required to enable the feature are still present on the computer, this flag is ignored.
- /// Specifies whether to enable all dependencies of the feature. If the specified feature or any one of its dependencies cannot be enabled, none of them will be changed from their existing state.
- /// A list of source locations to check for files needed to enable the feature.
- /// A progress callback method to invoke when progress is made.
- /// Optional user data to pass to the DismProgressCallback method.
- /// When a failure occurs.
- private static void EnableFeature(DismSession session, string featureName, string? identifier, DismPackageIdentifier packageIdentifier, bool limitAccess, bool enableAll, List? sourcePaths, Microsoft.Dism.DismProgressCallback? progressCallback, object? userData)
- {
- // Get the list of source paths as an array
- string[] sourcePathsArray = sourcePaths?.ToArray() ?? new string[0];
-
- // Create a DismProgress object to wrap the callback and allow cancellation
- DismProgress progress = new DismProgress(progressCallback, userData);
-
- int hresult = NativeMethods.DismEnableFeature(
- session: session,
- featureName: featureName,
- identifier: identifier,
- packageIdentifier: identifier == null ? DismPackageIdentifier.None : packageIdentifier,
- limitAccess: limitAccess,
- sourcePaths: sourcePathsArray,
- sourcePathCount: (uint)sourcePathsArray.Length,
- enableAll: enableAll,
- cancelEvent: progress.EventHandle,
- progress: progress.DismProgressCallbackNative,
- userData: IntPtr.Zero);
-
- DismUtilities.ThrowIfFail(hresult, session);
- }
-
#if !NET40
///
/// Asynchronously enables a feature from the default package.
@@ -357,6 +320,43 @@ private static Task EnableFeatureAsync(DismSession session, string featureName,
}
#endif
+ ///
+ /// Enables a feature from the specified package path.
+ ///
+ /// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.
+ /// The name of the feature that is being enabled. To enable more than one feature, separate each feature name with a semicolon.
+ /// A package name or absolute path.
+ /// A DismPackageIdentifier value.
+ /// Specifies whether Windows Update (WU) should be contacted as a source location for downloading files if none are found in other specified locations. Before checking WU, DISM will check for the files in the SourcePaths provided and in any locations specified in the registry by group policy. If the files required to enable the feature are still present on the computer, this flag is ignored.
+ /// Specifies whether to enable all dependencies of the feature. If the specified feature or any one of its dependencies cannot be enabled, none of them will be changed from their existing state.
+ /// A list of source locations to check for files needed to enable the feature.
+ /// A progress callback method to invoke when progress is made.
+ /// Optional user data to pass to the DismProgressCallback method.
+ /// When a failure occurs.
+ private static void EnableFeature(DismSession session, string featureName, string? identifier, DismPackageIdentifier packageIdentifier, bool limitAccess, bool enableAll, List? sourcePaths, Microsoft.Dism.DismProgressCallback? progressCallback, object? userData)
+ {
+ // Get the list of source paths as an array
+ string[] sourcePathsArray = sourcePaths?.ToArray() ?? new string[0];
+
+ // Create a DismProgress object to wrap the callback and allow cancellation
+ DismProgress progress = new DismProgress(progressCallback, userData);
+
+ int hresult = NativeMethods.DismEnableFeature(
+ session: session,
+ featureName: featureName,
+ identifier: identifier,
+ packageIdentifier: identifier == null ? DismPackageIdentifier.None : packageIdentifier,
+ limitAccess: limitAccess,
+ sourcePaths: sourcePathsArray,
+ sourcePathCount: (uint)sourcePathsArray.Length,
+ enableAll: enableAll,
+ cancelEvent: progress.EventHandle,
+ progress: progress.DismProgressCallbackNative,
+ userData: IntPtr.Zero);
+
+ DismUtilities.ThrowIfFail(hresult, session);
+ }
+
internal static partial class NativeMethods
{
///
diff --git a/src/Microsoft.Dism/DismApi.MountImage.cs b/src/Microsoft.Dism/DismApi.MountImage.cs
index 7d267e5..da14a30 100644
--- a/src/Microsoft.Dism/DismApi.MountImage.cs
+++ b/src/Microsoft.Dism/DismApi.MountImage.cs
@@ -218,31 +218,6 @@ public static void MountImage(string imageFilePath, string mountPath, string? im
MountImage(imageFilePath, mountPath, 0, imageName, DismImageIdentifier.ImageName, readOnly, options, progressCallback, userData);
}
- ///
- /// Mounts a WIM or VHD image file to a specified location.
- ///
- /// The path to the WIM or VHD file on the local computer. A .wim, .vhd, or .vhdx file name extension is required.
- /// The path of the location where the image should be mounted. This mount path must already exist on the computer. The Windows image in a .wim, .vhd, or .vhdx file can be mounted to an empty folder on an NTFS formatted drive. A Windows image in a .vhd or .vhdx file can also be mounted to an unassigned drive letter. You cannot mount an image to the root of the existing drive.
- /// The index of the image in the WIM file that you want to mount. For a VHD file, you must specify an index of 1.
- /// The name of the image that you want to mount.
- /// A DismImageIdentifier Enumeration value such as DismImageIndex.
- /// Specifies if the image should be mounted in read-only mode.
- /// Specifies options to use when mounting an image.
- /// A progress callback method to invoke when progress is made.
- /// Optional user data to pass to the DismProgressCallback method.
- private static void MountImage(string imageFilePath, string mountPath, int imageIndex, string? imageName, DismImageIdentifier imageIdentifier, bool readOnly, DismMountImageOptions options, Microsoft.Dism.DismProgressCallback? progressCallback, object? userData)
- {
- // Determine the flags to pass to the native call
- uint flags = (readOnly ? DISM_MOUNT_READONLY : DISM_MOUNT_READWRITE) | (uint)options;
-
- // Create a DismProgress object to wrap the callback and allow cancellation
- DismProgress progress = new DismProgress(progressCallback, userData);
-
- int hresult = NativeMethods.DismMountImage(imageFilePath, mountPath, (uint)imageIndex, imageName, imageIdentifier, flags, progress.EventHandle, progress.DismProgressCallbackNative, IntPtr.Zero);
-
- DismUtilities.ThrowIfFail(hresult);
- }
-
#if !NET40
///
/// Asynchronously mounts a WIM or VHD image file to a specified location using an image index.
@@ -257,7 +232,7 @@ private static void MountImage(string imageFilePath, string mountPath, int image
/// A representing the asynchronous operation.
/// When a failure occurs.
/// When the operation is canceled.
- public static Task MountImageAsync(string imageFilePath, string mountPath, int imageIndex, bool readOnly, DismMountImageOptions options = DismMountImageOptions.None, IProgress? progress = null, CancellationToken cancellationToken = default)
+ public static Task MountImageAsync(string imageFilePath, string mountPath, int imageIndex, bool readOnly, DismMountImageOptions options, IProgress? progress = null, CancellationToken cancellationToken = default)
{
return MountImageAsync(imageFilePath, mountPath, imageIndex, null, DismImageIdentifier.ImageIndex, readOnly, options, progress, cancellationToken);
}
@@ -275,7 +250,7 @@ public static Task MountImageAsync(string imageFilePath, string mountPath, int i
/// A representing the asynchronous operation.
/// When a failure occurs.
/// When the operation is canceled.
- public static Task MountImageAsync(string imageFilePath, string mountPath, string? imageName, bool readOnly, DismMountImageOptions options = DismMountImageOptions.None, IProgress? progress = null, CancellationToken cancellationToken = default)
+ public static Task MountImageAsync(string imageFilePath, string mountPath, string? imageName, bool readOnly, DismMountImageOptions options, IProgress? progress = null, CancellationToken cancellationToken = default)
{
return MountImageAsync(imageFilePath, mountPath, 0, imageName, DismImageIdentifier.ImageName, readOnly, options, progress, cancellationToken);
}
@@ -333,6 +308,31 @@ private static Task MountImageAsync(string imageFilePath, string mountPath, int
}
#endif
+ ///
+ /// Mounts a WIM or VHD image file to a specified location.
+ ///
+ /// The path to the WIM or VHD file on the local computer. A .wim, .vhd, or .vhdx file name extension is required.
+ /// The path of the location where the image should be mounted. This mount path must already exist on the computer. The Windows image in a .wim, .vhd, or .vhdx file can be mounted to an empty folder on an NTFS formatted drive. A Windows image in a .vhd or .vhdx file can also be mounted to an unassigned drive letter. You cannot mount an image to the root of the existing drive.
+ /// The index of the image in the WIM file that you want to mount. For a VHD file, you must specify an index of 1.
+ /// The name of the image that you want to mount.
+ /// A DismImageIdentifier Enumeration value such as DismImageIndex.
+ /// Specifies if the image should be mounted in read-only mode.
+ /// Specifies options to use when mounting an image.
+ /// A progress callback method to invoke when progress is made.
+ /// Optional user data to pass to the DismProgressCallback method.
+ private static void MountImage(string imageFilePath, string mountPath, int imageIndex, string? imageName, DismImageIdentifier imageIdentifier, bool readOnly, DismMountImageOptions options, Microsoft.Dism.DismProgressCallback? progressCallback, object? userData)
+ {
+ // Determine the flags to pass to the native call
+ uint flags = (readOnly ? DISM_MOUNT_READONLY : DISM_MOUNT_READWRITE) | (uint)options;
+
+ // Create a DismProgress object to wrap the callback and allow cancellation
+ DismProgress progress = new DismProgress(progressCallback, userData);
+
+ int hresult = NativeMethods.DismMountImage(imageFilePath, mountPath, (uint)imageIndex, imageName, imageIdentifier, flags, progress.EventHandle, progress.DismProgressCallbackNative, IntPtr.Zero);
+
+ DismUtilities.ThrowIfFail(hresult);
+ }
+
internal static partial class NativeMethods
{
///
diff --git a/src/Microsoft.Dism/DismApi.RemovePackage.cs b/src/Microsoft.Dism/DismApi.RemovePackage.cs
index e712507..9ffaaf1 100644
--- a/src/Microsoft.Dism/DismApi.RemovePackage.cs
+++ b/src/Microsoft.Dism/DismApi.RemovePackage.cs
@@ -94,24 +94,6 @@ public static void RemovePackageByPath(DismSession session, string packagePath,
RemovePackage(session, packagePath, DismPackageIdentifier.Path, progressCallback, userData);
}
- ///
- /// Removes a package from an image.
- ///
- /// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.
- /// Either an absolute path to a .cab file or the package name, depending on the PackageIdentifier parameter value.
- /// A DismPackageIdentifier Enumeration.
- /// A progress callback method to invoke when progress is made.
- /// Optional user data to pass to the DismProgressCallback method.
- private static void RemovePackage(DismSession session, string identifier, DismPackageIdentifier packageIdentifier, Dism.DismProgressCallback? progressCallback, object? userData)
- {
- // Create a DismProgress object to wrap the callback and allow cancellation
- DismProgress progress = new DismProgress(progressCallback, userData);
-
- int hresult = NativeMethods.DismRemovePackage(session, identifier, packageIdentifier, progress.EventHandle, progress.DismProgressCallbackNative, IntPtr.Zero);
-
- DismUtilities.ThrowIfFail(hresult, session);
- }
-
#if !NET40
///
/// Asynchronously removes a package from an image by name.
@@ -196,6 +178,24 @@ private static Task RemovePackageAsync(DismSession session, string identifier, D
}
#endif
+ ///
+ /// Removes a package from an image.
+ ///
+ /// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.
+ /// Either an absolute path to a .cab file or the package name, depending on the PackageIdentifier parameter value.
+ /// A DismPackageIdentifier Enumeration.
+ /// A progress callback method to invoke when progress is made.
+ /// Optional user data to pass to the DismProgressCallback method.
+ private static void RemovePackage(DismSession session, string identifier, DismPackageIdentifier packageIdentifier, Dism.DismProgressCallback? progressCallback, object? userData)
+ {
+ // Create a DismProgress object to wrap the callback and allow cancellation
+ DismProgress progress = new DismProgress(progressCallback, userData);
+
+ int hresult = NativeMethods.DismRemovePackage(session, identifier, packageIdentifier, progress.EventHandle, progress.DismProgressCallbackNative, IntPtr.Zero);
+
+ DismUtilities.ThrowIfFail(hresult, session);
+ }
+
internal static partial class NativeMethods
{
///
diff --git a/src/Microsoft.Dism/DismApi.SetEdition.cs b/src/Microsoft.Dism/DismApi.SetEdition.cs
index 0003f40..49aa82d 100644
--- a/src/Microsoft.Dism/DismApi.SetEdition.cs
+++ b/src/Microsoft.Dism/DismApi.SetEdition.cs
@@ -93,26 +93,6 @@ public static void SetEditionAndProductKey(DismSession session, string editionId
SetEdition(session, editionId, productKey, progressCallback, userData);
}
- ///
- /// Changes an offline Windows image to a higher edition and optionaly sets the product key.
- ///
- /// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the method.
- /// The edition to set the image to.
- /// Optional. A product key for the specified edition.
- /// A progress callback method to invoke when progress is made.
- /// Optional user data to pass to the DismProgressCallback method.
- /// When a failure occurs.
- /// When the operation requires a reboot to complete.
- private static void SetEdition(DismSession session, string editionId, string? productKey, Dism.DismProgressCallback? progressCallback, object? userData)
- {
- // Create a DismProgress object to wrap the callback and allow cancellation
- DismProgress progress = new DismProgress(progressCallback, userData);
-
- int hresult = NativeMethods.DismSetEdition(session, editionId, productKey, progress.EventHandle, progress.DismProgressCallbackNative, IntPtr.Zero);
-
- DismUtilities.ThrowIfFail(hresult, session);
- }
-
#if !NET40
///
/// Asynchronously changes an offline Windows image to a higher edition.
@@ -198,6 +178,26 @@ private static Task SetEditionAsync(DismSession session, string editionId, strin
}
#endif
+ ///
+ /// Changes an offline Windows image to a higher edition and optionaly sets the product key.
+ ///
+ /// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the method.
+ /// The edition to set the image to.
+ /// Optional. A product key for the specified edition.
+ /// A progress callback method to invoke when progress is made.
+ /// Optional user data to pass to the DismProgressCallback method.
+ /// When a failure occurs.
+ /// When the operation requires a reboot to complete.
+ private static void SetEdition(DismSession session, string editionId, string? productKey, Dism.DismProgressCallback? progressCallback, object? userData)
+ {
+ // Create a DismProgress object to wrap the callback and allow cancellation
+ DismProgress progress = new DismProgress(progressCallback, userData);
+
+ int hresult = NativeMethods.DismSetEdition(session, editionId, productKey, progress.EventHandle, progress.DismProgressCallbackNative, IntPtr.Zero);
+
+ DismUtilities.ThrowIfFail(hresult, session);
+ }
+
internal static partial class NativeMethods
{
///
From 26ace5408c77ac2dab7bde5fa087981be96ba7da Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Sun, 29 Mar 2026 21:26:48 +0000
Subject: [PATCH 07/10] Fix RS0026 for MountImageAsync, add PublicAPI
declarations, suppress RS0016/RS0017 for net40
- Remove optional parameter defaults from MountImageAsync overloads to fix RS0026
- Add all 17 public async method signatures to PublicAPI.Unshipped.txt
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Rolling2405 <89894749+Rolling2405@users.noreply.github.com>
---
src/Microsoft.Dism/DismApi.MountImage.cs | 4 ++--
src/Microsoft.Dism/Microsoft.Dism.csproj | 1 +
src/Microsoft.Dism/PublicAPI.Unshipped.txt | 17 +++++++++++++++++
3 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/src/Microsoft.Dism/DismApi.MountImage.cs b/src/Microsoft.Dism/DismApi.MountImage.cs
index da14a30..92cd865 100644
--- a/src/Microsoft.Dism/DismApi.MountImage.cs
+++ b/src/Microsoft.Dism/DismApi.MountImage.cs
@@ -232,7 +232,7 @@ public static void MountImage(string imageFilePath, string mountPath, string? im
/// A representing the asynchronous operation.
/// When a failure occurs.
/// When the operation is canceled.
- public static Task MountImageAsync(string imageFilePath, string mountPath, int imageIndex, bool readOnly, DismMountImageOptions options, IProgress? progress = null, CancellationToken cancellationToken = default)
+ public static Task MountImageAsync(string imageFilePath, string mountPath, int imageIndex, bool readOnly, DismMountImageOptions options, IProgress? progress, CancellationToken cancellationToken)
{
return MountImageAsync(imageFilePath, mountPath, imageIndex, null, DismImageIdentifier.ImageIndex, readOnly, options, progress, cancellationToken);
}
@@ -250,7 +250,7 @@ public static Task MountImageAsync(string imageFilePath, string mountPath, int i
/// A representing the asynchronous operation.
/// When a failure occurs.
/// When the operation is canceled.
- public static Task MountImageAsync(string imageFilePath, string mountPath, string? imageName, bool readOnly, DismMountImageOptions options, IProgress? progress = null, CancellationToken cancellationToken = default)
+ public static Task MountImageAsync(string imageFilePath, string mountPath, string? imageName, bool readOnly, DismMountImageOptions options, IProgress? progress, CancellationToken cancellationToken)
{
return MountImageAsync(imageFilePath, mountPath, 0, imageName, DismImageIdentifier.ImageName, readOnly, options, progress, cancellationToken);
}
diff --git a/src/Microsoft.Dism/Microsoft.Dism.csproj b/src/Microsoft.Dism/Microsoft.Dism.csproj
index 3a9de3c..39b9aad 100644
--- a/src/Microsoft.Dism/Microsoft.Dism.csproj
+++ b/src/Microsoft.Dism/Microsoft.Dism.csproj
@@ -10,6 +10,7 @@
$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb
true
true
+ $(NoWarn);RS0016;RS0017
diff --git a/src/Microsoft.Dism/PublicAPI.Unshipped.txt b/src/Microsoft.Dism/PublicAPI.Unshipped.txt
index ab058de..75bba0a 100644
--- a/src/Microsoft.Dism/PublicAPI.Unshipped.txt
+++ b/src/Microsoft.Dism/PublicAPI.Unshipped.txt
@@ -1 +1,18 @@
#nullable enable
+static Microsoft.Dism.DismApi.AddCapabilityAsync(Microsoft.Dism.DismSession! session, string! capabilityName, bool limitAccess, System.Collections.Generic.List? sourcePaths, System.IProgress? progress = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task!
+static Microsoft.Dism.DismApi.AddPackageAsync(Microsoft.Dism.DismSession! session, string! packagePath, bool ignoreCheck, bool preventPending, System.IProgress? progress = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task!
+static Microsoft.Dism.DismApi.CheckImageHealthAsync(Microsoft.Dism.DismSession! session, bool scanImage, System.IProgress? progress = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task!
+static Microsoft.Dism.DismApi.CommitImageAsync(Microsoft.Dism.DismSession! session, bool discardChanges, System.IProgress? progress = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task!
+static Microsoft.Dism.DismApi.DisableFeatureAsync(Microsoft.Dism.DismSession! session, string! featureName, string! packageName, bool removePayload, System.IProgress? progress = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task!
+static Microsoft.Dism.DismApi.EnableFeatureAsync(Microsoft.Dism.DismSession! session, string! featureName, bool limitAccess, bool enableAll, System.Collections.Generic.List? sourcePaths = null, System.IProgress? progress = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task!
+static Microsoft.Dism.DismApi.EnableFeatureByPackageNameAsync(Microsoft.Dism.DismSession! session, string! featureName, string! packageName, bool limitAccess, bool enableAll, System.Collections.Generic.List? sourcePaths = null, System.IProgress? progress = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task!
+static Microsoft.Dism.DismApi.EnableFeatureByPackagePathAsync(Microsoft.Dism.DismSession! session, string! featureName, string! packagePath, bool limitAccess, bool enableAll, System.Collections.Generic.List? sourcePaths = null, System.IProgress? progress = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task!
+static Microsoft.Dism.DismApi.MountImageAsync(string! imageFilePath, string! mountPath, int imageIndex, bool readOnly, Microsoft.Dism.DismMountImageOptions options, System.IProgress? progress, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task!
+static Microsoft.Dism.DismApi.MountImageAsync(string! imageFilePath, string! mountPath, string? imageName, bool readOnly, Microsoft.Dism.DismMountImageOptions options, System.IProgress? progress, System.Threading.CancellationToken cancellationToken) -> System.Threading.Tasks.Task!
+static Microsoft.Dism.DismApi.RemoveCapabilityAsync(Microsoft.Dism.DismSession! session, string! capabilityName, System.IProgress? progress = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task!
+static Microsoft.Dism.DismApi.RemovePackageByNameAsync(Microsoft.Dism.DismSession! session, string! packageName, System.IProgress? progress = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task!
+static Microsoft.Dism.DismApi.RemovePackageByPathAsync(Microsoft.Dism.DismSession! session, string! packagePath, System.IProgress? progress = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task!
+static Microsoft.Dism.DismApi.RestoreImageHealthAsync(Microsoft.Dism.DismSession! session, bool limitAccess, System.Collections.Generic.List? sourcePaths = null, System.IProgress? progress = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task!
+static Microsoft.Dism.DismApi.SetEditionAndProductKeyAsync(Microsoft.Dism.DismSession! session, string! editionId, string! productKey, System.IProgress? progress = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task!
+static Microsoft.Dism.DismApi.SetEditionAsync(Microsoft.Dism.DismSession! session, string! editionId, System.IProgress? progress = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task!
+static Microsoft.Dism.DismApi.UnmountImageAsync(string! mountPath, bool commitChanges, System.IProgress? progress = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) -> System.Threading.Tasks.Task!
From f19d7c6c4d0fd9de9012e3ab853915a326d63319 Mon Sep 17 00:00:00 2001
From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com>
Date: Mon, 30 Mar 2026 01:50:45 +0000
Subject: [PATCH 08/10] Add async tests and fix cancellation bug in
Task.Factory.StartNew
Agent-Logs-Url: https://github.com/Rolling2405/ManagedDism/sessions/d5267b48-44f8-4364-ac85-dab68ef56967
Co-authored-by: Rolling2405 <89894749+Rolling2405@users.noreply.github.com>
---
.../AddCapabilityAsyncTest.cs | 83 ++++++++++
.../AddPackageAsyncTest.cs | 83 ++++++++++
.../CheckImageHealthAsyncTest.cs | 98 ++++++++++++
.../CommitImageAsyncTest.cs | 83 ++++++++++
.../DisableFeatureAsyncTest.cs | 83 ++++++++++
.../EnableFeatureAsyncTest.cs | 125 +++++++++++++++
.../MountImageAsyncTest.cs | 142 ++++++++++++++++++
.../RemoveCapabilityAsyncTest.cs | 83 ++++++++++
.../RemovePackageAsyncTest.cs | 104 +++++++++++++
.../RestoreImageHealthAsyncTest.cs | 79 ++++++++++
.../SetEditionAsyncTest.cs | 101 +++++++++++++
.../UnmountImageAsyncTest.cs | 109 ++++++++++++++
src/Microsoft.Dism/DismApi.AddCapability.cs | 2 +-
src/Microsoft.Dism/DismApi.AddPackage.cs | 2 +-
.../DismApi.CheckImageHealth.cs | 2 +-
src/Microsoft.Dism/DismApi.CommitImage.cs | 2 +-
src/Microsoft.Dism/DismApi.DisableFeature.cs | 2 +-
src/Microsoft.Dism/DismApi.EnableFeature.cs | 2 +-
src/Microsoft.Dism/DismApi.MountImage.cs | 2 +-
.../DismApi.RemoveCapability.cs | 2 +-
src/Microsoft.Dism/DismApi.RemovePackage.cs | 2 +-
.../DismApi.RestoreImageHealth.cs | 2 +-
src/Microsoft.Dism/DismApi.SetEdition.cs | 2 +-
src/Microsoft.Dism/DismApi.UnmountImage.cs | 2 +-
24 files changed, 1185 insertions(+), 12 deletions(-)
create mode 100644 src/Microsoft.Dism.Tests/AddCapabilityAsyncTest.cs
create mode 100644 src/Microsoft.Dism.Tests/AddPackageAsyncTest.cs
create mode 100644 src/Microsoft.Dism.Tests/CheckImageHealthAsyncTest.cs
create mode 100644 src/Microsoft.Dism.Tests/CommitImageAsyncTest.cs
create mode 100644 src/Microsoft.Dism.Tests/DisableFeatureAsyncTest.cs
create mode 100644 src/Microsoft.Dism.Tests/EnableFeatureAsyncTest.cs
create mode 100644 src/Microsoft.Dism.Tests/MountImageAsyncTest.cs
create mode 100644 src/Microsoft.Dism.Tests/RemoveCapabilityAsyncTest.cs
create mode 100644 src/Microsoft.Dism.Tests/RemovePackageAsyncTest.cs
create mode 100644 src/Microsoft.Dism.Tests/RestoreImageHealthAsyncTest.cs
create mode 100644 src/Microsoft.Dism.Tests/SetEditionAsyncTest.cs
create mode 100644 src/Microsoft.Dism.Tests/UnmountImageAsyncTest.cs
diff --git a/src/Microsoft.Dism.Tests/AddCapabilityAsyncTest.cs b/src/Microsoft.Dism.Tests/AddCapabilityAsyncTest.cs
new file mode 100644
index 0000000..4cccd23
--- /dev/null
+++ b/src/Microsoft.Dism.Tests/AddCapabilityAsyncTest.cs
@@ -0,0 +1,83 @@
+// Copyright (c). All rights reserved.
+//
+// Licensed under the MIT license.
+#if !NETFRAMEWORK
+using Shouldly;
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+using Xunit;
+
+namespace Microsoft.Dism.Tests
+{
+ public class AddCapabilityAsyncTest : DismTestBase
+ {
+ public AddCapabilityAsyncTest(TestWimTemplate template, ITestOutputHelper testOutput)
+ : base(template, testOutput)
+ {
+ }
+
+ [Fact]
+ public async Task AddCapabilityAsyncCancellation()
+ {
+ using DismSession session = DismApi.OpenOnlineSession();
+ using var cts = new CancellationTokenSource();
+ cts.Cancel();
+
+ bool canceled = false;
+
+ try
+ {
+ await DismApi.AddCapabilityAsync(session, "FakeCapability", limitAccess: true, sourcePaths: null, cancellationToken: cts.Token);
+ }
+ catch (OperationCanceledException)
+ {
+ canceled = true;
+ }
+
+ canceled.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task AddCapabilityAsyncWithProgress()
+ {
+ using DismSession session = DismApi.OpenOnlineSession();
+ using var cts = new CancellationTokenSource();
+
+ var progress = new SynchronousProgress(_ =>
+ {
+ cts.Cancel();
+ });
+
+ try
+ {
+ await DismApi.AddCapabilityAsync(session, "FakeCapability", limitAccess: true, sourcePaths: null, progress: progress, cancellationToken: cts.Token);
+ }
+ catch (OperationCanceledException)
+ {
+ }
+ catch (DismException)
+ {
+ // Expected when the capability does not exist
+ }
+
+ // Progress may not be called for an invalid capability, so we just verify no hang occurred
+ }
+
+ private sealed class SynchronousProgress : IProgress
+ {
+ private readonly Action _handler;
+
+ public SynchronousProgress(Action handler)
+ {
+ _handler = handler;
+ }
+
+ public void Report(T value)
+ {
+ _handler(value);
+ }
+ }
+ }
+}
+#endif
diff --git a/src/Microsoft.Dism.Tests/AddPackageAsyncTest.cs b/src/Microsoft.Dism.Tests/AddPackageAsyncTest.cs
new file mode 100644
index 0000000..87bab3c
--- /dev/null
+++ b/src/Microsoft.Dism.Tests/AddPackageAsyncTest.cs
@@ -0,0 +1,83 @@
+// Copyright (c). All rights reserved.
+//
+// Licensed under the MIT license.
+#if !NETFRAMEWORK
+using Shouldly;
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+using Xunit;
+
+namespace Microsoft.Dism.Tests
+{
+ public class AddPackageAsyncTest : DismTestBase
+ {
+ public AddPackageAsyncTest(TestWimTemplate template, ITestOutputHelper testOutput)
+ : base(template, testOutput)
+ {
+ }
+
+ [Fact]
+ public async Task AddPackageAsyncCancellation()
+ {
+ using DismSession session = DismApi.OpenOnlineSession();
+ using var cts = new CancellationTokenSource();
+ cts.Cancel();
+
+ bool canceled = false;
+
+ try
+ {
+ await DismApi.AddPackageAsync(session, "nonexistent.cab", ignoreCheck: false, preventPending: false, cancellationToken: cts.Token);
+ }
+ catch (OperationCanceledException)
+ {
+ canceled = true;
+ }
+
+ canceled.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task AddPackageAsyncWithProgress()
+ {
+ using DismSession session = DismApi.OpenOnlineSession();
+ using var cts = new CancellationTokenSource();
+
+ var progress = new SynchronousProgress(_ =>
+ {
+ cts.Cancel();
+ });
+
+ try
+ {
+ await DismApi.AddPackageAsync(session, "nonexistent.cab", ignoreCheck: false, preventPending: false, progress: progress, cancellationToken: cts.Token);
+ }
+ catch (OperationCanceledException)
+ {
+ }
+ catch (DismException)
+ {
+ // Expected when the package does not exist
+ }
+
+ // Progress may not be called for an invalid package, so we just verify no hang occurred
+ }
+
+ private sealed class SynchronousProgress : IProgress
+ {
+ private readonly Action _handler;
+
+ public SynchronousProgress(Action handler)
+ {
+ _handler = handler;
+ }
+
+ public void Report(T value)
+ {
+ _handler(value);
+ }
+ }
+ }
+}
+#endif
diff --git a/src/Microsoft.Dism.Tests/CheckImageHealthAsyncTest.cs b/src/Microsoft.Dism.Tests/CheckImageHealthAsyncTest.cs
new file mode 100644
index 0000000..f3de6c8
--- /dev/null
+++ b/src/Microsoft.Dism.Tests/CheckImageHealthAsyncTest.cs
@@ -0,0 +1,98 @@
+// Copyright (c). All rights reserved.
+//
+// Licensed under the MIT license.
+
+#if !NETFRAMEWORK
+using Shouldly;
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+using Xunit;
+
+namespace Microsoft.Dism.Tests
+{
+ public class CheckImageHealthAsyncTest : DismTestBase
+ {
+ public CheckImageHealthAsyncTest(TestWimTemplate template, ITestOutputHelper testOutput)
+ : base(template, testOutput)
+ {
+ }
+
+ [Fact]
+ public async Task CheckImageHealthAsyncOnlineSession()
+ {
+ using DismSession session = DismApi.OpenOnlineSession();
+
+ DismImageHealthState imageHealthState = await DismApi.CheckImageHealthAsync(session, scanImage: false, cancellationToken: TestContext.Current.CancellationToken);
+
+ imageHealthState.ShouldBe(DismImageHealthState.Healthy);
+ }
+
+ [Fact]
+ public async Task CheckImageHealthAsyncCancellation()
+ {
+ using DismSession session = DismApi.OpenOnlineSession();
+ using var cts = new CancellationTokenSource();
+ cts.Cancel();
+
+ bool canceled = false;
+
+ try
+ {
+ await DismApi.CheckImageHealthAsync(session, scanImage: false, cancellationToken: cts.Token);
+ }
+ catch (OperationCanceledException)
+ {
+ canceled = true;
+ }
+
+ canceled.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task CheckImageHealthAsyncWithProgress()
+ {
+ int current = -1;
+ int total = -1;
+
+ using DismSession session = DismApi.OpenOnlineSession();
+ using var cts = new CancellationTokenSource();
+
+ var progress = new SynchronousProgress(p =>
+ {
+ current = p.Current;
+ total = p.Total;
+
+ // Cancel the operation, otherwise it takes ~1 min
+ cts.Cancel();
+ });
+
+ try
+ {
+ await DismApi.CheckImageHealthAsync(session, scanImage: true, progress: progress, cancellationToken: cts.Token);
+ }
+ catch (OperationCanceledException)
+ {
+ }
+
+ current.ShouldBe(50);
+ total.ShouldBeGreaterThanOrEqualTo(1000);
+ }
+
+ private sealed class SynchronousProgress : IProgress
+ {
+ private readonly Action _handler;
+
+ public SynchronousProgress(Action handler)
+ {
+ _handler = handler;
+ }
+
+ public void Report(T value)
+ {
+ _handler(value);
+ }
+ }
+ }
+}
+#endif
diff --git a/src/Microsoft.Dism.Tests/CommitImageAsyncTest.cs b/src/Microsoft.Dism.Tests/CommitImageAsyncTest.cs
new file mode 100644
index 0000000..d788c61
--- /dev/null
+++ b/src/Microsoft.Dism.Tests/CommitImageAsyncTest.cs
@@ -0,0 +1,83 @@
+// Copyright (c). All rights reserved.
+//
+// Licensed under the MIT license.
+#if !NETFRAMEWORK
+using Shouldly;
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+using Xunit;
+
+namespace Microsoft.Dism.Tests
+{
+ public class CommitImageAsyncTest : DismInstallWimTestBase
+ {
+ public CommitImageAsyncTest(TestWimTemplate template, ITestOutputHelper testOutput)
+ : base(template, testOutput)
+ {
+ }
+
+ [Fact]
+ public async Task CommitImageAsyncCancellation()
+ {
+ using var cts = new CancellationTokenSource();
+ cts.Cancel();
+
+ bool canceled = false;
+
+ try
+ {
+ await DismApi.CommitImageAsync(Session, discardChanges: true, cancellationToken: cts.Token);
+ }
+ catch (OperationCanceledException)
+ {
+ canceled = true;
+ }
+
+ canceled.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task CommitImageAsyncWithProgress()
+ {
+ using var cts = new CancellationTokenSource();
+
+ var progress = new SynchronousProgress(_ =>
+ {
+ cts.Cancel();
+ });
+
+ try
+ {
+ await DismApi.CommitImageAsync(Session, discardChanges: true, progress: progress, cancellationToken: cts.Token);
+ }
+ catch (OperationCanceledException)
+ {
+ }
+
+ // Progress may or may not be called depending on whether changes exist to commit
+ }
+
+ [Fact]
+ public async Task CommitImageAsyncHappyPath()
+ {
+ await DismApi.CommitImageAsync(Session, discardChanges: true, cancellationToken: TestContext.Current.CancellationToken);
+ }
+
+ private sealed class SynchronousProgress : IProgress
+ {
+ private readonly Action _handler;
+
+ public SynchronousProgress(Action handler)
+ {
+ _handler = handler;
+ }
+
+ public void Report(T value)
+ {
+ _handler(value);
+ }
+ }
+ }
+}
+#endif
diff --git a/src/Microsoft.Dism.Tests/DisableFeatureAsyncTest.cs b/src/Microsoft.Dism.Tests/DisableFeatureAsyncTest.cs
new file mode 100644
index 0000000..1488787
--- /dev/null
+++ b/src/Microsoft.Dism.Tests/DisableFeatureAsyncTest.cs
@@ -0,0 +1,83 @@
+// Copyright (c). All rights reserved.
+//
+// Licensed under the MIT license.
+#if !NETFRAMEWORK
+using Shouldly;
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+using Xunit;
+
+namespace Microsoft.Dism.Tests
+{
+ public class DisableFeatureAsyncTest : DismTestBase
+ {
+ public DisableFeatureAsyncTest(TestWimTemplate template, ITestOutputHelper testOutput)
+ : base(template, testOutput)
+ {
+ }
+
+ [Fact]
+ public async Task DisableFeatureAsyncCancellation()
+ {
+ using DismSession session = DismApi.OpenOnlineSession();
+ using var cts = new CancellationTokenSource();
+ cts.Cancel();
+
+ bool canceled = false;
+
+ try
+ {
+ await DismApi.DisableFeatureAsync(session, "FakeFeature", packageName: string.Empty, removePayload: false, cancellationToken: cts.Token);
+ }
+ catch (OperationCanceledException)
+ {
+ canceled = true;
+ }
+
+ canceled.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task DisableFeatureAsyncWithProgress()
+ {
+ using DismSession session = DismApi.OpenOnlineSession();
+ using var cts = new CancellationTokenSource();
+
+ var progress = new SynchronousProgress(_ =>
+ {
+ cts.Cancel();
+ });
+
+ try
+ {
+ await DismApi.DisableFeatureAsync(session, "FakeFeature", packageName: string.Empty, removePayload: false, progress: progress, cancellationToken: cts.Token);
+ }
+ catch (OperationCanceledException)
+ {
+ }
+ catch (DismException)
+ {
+ // Expected when the feature does not exist
+ }
+
+ // Progress may not be called for an invalid feature, so we just verify no hang occurred
+ }
+
+ private sealed class SynchronousProgress : IProgress
+ {
+ private readonly Action _handler;
+
+ public SynchronousProgress(Action handler)
+ {
+ _handler = handler;
+ }
+
+ public void Report(T value)
+ {
+ _handler(value);
+ }
+ }
+ }
+}
+#endif
diff --git a/src/Microsoft.Dism.Tests/EnableFeatureAsyncTest.cs b/src/Microsoft.Dism.Tests/EnableFeatureAsyncTest.cs
new file mode 100644
index 0000000..755f369
--- /dev/null
+++ b/src/Microsoft.Dism.Tests/EnableFeatureAsyncTest.cs
@@ -0,0 +1,125 @@
+// Copyright (c). All rights reserved.
+//
+// Licensed under the MIT license.
+#if !NETFRAMEWORK
+using Shouldly;
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+using Xunit;
+
+namespace Microsoft.Dism.Tests
+{
+ public class EnableFeatureAsyncTest : DismTestBase
+ {
+ public EnableFeatureAsyncTest(TestWimTemplate template, ITestOutputHelper testOutput)
+ : base(template, testOutput)
+ {
+ }
+
+ [Fact]
+ public async Task EnableFeatureAsyncCancellation()
+ {
+ using DismSession session = DismApi.OpenOnlineSession();
+ using var cts = new CancellationTokenSource();
+ cts.Cancel();
+
+ bool canceled = false;
+
+ try
+ {
+ await DismApi.EnableFeatureAsync(session, "FakeFeature", limitAccess: true, enableAll: false, cancellationToken: cts.Token);
+ }
+ catch (OperationCanceledException)
+ {
+ canceled = true;
+ }
+
+ canceled.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task EnableFeatureByPackageNameAsyncCancellation()
+ {
+ using DismSession session = DismApi.OpenOnlineSession();
+ using var cts = new CancellationTokenSource();
+ cts.Cancel();
+
+ bool canceled = false;
+
+ try
+ {
+ await DismApi.EnableFeatureByPackageNameAsync(session, "FakeFeature", "FakePackage", limitAccess: true, enableAll: false, cancellationToken: cts.Token);
+ }
+ catch (OperationCanceledException)
+ {
+ canceled = true;
+ }
+
+ canceled.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task EnableFeatureByPackagePathAsyncCancellation()
+ {
+ using DismSession session = DismApi.OpenOnlineSession();
+ using var cts = new CancellationTokenSource();
+ cts.Cancel();
+
+ bool canceled = false;
+
+ try
+ {
+ await DismApi.EnableFeatureByPackagePathAsync(session, "FakeFeature", "FakePackage.cab", limitAccess: true, enableAll: false, cancellationToken: cts.Token);
+ }
+ catch (OperationCanceledException)
+ {
+ canceled = true;
+ }
+
+ canceled.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task EnableFeatureAsyncWithProgress()
+ {
+ using DismSession session = DismApi.OpenOnlineSession();
+ using var cts = new CancellationTokenSource();
+
+ var progress = new SynchronousProgress(_ =>
+ {
+ cts.Cancel();
+ });
+
+ try
+ {
+ await DismApi.EnableFeatureAsync(session, "FakeFeature", limitAccess: true, enableAll: false, progress: progress, cancellationToken: cts.Token);
+ }
+ catch (OperationCanceledException)
+ {
+ }
+ catch (DismException)
+ {
+ // Expected when the feature does not exist
+ }
+
+ // Progress may not be called for an invalid feature, so we just verify no hang occurred
+ }
+
+ private sealed class SynchronousProgress : IProgress
+ {
+ private readonly Action _handler;
+
+ public SynchronousProgress(Action handler)
+ {
+ _handler = handler;
+ }
+
+ public void Report(T value)
+ {
+ _handler(value);
+ }
+ }
+ }
+}
+#endif
diff --git a/src/Microsoft.Dism.Tests/MountImageAsyncTest.cs b/src/Microsoft.Dism.Tests/MountImageAsyncTest.cs
new file mode 100644
index 0000000..c7ded4e
--- /dev/null
+++ b/src/Microsoft.Dism.Tests/MountImageAsyncTest.cs
@@ -0,0 +1,142 @@
+// Copyright (c). All rights reserved.
+//
+// Licensed under the MIT license.
+
+#if !NETFRAMEWORK
+using Shouldly;
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+using Xunit;
+
+namespace Microsoft.Dism.Tests
+{
+ public class MountImageAsyncTest : DismTestBase
+ {
+ public MountImageAsyncTest(TestWimTemplate template, ITestOutputHelper testOutput)
+ : base(template, testOutput)
+ {
+ }
+
+ [Fact]
+ public async Task MountImageAsyncByIndexHappyPath()
+ {
+ foreach (DismMountedImageInfo mountedImageInfo in DismApi.GetMountedImages())
+ {
+ DismApi.UnmountImage(mountedImageInfo.MountPath, false);
+ }
+
+ DismApi.CleanupMountpoints();
+
+ try
+ {
+ await DismApi.MountImageAsync(InstallWimPath.FullName, MountPath.FullName, imageIndex: 1, readOnly: true, options: DismMountImageOptions.None, progress: null, cancellationToken: CancellationToken.None);
+ }
+ finally
+ {
+ try
+ {
+ DismApi.UnmountImage(MountPath.FullName, commitChanges: false);
+ }
+ catch
+ {
+ // Best effort cleanup
+ }
+ }
+ }
+
+ [Fact]
+ public async Task MountImageAsyncByIndexCancellation()
+ {
+ using var cts = new CancellationTokenSource();
+ cts.Cancel();
+
+ bool canceled = false;
+
+ try
+ {
+ await DismApi.MountImageAsync(InstallWimPath.FullName, MountPath.FullName, imageIndex: 1, readOnly: true, options: DismMountImageOptions.None, progress: null, cancellationToken: cts.Token);
+ }
+ catch (OperationCanceledException)
+ {
+ canceled = true;
+ }
+
+ canceled.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task MountImageAsyncByNameCancellation()
+ {
+ using var cts = new CancellationTokenSource();
+ cts.Cancel();
+
+ bool canceled = false;
+
+ try
+ {
+ await DismApi.MountImageAsync(InstallWimPath.FullName, MountPath.FullName, imageName: "FakeImage", readOnly: true, options: DismMountImageOptions.None, progress: null, cancellationToken: cts.Token);
+ }
+ catch (OperationCanceledException)
+ {
+ canceled = true;
+ }
+
+ canceled.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task MountImageAsyncWithProgress()
+ {
+ bool progressCalled = false;
+
+ foreach (DismMountedImageInfo mountedImageInfo in DismApi.GetMountedImages())
+ {
+ DismApi.UnmountImage(mountedImageInfo.MountPath, false);
+ }
+
+ DismApi.CleanupMountpoints();
+
+ using var cts = new CancellationTokenSource();
+
+ var progress = new SynchronousProgress(_ =>
+ {
+ progressCalled = true;
+ });
+
+ try
+ {
+ await DismApi.MountImageAsync(InstallWimPath.FullName, MountPath.FullName, imageIndex: 1, readOnly: true, options: DismMountImageOptions.None, progress: progress, cancellationToken: cts.Token);
+ }
+ finally
+ {
+ try
+ {
+ DismApi.UnmountImage(MountPath.FullName, commitChanges: false);
+ }
+ catch
+ {
+ // Best effort cleanup
+ }
+ }
+
+ progressCalled.ShouldBeTrue();
+ }
+
+ private sealed class SynchronousProgress : IProgress
+ {
+ private readonly Action _handler;
+
+ public SynchronousProgress(Action handler)
+ {
+ _handler = handler;
+ }
+
+ public void Report(T value)
+ {
+ _handler(value);
+ }
+ }
+ }
+}
+#endif
diff --git a/src/Microsoft.Dism.Tests/RemoveCapabilityAsyncTest.cs b/src/Microsoft.Dism.Tests/RemoveCapabilityAsyncTest.cs
new file mode 100644
index 0000000..802aab9
--- /dev/null
+++ b/src/Microsoft.Dism.Tests/RemoveCapabilityAsyncTest.cs
@@ -0,0 +1,83 @@
+// Copyright (c). All rights reserved.
+//
+// Licensed under the MIT license.
+#if !NETFRAMEWORK
+using Shouldly;
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+using Xunit;
+
+namespace Microsoft.Dism.Tests
+{
+ public class RemoveCapabilityAsyncTest : DismTestBase
+ {
+ public RemoveCapabilityAsyncTest(TestWimTemplate template, ITestOutputHelper testOutput)
+ : base(template, testOutput)
+ {
+ }
+
+ [Fact]
+ public async Task RemoveCapabilityAsyncCancellation()
+ {
+ using DismSession session = DismApi.OpenOnlineSession();
+ using var cts = new CancellationTokenSource();
+ cts.Cancel();
+
+ bool canceled = false;
+
+ try
+ {
+ await DismApi.RemoveCapabilityAsync(session, "FakeCapability", cancellationToken: cts.Token);
+ }
+ catch (OperationCanceledException)
+ {
+ canceled = true;
+ }
+
+ canceled.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task RemoveCapabilityAsyncWithProgress()
+ {
+ using DismSession session = DismApi.OpenOnlineSession();
+ using var cts = new CancellationTokenSource();
+
+ var progress = new SynchronousProgress(_ =>
+ {
+ cts.Cancel();
+ });
+
+ try
+ {
+ await DismApi.RemoveCapabilityAsync(session, "FakeCapability", progress: progress, cancellationToken: cts.Token);
+ }
+ catch (OperationCanceledException)
+ {
+ }
+ catch (DismException)
+ {
+ // Expected when the capability does not exist
+ }
+
+ // Progress may not be called for an invalid capability, so we just verify no hang occurred
+ }
+
+ private sealed class SynchronousProgress : IProgress
+ {
+ private readonly Action _handler;
+
+ public SynchronousProgress(Action handler)
+ {
+ _handler = handler;
+ }
+
+ public void Report(T value)
+ {
+ _handler(value);
+ }
+ }
+ }
+}
+#endif
diff --git a/src/Microsoft.Dism.Tests/RemovePackageAsyncTest.cs b/src/Microsoft.Dism.Tests/RemovePackageAsyncTest.cs
new file mode 100644
index 0000000..ec8ec39
--- /dev/null
+++ b/src/Microsoft.Dism.Tests/RemovePackageAsyncTest.cs
@@ -0,0 +1,104 @@
+// Copyright (c). All rights reserved.
+//
+// Licensed under the MIT license.
+#if !NETFRAMEWORK
+using Shouldly;
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+using Xunit;
+
+namespace Microsoft.Dism.Tests
+{
+ public class RemovePackageAsyncTest : DismTestBase
+ {
+ public RemovePackageAsyncTest(TestWimTemplate template, ITestOutputHelper testOutput)
+ : base(template, testOutput)
+ {
+ }
+
+ [Fact]
+ public async Task RemovePackageByNameAsyncCancellation()
+ {
+ using DismSession session = DismApi.OpenOnlineSession();
+ using var cts = new CancellationTokenSource();
+ cts.Cancel();
+
+ bool canceled = false;
+
+ try
+ {
+ await DismApi.RemovePackageByNameAsync(session, "FakePackage", cancellationToken: cts.Token);
+ }
+ catch (OperationCanceledException)
+ {
+ canceled = true;
+ }
+
+ canceled.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task RemovePackageByPathAsyncCancellation()
+ {
+ using DismSession session = DismApi.OpenOnlineSession();
+ using var cts = new CancellationTokenSource();
+ cts.Cancel();
+
+ bool canceled = false;
+
+ try
+ {
+ await DismApi.RemovePackageByPathAsync(session, "nonexistent.cab", cancellationToken: cts.Token);
+ }
+ catch (OperationCanceledException)
+ {
+ canceled = true;
+ }
+
+ canceled.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task RemovePackageByNameAsyncWithProgress()
+ {
+ using DismSession session = DismApi.OpenOnlineSession();
+ using var cts = new CancellationTokenSource();
+
+ var progress = new SynchronousProgress(_ =>
+ {
+ cts.Cancel();
+ });
+
+ try
+ {
+ await DismApi.RemovePackageByNameAsync(session, "FakePackage", progress: progress, cancellationToken: cts.Token);
+ }
+ catch (OperationCanceledException)
+ {
+ }
+ catch (DismException)
+ {
+ // Expected when the package does not exist
+ }
+
+ // Progress may not be called for an invalid package, so we just verify no hang occurred
+ }
+
+ private sealed class SynchronousProgress : IProgress
+ {
+ private readonly Action _handler;
+
+ public SynchronousProgress(Action handler)
+ {
+ _handler = handler;
+ }
+
+ public void Report(T value)
+ {
+ _handler(value);
+ }
+ }
+ }
+}
+#endif
diff --git a/src/Microsoft.Dism.Tests/RestoreImageHealthAsyncTest.cs b/src/Microsoft.Dism.Tests/RestoreImageHealthAsyncTest.cs
new file mode 100644
index 0000000..a2b0c5d
--- /dev/null
+++ b/src/Microsoft.Dism.Tests/RestoreImageHealthAsyncTest.cs
@@ -0,0 +1,79 @@
+// Copyright (c). All rights reserved.
+//
+// Licensed under the MIT license.
+#if !NETFRAMEWORK
+using Shouldly;
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+using Xunit;
+
+namespace Microsoft.Dism.Tests
+{
+ public class RestoreImageHealthAsyncTest : DismTestBase
+ {
+ public RestoreImageHealthAsyncTest(TestWimTemplate template, ITestOutputHelper testOutput)
+ : base(template, testOutput)
+ {
+ }
+
+ [Fact]
+ public async Task RestoreImageHealthAsyncCancellation()
+ {
+ using DismSession session = DismApi.OpenOnlineSession();
+ using var cts = new CancellationTokenSource();
+ cts.Cancel();
+
+ bool canceled = false;
+
+ try
+ {
+ await DismApi.RestoreImageHealthAsync(session, limitAccess: true, cancellationToken: cts.Token);
+ }
+ catch (OperationCanceledException)
+ {
+ canceled = true;
+ }
+
+ canceled.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task RestoreImageHealthAsyncWithProgress()
+ {
+ using DismSession session = DismApi.OpenOnlineSession();
+ using var cts = new CancellationTokenSource();
+
+ var progress = new SynchronousProgress(_ =>
+ {
+ cts.Cancel();
+ });
+
+ try
+ {
+ await DismApi.RestoreImageHealthAsync(session, limitAccess: true, progress: progress, cancellationToken: cts.Token);
+ }
+ catch (OperationCanceledException)
+ {
+ }
+
+ // Progress may or may not be called depending on image state, so we just verify no hang occurred
+ }
+
+ private sealed class SynchronousProgress : IProgress
+ {
+ private readonly Action _handler;
+
+ public SynchronousProgress(Action handler)
+ {
+ _handler = handler;
+ }
+
+ public void Report(T value)
+ {
+ _handler(value);
+ }
+ }
+ }
+}
+#endif
diff --git a/src/Microsoft.Dism.Tests/SetEditionAsyncTest.cs b/src/Microsoft.Dism.Tests/SetEditionAsyncTest.cs
new file mode 100644
index 0000000..85b8391
--- /dev/null
+++ b/src/Microsoft.Dism.Tests/SetEditionAsyncTest.cs
@@ -0,0 +1,101 @@
+// Copyright (c). All rights reserved.
+//
+// Licensed under the MIT license.
+#if !NETFRAMEWORK
+using Shouldly;
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+using Xunit;
+
+namespace Microsoft.Dism.Tests
+{
+ public class SetEditionAsyncTest : DismInstallWimTestBase
+ {
+ public SetEditionAsyncTest(TestWimTemplate template, ITestOutputHelper testOutput)
+ : base(template, testOutput)
+ {
+ }
+
+ [Fact]
+ public async Task SetEditionAsyncCancellation()
+ {
+ using var cts = new CancellationTokenSource();
+ cts.Cancel();
+
+ bool canceled = false;
+
+ try
+ {
+ await DismApi.SetEditionAsync(Session, "FakeEdition", cancellationToken: cts.Token);
+ }
+ catch (OperationCanceledException)
+ {
+ canceled = true;
+ }
+
+ canceled.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task SetEditionAndProductKeyAsyncCancellation()
+ {
+ using var cts = new CancellationTokenSource();
+ cts.Cancel();
+
+ bool canceled = false;
+
+ try
+ {
+ await DismApi.SetEditionAndProductKeyAsync(Session, "FakeEdition", "XXXXX-XXXXX-XXXXX-XXXXX-XXXXX", cancellationToken: cts.Token);
+ }
+ catch (OperationCanceledException)
+ {
+ canceled = true;
+ }
+
+ canceled.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task SetEditionAsyncWithProgress()
+ {
+ using var cts = new CancellationTokenSource();
+
+ var progress = new SynchronousProgress(_ =>
+ {
+ cts.Cancel();
+ });
+
+ try
+ {
+ await DismApi.SetEditionAsync(Session, "FakeEdition", progress: progress, cancellationToken: cts.Token);
+ }
+ catch (OperationCanceledException)
+ {
+ }
+ catch (DismException)
+ {
+ // Expected when the edition does not exist
+ }
+
+ // Progress may not be called for an invalid edition, so we just verify no hang occurred
+ }
+
+ private sealed class SynchronousProgress : IProgress
+ {
+ private readonly Action _handler;
+
+ public SynchronousProgress(Action handler)
+ {
+ _handler = handler;
+ }
+
+ public void Report(T value)
+ {
+ _handler(value);
+ }
+ }
+ }
+}
+#endif
diff --git a/src/Microsoft.Dism.Tests/UnmountImageAsyncTest.cs b/src/Microsoft.Dism.Tests/UnmountImageAsyncTest.cs
new file mode 100644
index 0000000..cca5761
--- /dev/null
+++ b/src/Microsoft.Dism.Tests/UnmountImageAsyncTest.cs
@@ -0,0 +1,109 @@
+// Copyright (c). All rights reserved.
+//
+// Licensed under the MIT license.
+#if !NETFRAMEWORK
+using Shouldly;
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+using Xunit;
+
+namespace Microsoft.Dism.Tests
+{
+ public class UnmountImageAsyncTest : DismTestBase
+ {
+ public UnmountImageAsyncTest(TestWimTemplate template, ITestOutputHelper testOutput)
+ : base(template, testOutput)
+ {
+ }
+
+ [Fact]
+ public async Task UnmountImageAsyncCancellation()
+ {
+ using var cts = new CancellationTokenSource();
+ cts.Cancel();
+
+ bool canceled = false;
+
+ try
+ {
+ await DismApi.UnmountImageAsync(MountPath.FullName, commitChanges: false, cancellationToken: cts.Token);
+ }
+ catch (OperationCanceledException)
+ {
+ canceled = true;
+ }
+
+ canceled.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task UnmountImageAsyncWithProgress()
+ {
+ // Mount an image first so we can unmount it
+ foreach (DismMountedImageInfo mountedImageInfo in DismApi.GetMountedImages())
+ {
+ DismApi.UnmountImage(mountedImageInfo.MountPath, false);
+ }
+
+ DismApi.CleanupMountpoints();
+ DismApi.MountImage(InstallWimPath.FullName, MountPath.FullName, 1);
+
+ using var cts = new CancellationTokenSource();
+
+ var progress = new SynchronousProgress(_ =>
+ {
+ });
+
+ try
+ {
+ await DismApi.UnmountImageAsync(MountPath.FullName, commitChanges: false, progress: progress, cancellationToken: cts.Token);
+ }
+ catch (DismException)
+ {
+ // Attempt to clean up
+ try
+ {
+ DismApi.UnmountImage(MountPath.FullName, commitChanges: false);
+ }
+ catch
+ {
+ // Best effort cleanup
+ }
+ }
+
+ // Progress may or may not be called depending on image size
+ }
+
+ [Fact]
+ public async Task UnmountImageAsyncHappyPath()
+ {
+ // Mount an image first so we can unmount it
+ foreach (DismMountedImageInfo mountedImageInfo in DismApi.GetMountedImages())
+ {
+ DismApi.UnmountImage(mountedImageInfo.MountPath, false);
+ }
+
+ DismApi.CleanupMountpoints();
+ DismApi.MountImage(InstallWimPath.FullName, MountPath.FullName, 1);
+
+ await DismApi.UnmountImageAsync(MountPath.FullName, commitChanges: false, cancellationToken: TestContext.Current.CancellationToken);
+ }
+
+ private sealed class SynchronousProgress : IProgress
+ {
+ private readonly Action _handler;
+
+ public SynchronousProgress(Action handler)
+ {
+ _handler = handler;
+ }
+
+ public void Report(T value)
+ {
+ _handler(value);
+ }
+ }
+ }
+}
+#endif
diff --git a/src/Microsoft.Dism/DismApi.AddCapability.cs b/src/Microsoft.Dism/DismApi.AddCapability.cs
index da26570..c5949b5 100644
--- a/src/Microsoft.Dism/DismApi.AddCapability.cs
+++ b/src/Microsoft.Dism/DismApi.AddCapability.cs
@@ -121,7 +121,7 @@ public static Task AddCapabilityAsync(DismSession session, string capabilityName
ctsRegistration.Dispose();
}
},
- cancellationToken,
+ CancellationToken.None,
TaskCreationOptions.LongRunning,
TaskScheduler.Default);
diff --git a/src/Microsoft.Dism/DismApi.AddPackage.cs b/src/Microsoft.Dism/DismApi.AddPackage.cs
index 38fae3f..5d2f01a 100644
--- a/src/Microsoft.Dism/DismApi.AddPackage.cs
+++ b/src/Microsoft.Dism/DismApi.AddPackage.cs
@@ -122,7 +122,7 @@ public static Task AddPackageAsync(DismSession session, string packagePath, bool
ctsRegistration.Dispose();
}
},
- cancellationToken,
+ CancellationToken.None,
TaskCreationOptions.LongRunning,
TaskScheduler.Default);
diff --git a/src/Microsoft.Dism/DismApi.CheckImageHealth.cs b/src/Microsoft.Dism/DismApi.CheckImageHealth.cs
index 84b667a..5622326 100644
--- a/src/Microsoft.Dism/DismApi.CheckImageHealth.cs
+++ b/src/Microsoft.Dism/DismApi.CheckImageHealth.cs
@@ -111,7 +111,7 @@ public static Task CheckImageHealthAsync(DismSession sessi
ctsRegistration.Dispose();
}
},
- cancellationToken,
+ CancellationToken.None,
TaskCreationOptions.LongRunning,
TaskScheduler.Default);
diff --git a/src/Microsoft.Dism/DismApi.CommitImage.cs b/src/Microsoft.Dism/DismApi.CommitImage.cs
index cd0aa76..0fb6bbc 100644
--- a/src/Microsoft.Dism/DismApi.CommitImage.cs
+++ b/src/Microsoft.Dism/DismApi.CommitImage.cs
@@ -111,7 +111,7 @@ public static Task CommitImageAsync(DismSession session, bool discardChanges, IP
ctsRegistration.Dispose();
}
},
- cancellationToken,
+ CancellationToken.None,
TaskCreationOptions.LongRunning,
TaskScheduler.Default);
diff --git a/src/Microsoft.Dism/DismApi.DisableFeature.cs b/src/Microsoft.Dism/DismApi.DisableFeature.cs
index 9be4485..bf1f86b 100644
--- a/src/Microsoft.Dism/DismApi.DisableFeature.cs
+++ b/src/Microsoft.Dism/DismApi.DisableFeature.cs
@@ -126,7 +126,7 @@ public static Task DisableFeatureAsync(DismSession session, string featureName,
ctsRegistration.Dispose();
}
},
- cancellationToken,
+ CancellationToken.None,
TaskCreationOptions.LongRunning,
TaskScheduler.Default);
diff --git a/src/Microsoft.Dism/DismApi.EnableFeature.cs b/src/Microsoft.Dism/DismApi.EnableFeature.cs
index b489fc3..d2652e8 100644
--- a/src/Microsoft.Dism/DismApi.EnableFeature.cs
+++ b/src/Microsoft.Dism/DismApi.EnableFeature.cs
@@ -312,7 +312,7 @@ private static Task EnableFeatureAsync(DismSession session, string featureName,
ctsRegistration.Dispose();
}
},
- cancellationToken,
+ CancellationToken.None,
TaskCreationOptions.LongRunning,
TaskScheduler.Default);
diff --git a/src/Microsoft.Dism/DismApi.MountImage.cs b/src/Microsoft.Dism/DismApi.MountImage.cs
index 92cd865..d11adf4 100644
--- a/src/Microsoft.Dism/DismApi.MountImage.cs
+++ b/src/Microsoft.Dism/DismApi.MountImage.cs
@@ -300,7 +300,7 @@ private static Task MountImageAsync(string imageFilePath, string mountPath, int
ctsRegistration.Dispose();
}
},
- cancellationToken,
+ CancellationToken.None,
TaskCreationOptions.LongRunning,
TaskScheduler.Default);
diff --git a/src/Microsoft.Dism/DismApi.RemoveCapability.cs b/src/Microsoft.Dism/DismApi.RemoveCapability.cs
index e296a04..731e059 100644
--- a/src/Microsoft.Dism/DismApi.RemoveCapability.cs
+++ b/src/Microsoft.Dism/DismApi.RemoveCapability.cs
@@ -96,7 +96,7 @@ public static Task RemoveCapabilityAsync(DismSession session, string capabilityN
ctsRegistration.Dispose();
}
},
- cancellationToken,
+ CancellationToken.None,
TaskCreationOptions.LongRunning,
TaskScheduler.Default);
diff --git a/src/Microsoft.Dism/DismApi.RemovePackage.cs b/src/Microsoft.Dism/DismApi.RemovePackage.cs
index 9ffaaf1..fa998c9 100644
--- a/src/Microsoft.Dism/DismApi.RemovePackage.cs
+++ b/src/Microsoft.Dism/DismApi.RemovePackage.cs
@@ -170,7 +170,7 @@ private static Task RemovePackageAsync(DismSession session, string identifier, D
ctsRegistration.Dispose();
}
},
- cancellationToken,
+ CancellationToken.None,
TaskCreationOptions.LongRunning,
TaskScheduler.Default);
diff --git a/src/Microsoft.Dism/DismApi.RestoreImageHealth.cs b/src/Microsoft.Dism/DismApi.RestoreImageHealth.cs
index ec515de..e7501ae 100644
--- a/src/Microsoft.Dism/DismApi.RestoreImageHealth.cs
+++ b/src/Microsoft.Dism/DismApi.RestoreImageHealth.cs
@@ -132,7 +132,7 @@ public static Task RestoreImageHealthAsync(DismSession session, bool limitAccess
ctsRegistration.Dispose();
}
},
- cancellationToken,
+ CancellationToken.None,
TaskCreationOptions.LongRunning,
TaskScheduler.Default);
diff --git a/src/Microsoft.Dism/DismApi.SetEdition.cs b/src/Microsoft.Dism/DismApi.SetEdition.cs
index 49aa82d..e60d09c 100644
--- a/src/Microsoft.Dism/DismApi.SetEdition.cs
+++ b/src/Microsoft.Dism/DismApi.SetEdition.cs
@@ -170,7 +170,7 @@ private static Task SetEditionAsync(DismSession session, string editionId, strin
ctsRegistration.Dispose();
}
},
- cancellationToken,
+ CancellationToken.None,
TaskCreationOptions.LongRunning,
TaskScheduler.Default);
diff --git a/src/Microsoft.Dism/DismApi.UnmountImage.cs b/src/Microsoft.Dism/DismApi.UnmountImage.cs
index 95527cd..2a86b41 100644
--- a/src/Microsoft.Dism/DismApi.UnmountImage.cs
+++ b/src/Microsoft.Dism/DismApi.UnmountImage.cs
@@ -111,7 +111,7 @@ public static Task UnmountImageAsync(string mountPath, bool commitChanges, IProg
ctsRegistration.Dispose();
}
},
- cancellationToken,
+ CancellationToken.None,
TaskCreationOptions.LongRunning,
TaskScheduler.Default);
From 7efd06d0a0f7176a48653626ae7c763813e979ea Mon Sep 17 00:00:00 2001
From: Jeff Kluge
Date: Mon, 30 Mar 2026 10:46:26 -0700
Subject: [PATCH 09/10] Migrate from StyleCop to EditorConfig
---
.editorconfig | 113 ++++++++++++++++++
.gitignore | 5 +-
Directory.Packages.props | 6 +-
Microsoft.Dism.sln | 5 +-
.../AddCapabilityAsyncTest.cs | 6 +-
.../AddPackageAsyncTest.cs | 6 +-
src/Microsoft.Dism.Tests/ApplyUnattendTest.cs | 2 +-
.../CheckImageHealthAsyncTest.cs | 6 +-
.../CommitImageAsyncTest.cs | 6 +-
.../DisableFeatureAsyncTest.cs | 6 +-
.../DismAppxPackageTest.cs | 2 +-
.../DismCapabilityInfoTest.cs | 8 +-
.../DismCapabilityTest.cs | 2 +-
.../DismCollectionTest.cs | 2 +-
.../DismCustomPropertyTest.cs | 2 +-
.../DismDriverPackageTest.cs | 2 +-
src/Microsoft.Dism.Tests/DismDriverTest.cs | 2 +-
.../DismFeatureInfoTest.cs | 10 +-
src/Microsoft.Dism.Tests/DismFeatureTest.cs | 2 +-
src/Microsoft.Dism.Tests/DismImageInfoTest.cs | 8 +-
.../DismInitializeTest.cs | 4 +-
.../DismMountedImageInfoTest.cs | 2 +-
.../DismPackageInfoExTest.cs | 13 +-
.../DismPackageInfoTest.cs | 16 +--
src/Microsoft.Dism.Tests/DismPackageTest.cs | 2 +-
src/Microsoft.Dism.Tests/DismSessionTest.cs | 2 +-
.../DismWimCustomizedInfoTest.cs | 4 +-
.../EnableFeatureAsyncTest.cs | 10 +-
src/Microsoft.Dism.Tests/ExtensionMethods.cs | 2 +-
.../MountImageAsyncTest.cs | 8 +-
.../RemoveCapabilityAsyncTest.cs | 6 +-
.../RemovePackageAsyncTest.cs | 8 +-
.../RestoreImageHealthAsyncTest.cs | 6 +-
.../SetEditionAsyncTest.cs | 8 +-
src/Microsoft.Dism.Tests/TestWimTemplate.cs | 12 +-
.../UnmountImageAsyncTest.cs | 6 +-
src/Microsoft.Dism/DismApi.AddCapability.cs | 12 +-
src/Microsoft.Dism/DismApi.AddPackage.cs | 8 +-
.../DismApi.AddProvisionedAppxPackage.cs | 6 +-
.../DismApi.CheckImageHealth.cs | 8 +-
src/Microsoft.Dism/DismApi.CommitImage.cs | 8 +-
src/Microsoft.Dism/DismApi.DisableFeature.cs | 8 +-
src/Microsoft.Dism/DismApi.EnableFeature.cs | 12 +-
src/Microsoft.Dism/DismApi.Initialize.cs | 2 +-
src/Microsoft.Dism/DismApi.MountImage.cs | 8 +-
.../DismApi.RemoveCapability.cs | 8 +-
src/Microsoft.Dism/DismApi.RemovePackage.cs | 8 +-
.../DismApi.RestoreImageHealth.cs | 12 +-
src/Microsoft.Dism/DismApi.SetEdition.cs | 8 +-
src/Microsoft.Dism/DismApi.UnmountImage.cs | 8 +-
src/Microsoft.Dism/DismUtilities.cs | 4 +-
src/Microsoft.Dism/ExtensionMethods.cs | 4 +-
stylecop.json | 16 ---
53 files changed, 269 insertions(+), 181 deletions(-)
create mode 100644 .editorconfig
delete mode 100644 stylecop.json
diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..0cc0bb0
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,113 @@
+root = true
+
+[*.cs]
+csharp_using_directive_placement = outside_namespace:silent
+dotnet_sort_system_directives_first = false
+dotnet_separate_import_directive_groups = true
+file_header_template = Copyright (c). All rights reserved.\n\nLicensed under the MIT license.
+csharp_prefer_simple_using_statement = true:suggestion
+csharp_prefer_braces = true:silent
+csharp_style_namespace_declarations = block_scoped:silent
+csharp_style_prefer_method_group_conversion = true:silent
+csharp_style_prefer_top_level_statements = true:silent
+csharp_style_prefer_primary_constructors = true:suggestion
+csharp_prefer_system_threading_lock = true:suggestion
+csharp_style_prefer_simple_property_accessors = true:suggestion
+csharp_style_expression_bodied_methods = false:silent
+csharp_style_expression_bodied_constructors = false:silent
+csharp_style_expression_bodied_operators = false:silent
+csharp_style_expression_bodied_properties = true:silent
+csharp_style_expression_bodied_indexers = true:silent
+csharp_style_expression_bodied_accessors = true:silent
+csharp_style_expression_bodied_lambdas = true:silent
+csharp_style_expression_bodied_local_functions = false:silent
+csharp_style_throw_expression = true:suggestion
+csharp_style_prefer_null_check_over_type_check = true:suggestion
+csharp_prefer_simple_default_expression = true:suggestion
+csharp_style_prefer_local_over_anonymous_function = true:suggestion
+csharp_style_prefer_index_operator = true:suggestion
+csharp_style_prefer_range_operator = true:suggestion
+csharp_style_implicit_object_creation_when_type_is_apparent = true:error
+csharp_style_prefer_implicitly_typed_lambda_expression = true:suggestion
+csharp_style_prefer_tuple_swap = true:suggestion
+csharp_style_inlined_variable_declaration = true:suggestion
+csharp_style_deconstructed_variable_declaration = true:suggestion
+csharp_style_var_for_built_in_types = false:error
+csharp_style_var_when_type_is_apparent = false:error
+csharp_style_var_elsewhere = false:error
+csharp_style_allow_embedded_statements_on_same_line_experimental = true:silent
+csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true:silent
+csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true:silent
+csharp_style_allow_blank_line_after_token_in_conditional_expression_experimental = true:silent
+csharp_style_allow_blank_line_after_token_in_arrow_expression_clause_experimental = true:silent
+csharp_style_prefer_unbound_generic_type_in_nameof = true:suggestion
+csharp_style_prefer_utf8_string_literals = true:suggestion
+[*.{cs,vb}]
+#### Naming styles ####
+
+# Naming rules
+
+dotnet_naming_rule.interface_should_be_begins_with_i.severity = suggestion
+dotnet_naming_rule.interface_should_be_begins_with_i.symbols = interface
+dotnet_naming_rule.interface_should_be_begins_with_i.style = begins_with_i
+
+dotnet_naming_rule.types_should_be_pascal_case.severity = suggestion
+dotnet_naming_rule.types_should_be_pascal_case.symbols = types
+dotnet_naming_rule.types_should_be_pascal_case.style = pascal_case
+
+dotnet_naming_rule.non_field_members_should_be_pascal_case.severity = suggestion
+dotnet_naming_rule.non_field_members_should_be_pascal_case.symbols = non_field_members
+dotnet_naming_rule.non_field_members_should_be_pascal_case.style = pascal_case
+
+# Symbol specifications
+
+dotnet_naming_symbols.interface.applicable_kinds = interface
+dotnet_naming_symbols.interface.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
+dotnet_naming_symbols.interface.required_modifiers =
+
+dotnet_naming_symbols.types.applicable_kinds = class, struct, interface, enum
+dotnet_naming_symbols.types.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
+dotnet_naming_symbols.types.required_modifiers =
+
+dotnet_naming_symbols.non_field_members.applicable_kinds = property, event, method
+dotnet_naming_symbols.non_field_members.applicable_accessibilities = public, internal, private, protected, protected_internal, private_protected
+dotnet_naming_symbols.non_field_members.required_modifiers =
+
+# Naming styles
+
+dotnet_naming_style.begins_with_i.required_prefix = I
+dotnet_naming_style.begins_with_i.required_suffix =
+dotnet_naming_style.begins_with_i.word_separator =
+dotnet_naming_style.begins_with_i.capitalization = pascal_case
+
+dotnet_naming_style.pascal_case.required_prefix =
+dotnet_naming_style.pascal_case.required_suffix =
+dotnet_naming_style.pascal_case.word_separator =
+dotnet_naming_style.pascal_case.capitalization = pascal_case
+
+dotnet_naming_style.pascal_case.required_prefix =
+dotnet_naming_style.pascal_case.required_suffix =
+dotnet_naming_style.pascal_case.word_separator =
+dotnet_naming_style.pascal_case.capitalization = pascal_case
+dotnet_style_coalesce_expression = true:suggestion
+dotnet_style_null_propagation = true:suggestion
+dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
+dotnet_style_prefer_auto_properties = true:silent
+dotnet_style_object_initializer = true:suggestion
+dotnet_style_collection_initializer = true:suggestion
+dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
+dotnet_style_prefer_conditional_expression_over_assignment = true:silent
+dotnet_style_prefer_conditional_expression_over_return = true:silent
+dotnet_style_explicit_tuple_names = true:suggestion
+dotnet_style_prefer_inferred_tuple_names = true:suggestion
+dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
+dotnet_style_prefer_compound_assignment = true:suggestion
+dotnet_style_prefer_simplified_interpolation = true:suggestion
+dotnet_style_prefer_collection_expression = when_types_loosely_match:suggestion
+dotnet_style_namespace_match_folder = true:suggestion
+dotnet_style_operator_placement_when_wrapping = beginning_of_line
+tab_width = 4
+indent_size = 4
+end_of_line = crlf
+dotnet_style_allow_multiple_blank_lines_experimental = true:silent
+dotnet_style_allow_statement_immediately_after_block_experimental = true:silent
diff --git a/.gitignore b/.gitignore
index aeb948b..b49744d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -24,8 +24,9 @@ bld/
# Visual Studio 2015 cache/options directory
.vs/
-# Uncomment if you have tasks that create the project's static files in wwwroot
-#wwwroot/
+
+# Copilot directory
+.copilot
# MSTest test Results
[Tt]est[Rr]esult*/
diff --git a/Directory.Packages.props b/Directory.Packages.props
index aa7a684..9a7b44b 100644
--- a/Directory.Packages.props
+++ b/Directory.Packages.props
@@ -3,20 +3,18 @@
true
+
-
-
+
-
-
\ No newline at end of file
diff --git a/Microsoft.Dism.sln b/Microsoft.Dism.sln
index 18534c5..ea3fed3 100644
--- a/Microsoft.Dism.sln
+++ b/Microsoft.Dism.sln
@@ -1,7 +1,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 18
-VisualStudioVersion = 18.3.11214.30 main
+VisualStudioVersion = 18.3.11214.30
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Dism", "src\Microsoft.Dism\Microsoft.Dism.csproj", "{E6831090-F1C2-4619-9AB2-01D29272357A}"
EndProject
@@ -9,6 +9,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Dism.Tests", "src
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2173DC1F-7069-4707-963D-04DCF86C4976}"
ProjectSection(SolutionItems) = preProject
+ .editorconfig = .editorconfig
+ .gitignore = .gitignore
CONTRIBUTING.md = CONTRIBUTING.md
.github\dependabot.yml = .github\dependabot.yml
Directory.Build.props = Directory.Build.props
@@ -20,7 +22,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
LICENSE = LICENSE
NuGet.config = NuGet.config
README.md = README.md
- stylecop.json = stylecop.json
version.json = version.json
EndProjectSection
EndProject
diff --git a/src/Microsoft.Dism.Tests/AddCapabilityAsyncTest.cs b/src/Microsoft.Dism.Tests/AddCapabilityAsyncTest.cs
index 4cccd23..7b25e51 100644
--- a/src/Microsoft.Dism.Tests/AddCapabilityAsyncTest.cs
+++ b/src/Microsoft.Dism.Tests/AddCapabilityAsyncTest.cs
@@ -21,7 +21,7 @@ public AddCapabilityAsyncTest(TestWimTemplate template, ITestOutputHelper testOu
public async Task AddCapabilityAsyncCancellation()
{
using DismSession session = DismApi.OpenOnlineSession();
- using var cts = new CancellationTokenSource();
+ using CancellationTokenSource cts = new();
cts.Cancel();
bool canceled = false;
@@ -42,9 +42,9 @@ public async Task AddCapabilityAsyncCancellation()
public async Task AddCapabilityAsyncWithProgress()
{
using DismSession session = DismApi.OpenOnlineSession();
- using var cts = new CancellationTokenSource();
+ using CancellationTokenSource cts = new();
- var progress = new SynchronousProgress(_ =>
+ SynchronousProgress progress = new(_ =>
{
cts.Cancel();
});
diff --git a/src/Microsoft.Dism.Tests/AddPackageAsyncTest.cs b/src/Microsoft.Dism.Tests/AddPackageAsyncTest.cs
index 87bab3c..2ba5849 100644
--- a/src/Microsoft.Dism.Tests/AddPackageAsyncTest.cs
+++ b/src/Microsoft.Dism.Tests/AddPackageAsyncTest.cs
@@ -21,7 +21,7 @@ public AddPackageAsyncTest(TestWimTemplate template, ITestOutputHelper testOutpu
public async Task AddPackageAsyncCancellation()
{
using DismSession session = DismApi.OpenOnlineSession();
- using var cts = new CancellationTokenSource();
+ using CancellationTokenSource cts = new();
cts.Cancel();
bool canceled = false;
@@ -42,9 +42,9 @@ public async Task AddPackageAsyncCancellation()
public async Task AddPackageAsyncWithProgress()
{
using DismSession session = DismApi.OpenOnlineSession();
- using var cts = new CancellationTokenSource();
+ using CancellationTokenSource cts = new();
- var progress = new SynchronousProgress(_ =>
+ SynchronousProgress progress = new(_ =>
{
cts.Cancel();
});
diff --git a/src/Microsoft.Dism.Tests/ApplyUnattendTest.cs b/src/Microsoft.Dism.Tests/ApplyUnattendTest.cs
index 129260f..dd523ce 100644
--- a/src/Microsoft.Dism.Tests/ApplyUnattendTest.cs
+++ b/src/Microsoft.Dism.Tests/ApplyUnattendTest.cs
@@ -34,7 +34,7 @@ public void ApplyUnattendSimple()
";
- FileInfo unattendXmlFile = new FileInfo(Path.Combine(TestDirectory.FullName, "unattend.xml"));
+ FileInfo unattendXmlFile = new(Path.Combine(TestDirectory.FullName, "unattend.xml"));
unattendXmlFile.WriteAllText(unattendXml);
diff --git a/src/Microsoft.Dism.Tests/CheckImageHealthAsyncTest.cs b/src/Microsoft.Dism.Tests/CheckImageHealthAsyncTest.cs
index f3de6c8..3ab2211 100644
--- a/src/Microsoft.Dism.Tests/CheckImageHealthAsyncTest.cs
+++ b/src/Microsoft.Dism.Tests/CheckImageHealthAsyncTest.cs
@@ -32,7 +32,7 @@ public async Task CheckImageHealthAsyncOnlineSession()
public async Task CheckImageHealthAsyncCancellation()
{
using DismSession session = DismApi.OpenOnlineSession();
- using var cts = new CancellationTokenSource();
+ using CancellationTokenSource cts = new();
cts.Cancel();
bool canceled = false;
@@ -56,9 +56,9 @@ public async Task CheckImageHealthAsyncWithProgress()
int total = -1;
using DismSession session = DismApi.OpenOnlineSession();
- using var cts = new CancellationTokenSource();
+ using CancellationTokenSource cts = new();
- var progress = new SynchronousProgress(p =>
+ SynchronousProgress progress = new(p =>
{
current = p.Current;
total = p.Total;
diff --git a/src/Microsoft.Dism.Tests/CommitImageAsyncTest.cs b/src/Microsoft.Dism.Tests/CommitImageAsyncTest.cs
index d788c61..9254ba6 100644
--- a/src/Microsoft.Dism.Tests/CommitImageAsyncTest.cs
+++ b/src/Microsoft.Dism.Tests/CommitImageAsyncTest.cs
@@ -20,7 +20,7 @@ public CommitImageAsyncTest(TestWimTemplate template, ITestOutputHelper testOutp
[Fact]
public async Task CommitImageAsyncCancellation()
{
- using var cts = new CancellationTokenSource();
+ using CancellationTokenSource cts = new();
cts.Cancel();
bool canceled = false;
@@ -40,9 +40,9 @@ public async Task CommitImageAsyncCancellation()
[Fact]
public async Task CommitImageAsyncWithProgress()
{
- using var cts = new CancellationTokenSource();
+ using CancellationTokenSource cts = new();
- var progress = new SynchronousProgress(_ =>
+ SynchronousProgress progress = new(_ =>
{
cts.Cancel();
});
diff --git a/src/Microsoft.Dism.Tests/DisableFeatureAsyncTest.cs b/src/Microsoft.Dism.Tests/DisableFeatureAsyncTest.cs
index 1488787..a9131e2 100644
--- a/src/Microsoft.Dism.Tests/DisableFeatureAsyncTest.cs
+++ b/src/Microsoft.Dism.Tests/DisableFeatureAsyncTest.cs
@@ -21,7 +21,7 @@ public DisableFeatureAsyncTest(TestWimTemplate template, ITestOutputHelper testO
public async Task DisableFeatureAsyncCancellation()
{
using DismSession session = DismApi.OpenOnlineSession();
- using var cts = new CancellationTokenSource();
+ using CancellationTokenSource cts = new();
cts.Cancel();
bool canceled = false;
@@ -42,9 +42,9 @@ public async Task DisableFeatureAsyncCancellation()
public async Task DisableFeatureAsyncWithProgress()
{
using DismSession session = DismApi.OpenOnlineSession();
- using var cts = new CancellationTokenSource();
+ using CancellationTokenSource cts = new();
- var progress = new SynchronousProgress(_ =>
+ SynchronousProgress progress = new(_ =>
{
cts.Cancel();
});
diff --git a/src/Microsoft.Dism.Tests/DismAppxPackageTest.cs b/src/Microsoft.Dism.Tests/DismAppxPackageTest.cs
index 5b56dd2..bcfb759 100644
--- a/src/Microsoft.Dism.Tests/DismAppxPackageTest.cs
+++ b/src/Microsoft.Dism.Tests/DismAppxPackageTest.cs
@@ -11,7 +11,7 @@ namespace Microsoft.Dism.Tests
{
public class DismAppxPackageCollectionTest : DismCollectionTest
{
- private static readonly List Items = new List
+ private static readonly List Items = new()
{
new DismApi.DismAppxPackage_
{
diff --git a/src/Microsoft.Dism.Tests/DismCapabilityInfoTest.cs b/src/Microsoft.Dism.Tests/DismCapabilityInfoTest.cs
index 5411aee..49032c3 100644
--- a/src/Microsoft.Dism.Tests/DismCapabilityInfoTest.cs
+++ b/src/Microsoft.Dism.Tests/DismCapabilityInfoTest.cs
@@ -9,7 +9,7 @@ namespace Microsoft.Dism.Tests
{
public class DismCapabilityInfoTest : DismStructTest
{
- private readonly DismApi.DismCapabilityInfo_ _capabilityInfo = new DismApi.DismCapabilityInfo_
+ private readonly DismApi.DismCapabilityInfo_ _capabilityInfo = new()
{
Name = "6CDAF47E-B7D8-4A46-9B83-E13CDA1706A7",
DisplayName = "6411A803-B0CB-4570-9BE7-19644412B3C4",
@@ -24,20 +24,20 @@ public DismCapabilityInfoTest(TestWimTemplate template)
{
}
- protected override DismCapabilityInfo Item => new DismCapabilityInfo(ItemPtr);
+ protected override DismCapabilityInfo Item => new(ItemPtr);
protected override object Struct => _capabilityInfo;
[Fact]
public void DownloadAndInstallSizeDoNotOverflow()
{
- DismApi.DismCapabilityInfo_ dismCapabilityInfo = new DismApi.DismCapabilityInfo_
+ DismApi.DismCapabilityInfo_ dismCapabilityInfo = new()
{
DownloadSize = (uint)int.MaxValue + 1,
InstallSize = (uint)int.MaxValue + 10,
};
- DismCapabilityInfo capabilityInfo = new DismCapabilityInfo(dismCapabilityInfo);
+ DismCapabilityInfo capabilityInfo = new(dismCapabilityInfo);
capabilityInfo.DownloadSize.ShouldBe((uint)int.MaxValue + 1);
capabilityInfo.InstallSize.ShouldBe((uint)int.MaxValue + 10);
diff --git a/src/Microsoft.Dism.Tests/DismCapabilityTest.cs b/src/Microsoft.Dism.Tests/DismCapabilityTest.cs
index 827ee73..6b5a76f 100644
--- a/src/Microsoft.Dism.Tests/DismCapabilityTest.cs
+++ b/src/Microsoft.Dism.Tests/DismCapabilityTest.cs
@@ -11,7 +11,7 @@ namespace Microsoft.Dism.Tests
{
public class DismCapabilityCollectionTest : DismCollectionTest
{
- private static readonly List Items = new List
+ private static readonly List Items = new()
{
new DismApi.DismCapability_
{
diff --git a/src/Microsoft.Dism.Tests/DismCollectionTest.cs b/src/Microsoft.Dism.Tests/DismCollectionTest.cs
index 5983624..f08a679 100644
--- a/src/Microsoft.Dism.Tests/DismCollectionTest.cs
+++ b/src/Microsoft.Dism.Tests/DismCollectionTest.cs
@@ -43,7 +43,7 @@ public void CollectionTest()
public void CollectionTest_Empty()
{
TCollection actual = GetActual(IntPtr.Zero);
- ReadOnlyCollection expected = new ReadOnlyCollection(new List(0));
+ ReadOnlyCollection expected = new(new List(0));
actual.ShouldBe(expected);
}
diff --git a/src/Microsoft.Dism.Tests/DismCustomPropertyTest.cs b/src/Microsoft.Dism.Tests/DismCustomPropertyTest.cs
index f3d3200..59bc42c 100644
--- a/src/Microsoft.Dism.Tests/DismCustomPropertyTest.cs
+++ b/src/Microsoft.Dism.Tests/DismCustomPropertyTest.cs
@@ -11,7 +11,7 @@ namespace Microsoft.Dism.Tests
{
public class DismCustomPropertyCollectionTest : DismCollectionTest
{
- private static readonly List Items = new List
+ private static readonly List Items = new()
{
new DismApi.DismCustomProperty_
{
diff --git a/src/Microsoft.Dism.Tests/DismDriverPackageTest.cs b/src/Microsoft.Dism.Tests/DismDriverPackageTest.cs
index 9094094..2e19416 100644
--- a/src/Microsoft.Dism.Tests/DismDriverPackageTest.cs
+++ b/src/Microsoft.Dism.Tests/DismDriverPackageTest.cs
@@ -11,7 +11,7 @@ namespace Microsoft.Dism.Tests
{
public class DismDriverPackageCollectionTest : DismCollectionTest
{
- private static readonly List Items = new List
+ private static readonly List Items = new()
{
new DismApi.DismDriverPackage_
{
diff --git a/src/Microsoft.Dism.Tests/DismDriverTest.cs b/src/Microsoft.Dism.Tests/DismDriverTest.cs
index aeaeadb..abdd735 100644
--- a/src/Microsoft.Dism.Tests/DismDriverTest.cs
+++ b/src/Microsoft.Dism.Tests/DismDriverTest.cs
@@ -11,7 +11,7 @@ namespace Microsoft.Dism.Tests
{
public class DismDriverCollectionTest : DismCollectionTest
{
- private static readonly List Items = new List
+ private static readonly List Items = new()
{
new DismApi.DismDriver_
{
diff --git a/src/Microsoft.Dism.Tests/DismFeatureInfoTest.cs b/src/Microsoft.Dism.Tests/DismFeatureInfoTest.cs
index 4d97749..b4a6144 100644
--- a/src/Microsoft.Dism.Tests/DismFeatureInfoTest.cs
+++ b/src/Microsoft.Dism.Tests/DismFeatureInfoTest.cs
@@ -10,18 +10,16 @@ namespace Microsoft.Dism.Tests
{
public class DismFeatureInfoTest : DismStructTest
{
- private readonly DismApi.DismFeatureInfo_ _featureInfo = new DismApi.DismFeatureInfo_
+ private readonly DismApi.DismFeatureInfo_ _featureInfo = new()
{
CustomProperty = new List
{
- new DismApi.DismCustomProperty_
- {
+ new() {
Name = "Property1",
Path = "Path1",
Value = "Value1",
},
- new DismApi.DismCustomProperty_
- {
+ new() {
Name = "Property2",
Path = "Path2",
Value = "Value2",
@@ -40,7 +38,7 @@ public DismFeatureInfoTest(TestWimTemplate template)
{
}
- protected override DismFeatureInfo Item => new DismFeatureInfo(ItemPtr);
+ protected override DismFeatureInfo Item => new(ItemPtr);
protected override object Struct => _featureInfo;
diff --git a/src/Microsoft.Dism.Tests/DismFeatureTest.cs b/src/Microsoft.Dism.Tests/DismFeatureTest.cs
index c2fc373..263aa48 100644
--- a/src/Microsoft.Dism.Tests/DismFeatureTest.cs
+++ b/src/Microsoft.Dism.Tests/DismFeatureTest.cs
@@ -11,7 +11,7 @@ namespace Microsoft.Dism.Tests
{
public class DismFeatureCollectionTest : DismCollectionTest
{
- private static readonly List Items = new List
+ private static readonly List Items = new()
{
new DismApi.DismFeature_
{
diff --git a/src/Microsoft.Dism.Tests/DismImageInfoTest.cs b/src/Microsoft.Dism.Tests/DismImageInfoTest.cs
index c6a8b70..dc83e5d 100644
--- a/src/Microsoft.Dism.Tests/DismImageInfoTest.cs
+++ b/src/Microsoft.Dism.Tests/DismImageInfoTest.cs
@@ -12,7 +12,7 @@ namespace Microsoft.Dism.Tests
{
public class DismImageInfoCollectionTest : DismCollectionTest
{
- private readonly List _items = new List
+ private readonly List _items = new()
{
new DismApi.DismImageInfo_
{
@@ -37,8 +37,8 @@ public class DismImageInfoCollectionTest : DismCollectionTest
{
- new DismApi.DismLanguage("en-us"),
- new DismApi.DismLanguage("es-es"),
+ new("en-us"),
+ new("es-es"),
}.ToPtr(),
LanguageCount = 2,
MajorVersion = 2,
@@ -73,7 +73,7 @@ public class DismImageInfoCollectionTest : DismCollectionTest
{
- new DismApi.DismLanguage("es-es"),
+ new("es-es"),
}.ToPtr(),
LanguageCount = 1,
MajorVersion = 2,
diff --git a/src/Microsoft.Dism.Tests/DismInitializeTest.cs b/src/Microsoft.Dism.Tests/DismInitializeTest.cs
index 464084d..8617128 100644
--- a/src/Microsoft.Dism.Tests/DismInitializeTest.cs
+++ b/src/Microsoft.Dism.Tests/DismInitializeTest.cs
@@ -56,7 +56,7 @@ public void InitializeExWithLogFilePath()
[Fact]
public void InitializeExWithScratchDirectory()
{
- FileInfo logFile = new FileInfo(Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid():N}.log"));
+ FileInfo logFile = new(Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid():N}.log"));
DirectoryInfo scratchDirectory = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N")));
DismApi.InitializeEx(DismLogLevel.LogErrors, logFile.FullName, scratchDirectory.FullName);
@@ -121,7 +121,7 @@ public void InitializeWithLogFilePath()
[Fact]
public void InitializeWithScratchDirectory()
{
- FileInfo logFile = new FileInfo(Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid():N}.log"));
+ FileInfo logFile = new(Path.Combine(Path.GetTempPath(), $"{Guid.NewGuid():N}.log"));
DirectoryInfo scratchDirectory = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N")));
DismApi.Initialize(DismLogLevel.LogErrors, logFile.FullName, scratchDirectory.FullName);
diff --git a/src/Microsoft.Dism.Tests/DismMountedImageInfoTest.cs b/src/Microsoft.Dism.Tests/DismMountedImageInfoTest.cs
index afb0692..41f1387 100644
--- a/src/Microsoft.Dism.Tests/DismMountedImageInfoTest.cs
+++ b/src/Microsoft.Dism.Tests/DismMountedImageInfoTest.cs
@@ -11,7 +11,7 @@ namespace Microsoft.Dism.Tests
{
public class DismMountedImageInfoCollectionTest : DismCollectionTest
{
- private static readonly List Items = new List
+ private static readonly List Items = new()
{
new DismApi.DismMountedImageInfo_
{
diff --git a/src/Microsoft.Dism.Tests/DismPackageInfoExTest.cs b/src/Microsoft.Dism.Tests/DismPackageInfoExTest.cs
index a36b972..8510351 100644
--- a/src/Microsoft.Dism.Tests/DismPackageInfoExTest.cs
+++ b/src/Microsoft.Dism.Tests/DismPackageInfoExTest.cs
@@ -11,7 +11,7 @@ namespace Microsoft.Dism.Tests
{
public class DismPackageInfoExTest : DismStructTest
{
- private readonly DismApi.DismPackageInfoEx_ _packageInfo = new DismApi.DismPackageInfoEx_
+ private readonly DismApi.DismPackageInfoEx_ _packageInfo = new()
{
PackageInfo = new DismApi.DismPackageInfo_
{
@@ -21,8 +21,7 @@ public class DismPackageInfoExTest : DismStructTest
CreationTime = DateTime.Today.AddDays(-5),
CustomProperty = new List
{
- new DismApi.DismCustomProperty_
- {
+ new() {
Name = "TheName",
Path = "ThePath",
Value = "TheValue",
@@ -33,13 +32,11 @@ public class DismPackageInfoExTest : DismStructTest
DisplayName = "DisplayName",
Feature = new List
{
- new DismApi.DismFeature_
- {
+ new() {
FeatureName = "Feature1",
State = DismPackageFeatureState.PartiallyInstalled,
},
- new DismApi.DismFeature_
- {
+ new() {
FeatureName = "Feature2",
State = DismPackageFeatureState.Installed,
},
@@ -66,7 +63,7 @@ public DismPackageInfoExTest(TestWimTemplate template)
{
}
- protected override DismPackageInfoEx Item => new DismPackageInfoEx(ItemPtr);
+ protected override DismPackageInfoEx Item => new(ItemPtr);
protected override object Struct => _packageInfo;
diff --git a/src/Microsoft.Dism.Tests/DismPackageInfoTest.cs b/src/Microsoft.Dism.Tests/DismPackageInfoTest.cs
index 4e01c1e..da1a007 100644
--- a/src/Microsoft.Dism.Tests/DismPackageInfoTest.cs
+++ b/src/Microsoft.Dism.Tests/DismPackageInfoTest.cs
@@ -11,7 +11,7 @@ namespace Microsoft.Dism.Tests
{
public class DismPackageInfoTest : DismStructTest
{
- private readonly DismApi.DismPackageInfo_ _packageInfo = new DismApi.DismPackageInfo_
+ private readonly DismApi.DismPackageInfo_ _packageInfo = new()
{
Applicable = true,
Company = "Company",
@@ -19,14 +19,12 @@ public class DismPackageInfoTest : DismStructTest
CreationTime = DateTime.Today.AddDays(-5),
CustomProperty = new List
{
- new DismApi.DismCustomProperty_
- {
+ new() {
Name = "Name1",
Path = "Path1",
Value = "Value1",
},
- new DismApi.DismCustomProperty_
- {
+ new() {
Name = "Name2",
Path = "Path2",
Value = "Value2",
@@ -37,13 +35,11 @@ public class DismPackageInfoTest : DismStructTest
DisplayName = "DisplayName",
Feature = new List
{
- new DismApi.DismFeature_
- {
+ new() {
FeatureName = "FeatureName1",
State = DismPackageFeatureState.Installed,
},
- new DismApi.DismFeature_
- {
+ new() {
FeatureName = "FeatureName2",
State = DismPackageFeatureState.Superseded,
},
@@ -68,7 +64,7 @@ public DismPackageInfoTest(TestWimTemplate template)
{
}
- protected override DismPackageInfo Item => new DismPackageInfo(ItemPtr);
+ protected override DismPackageInfo Item => new(ItemPtr);
protected override object Struct => _packageInfo;
diff --git a/src/Microsoft.Dism.Tests/DismPackageTest.cs b/src/Microsoft.Dism.Tests/DismPackageTest.cs
index fe798ae..dc858d7 100644
--- a/src/Microsoft.Dism.Tests/DismPackageTest.cs
+++ b/src/Microsoft.Dism.Tests/DismPackageTest.cs
@@ -11,7 +11,7 @@ namespace Microsoft.Dism.Tests
{
public class DismPackageCollectionTest : DismCollectionTest
{
- private static readonly List Items = new List
+ private static readonly List Items = new()
{
new DismApi.DismPackage_
{
diff --git a/src/Microsoft.Dism.Tests/DismSessionTest.cs b/src/Microsoft.Dism.Tests/DismSessionTest.cs
index e70ca7f..24f3184 100644
--- a/src/Microsoft.Dism.Tests/DismSessionTest.cs
+++ b/src/Microsoft.Dism.Tests/DismSessionTest.cs
@@ -18,7 +18,7 @@ public DismSessionTest(TestWimTemplate template, ITestOutputHelper testOutput)
[Fact]
public void SessionOptionsDefaults()
{
- DismSessionOptions options = new DismSessionOptions();
+ DismSessionOptions options = new();
options.ThrowExceptionOnRebootRequired.ShouldBeTrue();
}
diff --git a/src/Microsoft.Dism.Tests/DismWimCustomizedInfoTest.cs b/src/Microsoft.Dism.Tests/DismWimCustomizedInfoTest.cs
index 8f48ee5..3dd3a46 100644
--- a/src/Microsoft.Dism.Tests/DismWimCustomizedInfoTest.cs
+++ b/src/Microsoft.Dism.Tests/DismWimCustomizedInfoTest.cs
@@ -9,7 +9,7 @@ namespace Microsoft.Dism.Tests
{
public class DismWimCustomizedInfoTest : DismStructTest
{
- private readonly DismApi.DismWimCustomizedInfo_ _customizedInfo = new DismApi.DismWimCustomizedInfo_
+ private readonly DismApi.DismWimCustomizedInfo_ _customizedInfo = new()
{
CreatedTime = DateTime.Today.AddDays(-15),
DirectoryCount = 123,
@@ -23,7 +23,7 @@ public DismWimCustomizedInfoTest(TestWimTemplate template)
{
}
- protected override DismWimCustomizedInfo Item => new DismWimCustomizedInfo(_customizedInfo);
+ protected override DismWimCustomizedInfo Item => new(_customizedInfo);
protected override object Struct => _customizedInfo;
diff --git a/src/Microsoft.Dism.Tests/EnableFeatureAsyncTest.cs b/src/Microsoft.Dism.Tests/EnableFeatureAsyncTest.cs
index 755f369..17ae751 100644
--- a/src/Microsoft.Dism.Tests/EnableFeatureAsyncTest.cs
+++ b/src/Microsoft.Dism.Tests/EnableFeatureAsyncTest.cs
@@ -21,7 +21,7 @@ public EnableFeatureAsyncTest(TestWimTemplate template, ITestOutputHelper testOu
public async Task EnableFeatureAsyncCancellation()
{
using DismSession session = DismApi.OpenOnlineSession();
- using var cts = new CancellationTokenSource();
+ using CancellationTokenSource cts = new();
cts.Cancel();
bool canceled = false;
@@ -42,7 +42,7 @@ public async Task EnableFeatureAsyncCancellation()
public async Task EnableFeatureByPackageNameAsyncCancellation()
{
using DismSession session = DismApi.OpenOnlineSession();
- using var cts = new CancellationTokenSource();
+ using CancellationTokenSource cts = new();
cts.Cancel();
bool canceled = false;
@@ -63,7 +63,7 @@ public async Task EnableFeatureByPackageNameAsyncCancellation()
public async Task EnableFeatureByPackagePathAsyncCancellation()
{
using DismSession session = DismApi.OpenOnlineSession();
- using var cts = new CancellationTokenSource();
+ using CancellationTokenSource cts = new();
cts.Cancel();
bool canceled = false;
@@ -84,9 +84,9 @@ public async Task EnableFeatureByPackagePathAsyncCancellation()
public async Task EnableFeatureAsyncWithProgress()
{
using DismSession session = DismApi.OpenOnlineSession();
- using var cts = new CancellationTokenSource();
+ using CancellationTokenSource cts = new();
- var progress = new SynchronousProgress(_ =>
+ SynchronousProgress progress = new(_ =>
{
cts.Cancel();
});
diff --git a/src/Microsoft.Dism.Tests/ExtensionMethods.cs b/src/Microsoft.Dism.Tests/ExtensionMethods.cs
index c679ecd..3de5426 100644
--- a/src/Microsoft.Dism.Tests/ExtensionMethods.cs
+++ b/src/Microsoft.Dism.Tests/ExtensionMethods.cs
@@ -21,7 +21,7 @@ public static IntPtr ToPtr(this IList list)
for (int i = 0; i < list.Count; i++)
{
- IntPtr currentPtr = new IntPtr(startPtr + (i * structSize));
+ IntPtr currentPtr = new(startPtr + (i * structSize));
Marshal.StructureToPtr(list[i] !, currentPtr, false);
}
diff --git a/src/Microsoft.Dism.Tests/MountImageAsyncTest.cs b/src/Microsoft.Dism.Tests/MountImageAsyncTest.cs
index c7ded4e..9e818c9 100644
--- a/src/Microsoft.Dism.Tests/MountImageAsyncTest.cs
+++ b/src/Microsoft.Dism.Tests/MountImageAsyncTest.cs
@@ -48,7 +48,7 @@ public async Task MountImageAsyncByIndexHappyPath()
[Fact]
public async Task MountImageAsyncByIndexCancellation()
{
- using var cts = new CancellationTokenSource();
+ using CancellationTokenSource cts = new();
cts.Cancel();
bool canceled = false;
@@ -68,7 +68,7 @@ public async Task MountImageAsyncByIndexCancellation()
[Fact]
public async Task MountImageAsyncByNameCancellation()
{
- using var cts = new CancellationTokenSource();
+ using CancellationTokenSource cts = new();
cts.Cancel();
bool canceled = false;
@@ -97,9 +97,9 @@ public async Task MountImageAsyncWithProgress()
DismApi.CleanupMountpoints();
- using var cts = new CancellationTokenSource();
+ using CancellationTokenSource cts = new();
- var progress = new SynchronousProgress(_ =>
+ SynchronousProgress progress = new(_ =>
{
progressCalled = true;
});
diff --git a/src/Microsoft.Dism.Tests/RemoveCapabilityAsyncTest.cs b/src/Microsoft.Dism.Tests/RemoveCapabilityAsyncTest.cs
index 802aab9..fbf955b 100644
--- a/src/Microsoft.Dism.Tests/RemoveCapabilityAsyncTest.cs
+++ b/src/Microsoft.Dism.Tests/RemoveCapabilityAsyncTest.cs
@@ -21,7 +21,7 @@ public RemoveCapabilityAsyncTest(TestWimTemplate template, ITestOutputHelper tes
public async Task RemoveCapabilityAsyncCancellation()
{
using DismSession session = DismApi.OpenOnlineSession();
- using var cts = new CancellationTokenSource();
+ using CancellationTokenSource cts = new();
cts.Cancel();
bool canceled = false;
@@ -42,9 +42,9 @@ public async Task RemoveCapabilityAsyncCancellation()
public async Task RemoveCapabilityAsyncWithProgress()
{
using DismSession session = DismApi.OpenOnlineSession();
- using var cts = new CancellationTokenSource();
+ using CancellationTokenSource cts = new();
- var progress = new SynchronousProgress(_ =>
+ SynchronousProgress progress = new(_ =>
{
cts.Cancel();
});
diff --git a/src/Microsoft.Dism.Tests/RemovePackageAsyncTest.cs b/src/Microsoft.Dism.Tests/RemovePackageAsyncTest.cs
index ec8ec39..e609256 100644
--- a/src/Microsoft.Dism.Tests/RemovePackageAsyncTest.cs
+++ b/src/Microsoft.Dism.Tests/RemovePackageAsyncTest.cs
@@ -21,7 +21,7 @@ public RemovePackageAsyncTest(TestWimTemplate template, ITestOutputHelper testOu
public async Task RemovePackageByNameAsyncCancellation()
{
using DismSession session = DismApi.OpenOnlineSession();
- using var cts = new CancellationTokenSource();
+ using CancellationTokenSource cts = new();
cts.Cancel();
bool canceled = false;
@@ -42,7 +42,7 @@ public async Task RemovePackageByNameAsyncCancellation()
public async Task RemovePackageByPathAsyncCancellation()
{
using DismSession session = DismApi.OpenOnlineSession();
- using var cts = new CancellationTokenSource();
+ using CancellationTokenSource cts = new();
cts.Cancel();
bool canceled = false;
@@ -63,9 +63,9 @@ public async Task RemovePackageByPathAsyncCancellation()
public async Task RemovePackageByNameAsyncWithProgress()
{
using DismSession session = DismApi.OpenOnlineSession();
- using var cts = new CancellationTokenSource();
+ using CancellationTokenSource cts = new();
- var progress = new SynchronousProgress(_ =>
+ SynchronousProgress progress = new(_ =>
{
cts.Cancel();
});
diff --git a/src/Microsoft.Dism.Tests/RestoreImageHealthAsyncTest.cs b/src/Microsoft.Dism.Tests/RestoreImageHealthAsyncTest.cs
index a2b0c5d..d162b77 100644
--- a/src/Microsoft.Dism.Tests/RestoreImageHealthAsyncTest.cs
+++ b/src/Microsoft.Dism.Tests/RestoreImageHealthAsyncTest.cs
@@ -21,7 +21,7 @@ public RestoreImageHealthAsyncTest(TestWimTemplate template, ITestOutputHelper t
public async Task RestoreImageHealthAsyncCancellation()
{
using DismSession session = DismApi.OpenOnlineSession();
- using var cts = new CancellationTokenSource();
+ using CancellationTokenSource cts = new();
cts.Cancel();
bool canceled = false;
@@ -42,9 +42,9 @@ public async Task RestoreImageHealthAsyncCancellation()
public async Task RestoreImageHealthAsyncWithProgress()
{
using DismSession session = DismApi.OpenOnlineSession();
- using var cts = new CancellationTokenSource();
+ using CancellationTokenSource cts = new();
- var progress = new SynchronousProgress(_ =>
+ SynchronousProgress progress = new(_ =>
{
cts.Cancel();
});
diff --git a/src/Microsoft.Dism.Tests/SetEditionAsyncTest.cs b/src/Microsoft.Dism.Tests/SetEditionAsyncTest.cs
index 85b8391..02989cb 100644
--- a/src/Microsoft.Dism.Tests/SetEditionAsyncTest.cs
+++ b/src/Microsoft.Dism.Tests/SetEditionAsyncTest.cs
@@ -20,7 +20,7 @@ public SetEditionAsyncTest(TestWimTemplate template, ITestOutputHelper testOutpu
[Fact]
public async Task SetEditionAsyncCancellation()
{
- using var cts = new CancellationTokenSource();
+ using CancellationTokenSource cts = new();
cts.Cancel();
bool canceled = false;
@@ -40,7 +40,7 @@ public async Task SetEditionAsyncCancellation()
[Fact]
public async Task SetEditionAndProductKeyAsyncCancellation()
{
- using var cts = new CancellationTokenSource();
+ using CancellationTokenSource cts = new();
cts.Cancel();
bool canceled = false;
@@ -60,9 +60,9 @@ public async Task SetEditionAndProductKeyAsyncCancellation()
[Fact]
public async Task SetEditionAsyncWithProgress()
{
- using var cts = new CancellationTokenSource();
+ using CancellationTokenSource cts = new();
- var progress = new SynchronousProgress(_ =>
+ SynchronousProgress progress = new(_ =>
{
cts.Cancel();
});
diff --git a/src/Microsoft.Dism.Tests/TestWimTemplate.cs b/src/Microsoft.Dism.Tests/TestWimTemplate.cs
index 88f4bc6..5994188 100644
--- a/src/Microsoft.Dism.Tests/TestWimTemplate.cs
+++ b/src/Microsoft.Dism.Tests/TestWimTemplate.cs
@@ -26,9 +26,9 @@ public class TestWimTemplate : IDisposable
public const string ProductType = "WinNT";
public const int SpLevel = 0;
public const string SystemRoot = "WINDOWS";
- public static readonly CultureInfo DefaultLangauge = new CultureInfo("en-US");
- public static readonly CultureInfo Language = new CultureInfo("en-US");
- public static readonly Version ProductVersion = new Version(6, 3, 9600, 16384);
+ public static readonly CultureInfo DefaultLangauge = new("en-US");
+ public static readonly CultureInfo Language = new("en-US");
+ public static readonly Version ProductVersion = new(6, 3, 9600, 16384);
private const string TestWimTemplateFilename = @"test_template.wim";
@@ -73,7 +73,7 @@ private string CaptureTemplateImage(string capturePath)
throw new DirectoryNotFoundException(string.Format(CultureInfo.CurrentCulture, "Could not find part of the path '{0}'", capturePath));
}
- XmlDocument xmlDocument = new XmlDocument
+ XmlDocument xmlDocument = new()
{
XmlResolver = null,
};
@@ -91,8 +91,8 @@ private string CaptureTemplateImage(string capturePath)
xml.ShouldNotBeNull();
- using (StringReader stringReader = new StringReader(xml.OuterXml))
- using (XmlTextReader reader = new XmlTextReader(stringReader)
+ using (StringReader stringReader = new(xml.OuterXml))
+ using (XmlTextReader reader = new(stringReader)
{
DtdProcessing = DtdProcessing.Prohibit,
})
diff --git a/src/Microsoft.Dism.Tests/UnmountImageAsyncTest.cs b/src/Microsoft.Dism.Tests/UnmountImageAsyncTest.cs
index cca5761..3829b38 100644
--- a/src/Microsoft.Dism.Tests/UnmountImageAsyncTest.cs
+++ b/src/Microsoft.Dism.Tests/UnmountImageAsyncTest.cs
@@ -20,7 +20,7 @@ public UnmountImageAsyncTest(TestWimTemplate template, ITestOutputHelper testOut
[Fact]
public async Task UnmountImageAsyncCancellation()
{
- using var cts = new CancellationTokenSource();
+ using CancellationTokenSource cts = new();
cts.Cancel();
bool canceled = false;
@@ -49,9 +49,9 @@ public async Task UnmountImageAsyncWithProgress()
DismApi.CleanupMountpoints();
DismApi.MountImage(InstallWimPath.FullName, MountPath.FullName, 1);
- using var cts = new CancellationTokenSource();
+ using CancellationTokenSource cts = new();
- var progress = new SynchronousProgress(_ =>
+ SynchronousProgress progress = new(_ =>
{
});
diff --git a/src/Microsoft.Dism/DismApi.AddCapability.cs b/src/Microsoft.Dism/DismApi.AddCapability.cs
index c5949b5..2d897ec 100644
--- a/src/Microsoft.Dism/DismApi.AddCapability.cs
+++ b/src/Microsoft.Dism/DismApi.AddCapability.cs
@@ -55,10 +55,10 @@ public static void AddCapability(DismSession session, string capabilityName, boo
public static void AddCapability(DismSession session, string capabilityName, bool limitAccess, List? sourcePaths, Microsoft.Dism.DismProgressCallback? progressCallback, object? userData)
{
// Get the list of source paths as an array
- string[] sourcePathsArray = sourcePaths?.ToArray() ?? new string[0];
+ string[] sourcePathsArray = sourcePaths?.ToArray() ?? [];
// Create a DismProgress object to wrap the callback and allow cancellation
- DismProgress progress = new DismProgress(progressCallback, userData);
+ DismProgress progress = new(progressCallback, userData);
int hresult = NativeMethods.DismAddCapability(session, capabilityName, limitAccess, sourcePathsArray, (uint)sourcePathsArray.Length, progress.EventHandle, progress.DismProgressCallbackNative, IntPtr.Zero);
@@ -81,18 +81,18 @@ public static void AddCapability(DismSession session, string capabilityName, boo
/// When the operation requires a reboot to complete.
public static Task AddCapabilityAsync(DismSession session, string capabilityName, bool limitAccess, List? sourcePaths, IProgress? progress = null, CancellationToken cancellationToken = default)
{
- var tcs = new TaskCompletionSource();
+ TaskCompletionSource tcs = new();
- var ctsRegistration = default(CancellationTokenRegistration);
+ CancellationTokenRegistration ctsRegistration = default;
Task.Factory.StartNew(
() =>
{
try
{
- string[] sourcePathsArray = sourcePaths?.ToArray() ?? new string[0];
+ string[] sourcePathsArray = sourcePaths?.ToArray() ?? [];
- var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
+ DismProgress dismProgress = new(progress != null ? p => progress.Report(p) : null, null);
ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
diff --git a/src/Microsoft.Dism/DismApi.AddPackage.cs b/src/Microsoft.Dism/DismApi.AddPackage.cs
index 5d2f01a..d952236 100644
--- a/src/Microsoft.Dism/DismApi.AddPackage.cs
+++ b/src/Microsoft.Dism/DismApi.AddPackage.cs
@@ -60,7 +60,7 @@ public static void AddPackage(DismSession session, string packagePath, bool igno
public static void AddPackage(DismSession session, string packagePath, bool ignoreCheck, bool preventPending, Microsoft.Dism.DismProgressCallback? progressCallback, object? userData)
{
// Create a DismProgress object to wrap the callback and allow cancellation
- DismProgress progress = new DismProgress(progressCallback, userData);
+ DismProgress progress = new(progressCallback, userData);
int hresult = NativeMethods.DismAddPackage(session, packagePath, ignoreCheck, preventPending, progress.EventHandle, progress.DismProgressCallbackNative, IntPtr.Zero);
@@ -84,16 +84,16 @@ public static void AddPackage(DismSession session, string packagePath, bool igno
/// When the package is not applicable to the specified session.
public static Task AddPackageAsync(DismSession session, string packagePath, bool ignoreCheck, bool preventPending, IProgress? progress = null, CancellationToken cancellationToken = default)
{
- var tcs = new TaskCompletionSource();
+ TaskCompletionSource tcs = new();
- var ctsRegistration = default(CancellationTokenRegistration);
+ CancellationTokenRegistration ctsRegistration = default;
Task.Factory.StartNew(
() =>
{
try
{
- var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
+ DismProgress dismProgress = new(progress != null ? p => progress.Report(p) : null, null);
ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
diff --git a/src/Microsoft.Dism/DismApi.AddProvisionedAppxPackage.cs b/src/Microsoft.Dism/DismApi.AddProvisionedAppxPackage.cs
index 25129bc..ecf1321 100644
--- a/src/Microsoft.Dism/DismApi.AddProvisionedAppxPackage.cs
+++ b/src/Microsoft.Dism/DismApi.AddProvisionedAppxPackage.cs
@@ -72,11 +72,11 @@ public static void AddProvisionedAppxPackage(DismSession session, string appPath
int hresult = NativeMethods._DismAddProvisionedAppxPackage(
session,
appPath,
- dependencyPackages?.ToArray() ?? new string[0],
+ dependencyPackages?.ToArray() ?? [],
(uint)(dependencyPackages?.Count ?? 0),
- optionalPackages?.ToArray() ?? new string[0],
+ optionalPackages?.ToArray() ?? [],
(uint)(optionalPackages?.Count ?? 0),
- licensePaths?.ToArray() ?? new string[0],
+ licensePaths?.ToArray() ?? [],
(uint)(licensePaths?.Count ?? 0),
SkipLicense: licensePaths == null || licensePaths.Count == 0,
customDataPath,
diff --git a/src/Microsoft.Dism/DismApi.CheckImageHealth.cs b/src/Microsoft.Dism/DismApi.CheckImageHealth.cs
index 5622326..f1ed48f 100644
--- a/src/Microsoft.Dism/DismApi.CheckImageHealth.cs
+++ b/src/Microsoft.Dism/DismApi.CheckImageHealth.cs
@@ -51,7 +51,7 @@ public static DismImageHealthState CheckImageHealth(DismSession session, bool sc
public static DismImageHealthState CheckImageHealth(DismSession session, bool scanImage, Microsoft.Dism.DismProgressCallback? progressCallback, object? userData)
{
// Create a DismProgress object to wrap the callback and allow cancellation
- DismProgress progress = new DismProgress(progressCallback, userData);
+ DismProgress progress = new(progressCallback, userData);
int hresult = NativeMethods.DismCheckImageHealth(session, scanImage, progress.EventHandle, progress.DismProgressCallbackNative, IntPtr.Zero, out DismImageHealthState imageHealthState);
@@ -73,16 +73,16 @@ public static DismImageHealthState CheckImageHealth(DismSession session, bool sc
/// When the operation is canceled.
public static Task CheckImageHealthAsync(DismSession session, bool scanImage, IProgress? progress = null, CancellationToken cancellationToken = default)
{
- var tcs = new TaskCompletionSource();
+ TaskCompletionSource tcs = new();
- var ctsRegistration = default(CancellationTokenRegistration);
+ CancellationTokenRegistration ctsRegistration = default;
Task.Factory.StartNew(
() =>
{
try
{
- var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
+ DismProgress dismProgress = new(progress != null ? p => progress.Report(p) : null, null);
ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
diff --git a/src/Microsoft.Dism/DismApi.CommitImage.cs b/src/Microsoft.Dism/DismApi.CommitImage.cs
index 0fb6bbc..37d79fa 100644
--- a/src/Microsoft.Dism/DismApi.CommitImage.cs
+++ b/src/Microsoft.Dism/DismApi.CommitImage.cs
@@ -51,7 +51,7 @@ public static void CommitImage(DismSession session, bool discardChanges, Microso
UInt32 flags = discardChanges ? DISM_DISCARD_IMAGE : DISM_COMMIT_IMAGE;
// Create a DismProgress object to wrap the callback and allow cancellation
- DismProgress progress = new DismProgress(progressCallback, userData);
+ DismProgress progress = new(progressCallback, userData);
int hresult = NativeMethods.DismCommitImage(session, flags, progress.EventHandle, progress.DismProgressCallbackNative, IntPtr.Zero);
@@ -71,9 +71,9 @@ public static void CommitImage(DismSession session, bool discardChanges, Microso
/// When the operation is canceled.
public static Task CommitImageAsync(DismSession session, bool discardChanges, IProgress? progress = null, CancellationToken cancellationToken = default)
{
- var tcs = new TaskCompletionSource();
+ TaskCompletionSource tcs = new();
- var ctsRegistration = default(CancellationTokenRegistration);
+ CancellationTokenRegistration ctsRegistration = default;
Task.Factory.StartNew(
() =>
@@ -82,7 +82,7 @@ public static Task CommitImageAsync(DismSession session, bool discardChanges, IP
{
UInt32 flags = discardChanges ? DISM_DISCARD_IMAGE : DISM_COMMIT_IMAGE;
- var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
+ DismProgress dismProgress = new(progress != null ? p => progress.Report(p) : null, null);
ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
diff --git a/src/Microsoft.Dism/DismApi.DisableFeature.cs b/src/Microsoft.Dism/DismApi.DisableFeature.cs
index bf1f86b..e25a0ce 100644
--- a/src/Microsoft.Dism/DismApi.DisableFeature.cs
+++ b/src/Microsoft.Dism/DismApi.DisableFeature.cs
@@ -63,7 +63,7 @@ public static void DisableFeature(DismSession session, string featureName, strin
public static void DisableFeature(DismSession session, string featureName, string packageName, bool removePayload, Microsoft.Dism.DismProgressCallback? progressCallback, object? userData)
{
// Create a DismProgress object to wrap the callback and allow cancellation
- DismProgress progress = new DismProgress(progressCallback, userData);
+ DismProgress progress = new(progressCallback, userData);
int hresult = NativeMethods.DismDisableFeature(session, featureName, packageName, removePayload, progress.EventHandle, progress.DismProgressCallbackNative, IntPtr.Zero);
@@ -88,16 +88,16 @@ public static void DisableFeature(DismSession session, string featureName, strin
/// When the operation requires a reboot to complete.
public static Task DisableFeatureAsync(DismSession session, string featureName, string packageName, bool removePayload, IProgress? progress = null, CancellationToken cancellationToken = default)
{
- var tcs = new TaskCompletionSource();
+ TaskCompletionSource tcs = new();
- var ctsRegistration = default(CancellationTokenRegistration);
+ CancellationTokenRegistration ctsRegistration = default;
Task.Factory.StartNew(
() =>
{
try
{
- var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
+ DismProgress dismProgress = new(progress != null ? p => progress.Report(p) : null, null);
ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
diff --git a/src/Microsoft.Dism/DismApi.EnableFeature.cs b/src/Microsoft.Dism/DismApi.EnableFeature.cs
index d2652e8..bfb9e9b 100644
--- a/src/Microsoft.Dism/DismApi.EnableFeature.cs
+++ b/src/Microsoft.Dism/DismApi.EnableFeature.cs
@@ -272,18 +272,18 @@ public static Task EnableFeatureByPackagePathAsync(DismSession session, string f
///
private static Task EnableFeatureAsync(DismSession session, string featureName, string? identifier, DismPackageIdentifier packageIdentifier, bool limitAccess, bool enableAll, List? sourcePaths, IProgress? progress, CancellationToken cancellationToken)
{
- var tcs = new TaskCompletionSource();
+ TaskCompletionSource tcs = new();
- var ctsRegistration = default(CancellationTokenRegistration);
+ CancellationTokenRegistration ctsRegistration = default;
Task.Factory.StartNew(
() =>
{
try
{
- string[] sourcePathsArray = sourcePaths?.ToArray() ?? new string[0];
+ string[] sourcePathsArray = sourcePaths?.ToArray() ?? [];
- var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
+ DismProgress dismProgress = new(progress != null ? p => progress.Report(p) : null, null);
ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
@@ -336,10 +336,10 @@ private static Task EnableFeatureAsync(DismSession session, string featureName,
private static void EnableFeature(DismSession session, string featureName, string? identifier, DismPackageIdentifier packageIdentifier, bool limitAccess, bool enableAll, List? sourcePaths, Microsoft.Dism.DismProgressCallback? progressCallback, object? userData)
{
// Get the list of source paths as an array
- string[] sourcePathsArray = sourcePaths?.ToArray() ?? new string[0];
+ string[] sourcePathsArray = sourcePaths?.ToArray() ?? [];
// Create a DismProgress object to wrap the callback and allow cancellation
- DismProgress progress = new DismProgress(progressCallback, userData);
+ DismProgress progress = new(progressCallback, userData);
int hresult = NativeMethods.DismEnableFeature(
session: session,
diff --git a/src/Microsoft.Dism/DismApi.Initialize.cs b/src/Microsoft.Dism/DismApi.Initialize.cs
index 942395f..4bea113 100644
--- a/src/Microsoft.Dism/DismApi.Initialize.cs
+++ b/src/Microsoft.Dism/DismApi.Initialize.cs
@@ -11,7 +11,7 @@ public static partial class DismApi
///
/// Used to lock when initializing or shutting down.
///
- private static readonly object InitializeShutDownLock = new object();
+ private static readonly object InitializeShutDownLock = new();
///
/// Used to keep track if DismApi has been initialized.
diff --git a/src/Microsoft.Dism/DismApi.MountImage.cs b/src/Microsoft.Dism/DismApi.MountImage.cs
index d11adf4..5504873 100644
--- a/src/Microsoft.Dism/DismApi.MountImage.cs
+++ b/src/Microsoft.Dism/DismApi.MountImage.cs
@@ -260,9 +260,9 @@ public static Task MountImageAsync(string imageFilePath, string mountPath, strin
///
private static Task MountImageAsync(string imageFilePath, string mountPath, int imageIndex, string? imageName, DismImageIdentifier imageIdentifier, bool readOnly, DismMountImageOptions options, IProgress? progress, CancellationToken cancellationToken)
{
- var tcs = new TaskCompletionSource();
+ TaskCompletionSource tcs = new();
- var ctsRegistration = default(CancellationTokenRegistration);
+ CancellationTokenRegistration ctsRegistration = default;
Task.Factory.StartNew(
() =>
@@ -271,7 +271,7 @@ private static Task MountImageAsync(string imageFilePath, string mountPath, int
{
uint flags = (readOnly ? DISM_MOUNT_READONLY : DISM_MOUNT_READWRITE) | (uint)options;
- var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
+ DismProgress dismProgress = new(progress != null ? p => progress.Report(p) : null, null);
ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
@@ -326,7 +326,7 @@ private static void MountImage(string imageFilePath, string mountPath, int image
uint flags = (readOnly ? DISM_MOUNT_READONLY : DISM_MOUNT_READWRITE) | (uint)options;
// Create a DismProgress object to wrap the callback and allow cancellation
- DismProgress progress = new DismProgress(progressCallback, userData);
+ DismProgress progress = new(progressCallback, userData);
int hresult = NativeMethods.DismMountImage(imageFilePath, mountPath, (uint)imageIndex, imageName, imageIdentifier, flags, progress.EventHandle, progress.DismProgressCallbackNative, IntPtr.Zero);
diff --git a/src/Microsoft.Dism/DismApi.RemoveCapability.cs b/src/Microsoft.Dism/DismApi.RemoveCapability.cs
index 731e059..ae97d4c 100644
--- a/src/Microsoft.Dism/DismApi.RemoveCapability.cs
+++ b/src/Microsoft.Dism/DismApi.RemoveCapability.cs
@@ -37,7 +37,7 @@ public static void RemoveCapability(DismSession session, string capabilityName)
public static void RemoveCapability(DismSession session, string capabilityName, Dism.DismProgressCallback? progressCallback, object? userData)
{
// Create a DismProgress object to wrap the callback and allow cancellation
- DismProgress progress = new DismProgress(progressCallback, userData);
+ DismProgress progress = new(progressCallback, userData);
int hresult = NativeMethods.DismRemoveCapability(session, capabilityName, progress.EventHandle, progress.DismProgressCallbackNative, IntPtr.Zero);
@@ -58,16 +58,16 @@ public static void RemoveCapability(DismSession session, string capabilityName,
/// When the operation requires a reboot to complete.
public static Task RemoveCapabilityAsync(DismSession session, string capabilityName, IProgress? progress = null, CancellationToken cancellationToken = default)
{
- var tcs = new TaskCompletionSource();
+ TaskCompletionSource tcs = new();
- var ctsRegistration = default(CancellationTokenRegistration);
+ CancellationTokenRegistration ctsRegistration = default;
Task.Factory.StartNew(
() =>
{
try
{
- var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
+ DismProgress dismProgress = new(progress != null ? p => progress.Report(p) : null, null);
ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
diff --git a/src/Microsoft.Dism/DismApi.RemovePackage.cs b/src/Microsoft.Dism/DismApi.RemovePackage.cs
index fa998c9..6f71699 100644
--- a/src/Microsoft.Dism/DismApi.RemovePackage.cs
+++ b/src/Microsoft.Dism/DismApi.RemovePackage.cs
@@ -132,16 +132,16 @@ public static Task RemovePackageByPathAsync(DismSession session, string packageP
///
private static Task RemovePackageAsync(DismSession session, string identifier, DismPackageIdentifier packageIdentifier, IProgress? progress, CancellationToken cancellationToken)
{
- var tcs = new TaskCompletionSource();
+ TaskCompletionSource tcs = new();
- var ctsRegistration = default(CancellationTokenRegistration);
+ CancellationTokenRegistration ctsRegistration = default;
Task.Factory.StartNew(
() =>
{
try
{
- var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
+ DismProgress dismProgress = new(progress != null ? p => progress.Report(p) : null, null);
ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
@@ -189,7 +189,7 @@ private static Task RemovePackageAsync(DismSession session, string identifier, D
private static void RemovePackage(DismSession session, string identifier, DismPackageIdentifier packageIdentifier, Dism.DismProgressCallback? progressCallback, object? userData)
{
// Create a DismProgress object to wrap the callback and allow cancellation
- DismProgress progress = new DismProgress(progressCallback, userData);
+ DismProgress progress = new(progressCallback, userData);
int hresult = NativeMethods.DismRemovePackage(session, identifier, packageIdentifier, progress.EventHandle, progress.DismProgressCallbackNative, IntPtr.Zero);
diff --git a/src/Microsoft.Dism/DismApi.RestoreImageHealth.cs b/src/Microsoft.Dism/DismApi.RestoreImageHealth.cs
index e7501ae..7f350fa 100644
--- a/src/Microsoft.Dism/DismApi.RestoreImageHealth.cs
+++ b/src/Microsoft.Dism/DismApi.RestoreImageHealth.cs
@@ -67,10 +67,10 @@ public static void RestoreImageHealth(DismSession session, bool limitAccess, Lis
public static void RestoreImageHealth(DismSession session, bool limitAccess, List? sourcePaths, Dism.DismProgressCallback? progressCallback, object? userData)
{
// Get the list of source paths as an array
- string[] sourcePathsArray = sourcePaths?.ToArray() ?? new string[0];
+ string[] sourcePathsArray = sourcePaths?.ToArray() ?? [];
// Create a DismProgress object to wrap the callback and allow cancellation
- DismProgress progress = new DismProgress(progressCallback, userData);
+ DismProgress progress = new(progressCallback, userData);
int hresult = NativeMethods.DismRestoreImageHealth(session, sourcePathsArray, (uint)sourcePathsArray.Length, limitAccess, progress.EventHandle, progress.DismProgressCallbackNative, IntPtr.Zero);
@@ -92,18 +92,18 @@ public static void RestoreImageHealth(DismSession session, bool limitAccess, Lis
/// When the operation requires a reboot to complete.
public static Task RestoreImageHealthAsync(DismSession session, bool limitAccess, List? sourcePaths = null, IProgress? progress = null, CancellationToken cancellationToken = default)
{
- var tcs = new TaskCompletionSource();
+ TaskCompletionSource tcs = new();
- var ctsRegistration = default(CancellationTokenRegistration);
+ CancellationTokenRegistration ctsRegistration = default;
Task.Factory.StartNew(
() =>
{
try
{
- string[] sourcePathsArray = sourcePaths?.ToArray() ?? new string[0];
+ string[] sourcePathsArray = sourcePaths?.ToArray() ?? [];
- var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
+ DismProgress dismProgress = new(progress != null ? p => progress.Report(p) : null, null);
ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
diff --git a/src/Microsoft.Dism/DismApi.SetEdition.cs b/src/Microsoft.Dism/DismApi.SetEdition.cs
index e60d09c..b8d73f8 100644
--- a/src/Microsoft.Dism/DismApi.SetEdition.cs
+++ b/src/Microsoft.Dism/DismApi.SetEdition.cs
@@ -132,16 +132,16 @@ public static Task SetEditionAndProductKeyAsync(DismSession session, string edit
///
private static Task SetEditionAsync(DismSession session, string editionId, string? productKey, IProgress? progress, CancellationToken cancellationToken)
{
- var tcs = new TaskCompletionSource();
+ TaskCompletionSource tcs = new();
- var ctsRegistration = default(CancellationTokenRegistration);
+ CancellationTokenRegistration ctsRegistration = default;
Task.Factory.StartNew(
() =>
{
try
{
- var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
+ DismProgress dismProgress = new(progress != null ? p => progress.Report(p) : null, null);
ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
@@ -191,7 +191,7 @@ private static Task SetEditionAsync(DismSession session, string editionId, strin
private static void SetEdition(DismSession session, string editionId, string? productKey, Dism.DismProgressCallback? progressCallback, object? userData)
{
// Create a DismProgress object to wrap the callback and allow cancellation
- DismProgress progress = new DismProgress(progressCallback, userData);
+ DismProgress progress = new(progressCallback, userData);
int hresult = NativeMethods.DismSetEdition(session, editionId, productKey, progress.EventHandle, progress.DismProgressCallbackNative, IntPtr.Zero);
diff --git a/src/Microsoft.Dism/DismApi.UnmountImage.cs b/src/Microsoft.Dism/DismApi.UnmountImage.cs
index 2a86b41..7331b5d 100644
--- a/src/Microsoft.Dism/DismApi.UnmountImage.cs
+++ b/src/Microsoft.Dism/DismApi.UnmountImage.cs
@@ -51,7 +51,7 @@ public static void UnmountImage(string mountPath, bool commitChanges, Dism.DismP
uint flags = commitChanges ? DISM_COMMIT_IMAGE : DISM_DISCARD_IMAGE;
// Create a DismProgress object to wrap the callback and allow cancellation
- DismProgress progress = new DismProgress(progressCallback, userData);
+ DismProgress progress = new(progressCallback, userData);
int hresult = NativeMethods.DismUnmountImage(mountPath, flags, progress.EventHandle, progress.DismProgressCallbackNative, IntPtr.Zero);
@@ -71,9 +71,9 @@ public static void UnmountImage(string mountPath, bool commitChanges, Dism.DismP
/// When the operation is canceled.
public static Task UnmountImageAsync(string mountPath, bool commitChanges, IProgress? progress = null, CancellationToken cancellationToken = default)
{
- var tcs = new TaskCompletionSource();
+ TaskCompletionSource tcs = new();
- var ctsRegistration = default(CancellationTokenRegistration);
+ CancellationTokenRegistration ctsRegistration = default;
Task.Factory.StartNew(
() =>
@@ -82,7 +82,7 @@ public static Task UnmountImageAsync(string mountPath, bool commitChanges, IProg
{
uint flags = commitChanges ? DISM_COMMIT_IMAGE : DISM_DISCARD_IMAGE;
- var dismProgress = new DismProgress(progress != null ? p => progress.Report(p) : null, null);
+ DismProgress dismProgress = new(progress != null ? p => progress.Report(p) : null, null);
ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
diff --git a/src/Microsoft.Dism/DismUtilities.cs b/src/Microsoft.Dism/DismUtilities.cs
index 6608c5c..29bbd4d 100644
--- a/src/Microsoft.Dism/DismUtilities.cs
+++ b/src/Microsoft.Dism/DismUtilities.cs
@@ -147,7 +147,7 @@ public static string? WAIKDISMAPIPath
return null;
}
- FileInfo dismPath = new FileInfo(Path.Combine(servicingPath, "dism.exe"));
+ FileInfo dismPath = new(Path.Combine(servicingPath, "dism.exe"));
return dismPath.Exists ? dismPath.FullName : null;
}
@@ -290,7 +290,7 @@ internal static void ThrowIfFail(int hresult, DismSession? session = null, [Call
return null;
}
- FileInfo dismPath = new FileInfo(Path.Combine(kitsRoot, "Assessment and Deployment Kit", "Deployment Tools", Environment.Is64BitProcess ? "amd64" : "x86", "DISM", "dismapi.dll"));
+ FileInfo dismPath = new(Path.Combine(kitsRoot, "Assessment and Deployment Kit", "Deployment Tools", Environment.Is64BitProcess ? "amd64" : "x86", "DISM", "dismapi.dll"));
return dismPath.Exists ? dismPath.FullName : null;
}
diff --git a/src/Microsoft.Dism/ExtensionMethods.cs b/src/Microsoft.Dism/ExtensionMethods.cs
index 381ca23..6933e18 100644
--- a/src/Microsoft.Dism/ExtensionMethods.cs
+++ b/src/Microsoft.Dism/ExtensionMethods.cs
@@ -33,7 +33,7 @@ public static List ToList(this IntPtr ptr, uint count, Func list = new List((int)count);
+ List list = new((int)count);
if (ptr != IntPtr.Zero && count > 0)
{
@@ -48,7 +48,7 @@ public static List ToList(this IntPtr ptr, uint count, Func();
diff --git a/stylecop.json b/stylecop.json
deleted file mode 100644
index 3e69aeb..0000000
--- a/stylecop.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
- "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
- "settings": {
- "orderingRules": {
- "usingDirectivesPlacement": "outsideNamespace",
- "systemUsingDirectivesFirst": false,
- "blankLinesBetweenUsingGroups": "require",
-
- },
- "documentationRules": {
- "companyName": "",
- "copyrightText": "Copyright (c). All rights reserved.\n\nLicensed under the MIT license.",
- "xmlHeader": false
- }
- }
-}
\ No newline at end of file
From 2c2c360394f047122ff4a1499d4efe105ebf379e Mon Sep 17 00:00:00 2001
From: Jeff Kluge
Date: Tue, 14 Apr 2026 17:37:40 -0700
Subject: [PATCH 10/10] step
---
.editorconfig | 6 +-
Directory.Build.targets | 2 +-
.../AddCapabilityAsyncTest.cs | 83 ----
.../AddPackageAsyncTest.cs | 83 ----
.../CheckImageHealthAsyncTest.cs | 98 -----
.../CheckImageHealthTest.cs | 67 ++-
.../CommitImageAsyncTest.cs | 83 ----
.../DisableFeatureAsyncTest.cs | 83 ----
.../EnableFeatureAsyncTest.cs | 125 ------
.../GetCurrentEditionTests.cs | 2 +-
.../Microsoft.Dism.Tests.csproj | 2 +-
.../MountImageAsyncTest.cs | 142 -------
src/Microsoft.Dism.Tests/MountImageTest.cs | 92 +++++
.../RemoveCapabilityAsyncTest.cs | 83 ----
.../RemovePackageAsyncTest.cs | 104 -----
.../RestoreImageHealthAsyncTest.cs | 79 ----
.../SetEditionAsyncTest.cs | 101 -----
src/Microsoft.Dism.Tests/TestWimTemplate.cs | 4 +-
.../UnmountImageAsyncTest.cs | 109 -----
.../CallerMemberNameAttribute.cs | 16 -
src/Microsoft.Dism/DismApi.AddCapability.cs | 132 +++---
src/Microsoft.Dism/DismApi.AddDriver.cs | 14 +-
src/Microsoft.Dism/DismApi.AddPackage.cs | 130 +++---
.../DismApi.AddProvisionedAppxPackage.cs | 29 +-
src/Microsoft.Dism/DismApi.ApplyFfuImage.cs | 12 +-
src/Microsoft.Dism/DismApi.ApplyUnattend.cs | 12 +-
.../DismApi.CheckImageHealth.cs | 122 +++---
.../DismApi.CleanupMountpoints.cs | 9 +-
src/Microsoft.Dism/DismApi.CloseSession.cs | 10 +-
src/Microsoft.Dism/DismApi.CommitImage.cs | 136 +++---
src/Microsoft.Dism/DismApi.Delete.cs | 10 +-
src/Microsoft.Dism/DismApi.DisableFeature.cs | 166 +++++---
src/Microsoft.Dism/DismApi.EnableFeature.cs | 387 ++++++++++++------
src/Microsoft.Dism/DismApi.GetCapabilities.cs | 12 +-
.../DismApi.GetCapabilityInfo.cs | 12 +-
.../DismApi.GetCurrentEdition.cs | 11 +-
src/Microsoft.Dism/DismApi.GetDriverInfo.cs | 14 +-
src/Microsoft.Dism/DismApi.GetDrivers.cs | 15 +-
src/Microsoft.Dism/DismApi.GetFeatureInfo.cs | 14 +-
.../DismApi.GetFeatureParent.cs | 15 +-
src/Microsoft.Dism/DismApi.GetFeatures.cs | 14 +-
src/Microsoft.Dism/DismApi.GetImageInfo.cs | 12 +-
.../DismApi.GetLastErrorMessage.cs | 10 +-
.../DismApi.GetMountedImages.cs | 11 +-
src/Microsoft.Dism/DismApi.GetPackageInfo.cs | 13 +-
.../DismApi.GetPackageInfoEx.cs | 13 +-
src/Microsoft.Dism/DismApi.GetPackages.cs | 12 +-
.../DismApi.GetProductKeyInfo.cs | 13 +-
.../DismApi.GetProvisionedAppxPackages.cs | 12 +-
.../DismApi.GetRegistryMountPoint.cs | 12 +-
.../DismApi.GetTargetEditions.cs | 12 +-
src/Microsoft.Dism/DismApi.Initialize.cs | 12 +-
src/Microsoft.Dism/DismApi.MountImage.cs | 248 +++++++----
src/Microsoft.Dism/DismApi.OpenSession.cs | 13 +-
src/Microsoft.Dism/DismApi.RemountImage.cs | 10 +-
.../DismApi.RemoveCapability.cs | 135 +++---
src/Microsoft.Dism/DismApi.RemovePackage.cs | 175 +++++---
.../DismApi.RemoveProvisionedAppxPackage.cs | 11 +-
.../DismApi.RestoreImageHealth.cs | 144 ++++---
src/Microsoft.Dism/DismApi.SetEdition.cs | 175 ++++----
src/Microsoft.Dism/DismApi.SetProductKey.cs | 11 +-
src/Microsoft.Dism/DismApi.SplitFfuImage.cs | 12 +-
src/Microsoft.Dism/DismApi.UnmountImage.cs | 126 +++---
.../DismApi.ValidateProductKey.cs | 11 +-
src/Microsoft.Dism/DismCustomProperty.cs | 2 +-
src/Microsoft.Dism/DismProgress.cs | 10 +
src/Microsoft.Dism/DismProgressCallback.cs | 2 +-
src/Microsoft.Dism/DismUtilities.cs | 39 ++
src/Microsoft.Dism/GlobalSuppressions.cs | 61 ++-
src/Microsoft.Dism/Microsoft.Dism.csproj | 4 +-
src/Microsoft.Dism/PublicAPI.Unshipped.txt | 75 +++-
src/Microsoft.Dism/SystemTime.cs | 4 +-
72 files changed, 1841 insertions(+), 2199 deletions(-)
delete mode 100644 src/Microsoft.Dism.Tests/AddCapabilityAsyncTest.cs
delete mode 100644 src/Microsoft.Dism.Tests/AddPackageAsyncTest.cs
delete mode 100644 src/Microsoft.Dism.Tests/CheckImageHealthAsyncTest.cs
delete mode 100644 src/Microsoft.Dism.Tests/CommitImageAsyncTest.cs
delete mode 100644 src/Microsoft.Dism.Tests/DisableFeatureAsyncTest.cs
delete mode 100644 src/Microsoft.Dism.Tests/EnableFeatureAsyncTest.cs
delete mode 100644 src/Microsoft.Dism.Tests/MountImageAsyncTest.cs
create mode 100644 src/Microsoft.Dism.Tests/MountImageTest.cs
delete mode 100644 src/Microsoft.Dism.Tests/RemoveCapabilityAsyncTest.cs
delete mode 100644 src/Microsoft.Dism.Tests/RemovePackageAsyncTest.cs
delete mode 100644 src/Microsoft.Dism.Tests/RestoreImageHealthAsyncTest.cs
delete mode 100644 src/Microsoft.Dism.Tests/SetEditionAsyncTest.cs
delete mode 100644 src/Microsoft.Dism.Tests/UnmountImageAsyncTest.cs
delete mode 100644 src/Microsoft.Dism/CallerMemberNameAttribute.cs
diff --git a/.editorconfig b/.editorconfig
index 0cc0bb0..47bb059 100644
--- a/.editorconfig
+++ b/.editorconfig
@@ -1,11 +1,11 @@
root = true
[*.cs]
-csharp_using_directive_placement = outside_namespace:silent
+csharp_using_directive_placement = outside_namespace:error
dotnet_sort_system_directives_first = false
-dotnet_separate_import_directive_groups = true
+dotnet_separate_import_directive_groups = false
file_header_template = Copyright (c). All rights reserved.\n\nLicensed under the MIT license.
-csharp_prefer_simple_using_statement = true:suggestion
+csharp_prefer_simple_using_statement = true:error
csharp_prefer_braces = true:silent
csharp_style_namespace_declarations = block_scoped:silent
csharp_style_prefer_method_group_conversion = true:silent
diff --git a/Directory.Build.targets b/Directory.Build.targets
index 76a4afd..47169ae 100644
--- a/Directory.Build.targets
+++ b/Directory.Build.targets
@@ -9,7 +9,7 @@
Git
true
- Full
+ Full
true
All
Low
diff --git a/src/Microsoft.Dism.Tests/AddCapabilityAsyncTest.cs b/src/Microsoft.Dism.Tests/AddCapabilityAsyncTest.cs
deleted file mode 100644
index 7b25e51..0000000
--- a/src/Microsoft.Dism.Tests/AddCapabilityAsyncTest.cs
+++ /dev/null
@@ -1,83 +0,0 @@
-// Copyright (c). All rights reserved.
-//
-// Licensed under the MIT license.
-#if !NETFRAMEWORK
-using Shouldly;
-using System;
-using System.Threading;
-using System.Threading.Tasks;
-using Xunit;
-
-namespace Microsoft.Dism.Tests
-{
- public class AddCapabilityAsyncTest : DismTestBase
- {
- public AddCapabilityAsyncTest(TestWimTemplate template, ITestOutputHelper testOutput)
- : base(template, testOutput)
- {
- }
-
- [Fact]
- public async Task AddCapabilityAsyncCancellation()
- {
- using DismSession session = DismApi.OpenOnlineSession();
- using CancellationTokenSource cts = new();
- cts.Cancel();
-
- bool canceled = false;
-
- try
- {
- await DismApi.AddCapabilityAsync(session, "FakeCapability", limitAccess: true, sourcePaths: null, cancellationToken: cts.Token);
- }
- catch (OperationCanceledException)
- {
- canceled = true;
- }
-
- canceled.ShouldBeTrue();
- }
-
- [Fact]
- public async Task AddCapabilityAsyncWithProgress()
- {
- using DismSession session = DismApi.OpenOnlineSession();
- using CancellationTokenSource cts = new();
-
- SynchronousProgress progress = new(_ =>
- {
- cts.Cancel();
- });
-
- try
- {
- await DismApi.AddCapabilityAsync(session, "FakeCapability", limitAccess: true, sourcePaths: null, progress: progress, cancellationToken: cts.Token);
- }
- catch (OperationCanceledException)
- {
- }
- catch (DismException)
- {
- // Expected when the capability does not exist
- }
-
- // Progress may not be called for an invalid capability, so we just verify no hang occurred
- }
-
- private sealed class SynchronousProgress : IProgress
- {
- private readonly Action _handler;
-
- public SynchronousProgress(Action handler)
- {
- _handler = handler;
- }
-
- public void Report(T value)
- {
- _handler(value);
- }
- }
- }
-}
-#endif
diff --git a/src/Microsoft.Dism.Tests/AddPackageAsyncTest.cs b/src/Microsoft.Dism.Tests/AddPackageAsyncTest.cs
deleted file mode 100644
index 2ba5849..0000000
--- a/src/Microsoft.Dism.Tests/AddPackageAsyncTest.cs
+++ /dev/null
@@ -1,83 +0,0 @@
-// Copyright (c). All rights reserved.
-//
-// Licensed under the MIT license.
-#if !NETFRAMEWORK
-using Shouldly;
-using System;
-using System.Threading;
-using System.Threading.Tasks;
-using Xunit;
-
-namespace Microsoft.Dism.Tests
-{
- public class AddPackageAsyncTest : DismTestBase
- {
- public AddPackageAsyncTest(TestWimTemplate template, ITestOutputHelper testOutput)
- : base(template, testOutput)
- {
- }
-
- [Fact]
- public async Task AddPackageAsyncCancellation()
- {
- using DismSession session = DismApi.OpenOnlineSession();
- using CancellationTokenSource cts = new();
- cts.Cancel();
-
- bool canceled = false;
-
- try
- {
- await DismApi.AddPackageAsync(session, "nonexistent.cab", ignoreCheck: false, preventPending: false, cancellationToken: cts.Token);
- }
- catch (OperationCanceledException)
- {
- canceled = true;
- }
-
- canceled.ShouldBeTrue();
- }
-
- [Fact]
- public async Task AddPackageAsyncWithProgress()
- {
- using DismSession session = DismApi.OpenOnlineSession();
- using CancellationTokenSource cts = new();
-
- SynchronousProgress progress = new(_ =>
- {
- cts.Cancel();
- });
-
- try
- {
- await DismApi.AddPackageAsync(session, "nonexistent.cab", ignoreCheck: false, preventPending: false, progress: progress, cancellationToken: cts.Token);
- }
- catch (OperationCanceledException)
- {
- }
- catch (DismException)
- {
- // Expected when the package does not exist
- }
-
- // Progress may not be called for an invalid package, so we just verify no hang occurred
- }
-
- private sealed class SynchronousProgress : IProgress
- {
- private readonly Action _handler;
-
- public SynchronousProgress(Action handler)
- {
- _handler = handler;
- }
-
- public void Report(T value)
- {
- _handler(value);
- }
- }
- }
-}
-#endif
diff --git a/src/Microsoft.Dism.Tests/CheckImageHealthAsyncTest.cs b/src/Microsoft.Dism.Tests/CheckImageHealthAsyncTest.cs
deleted file mode 100644
index 3ab2211..0000000
--- a/src/Microsoft.Dism.Tests/CheckImageHealthAsyncTest.cs
+++ /dev/null
@@ -1,98 +0,0 @@
-// Copyright (c). All rights reserved.
-//
-// Licensed under the MIT license.
-
-#if !NETFRAMEWORK
-using Shouldly;
-using System;
-using System.Threading;
-using System.Threading.Tasks;
-using Xunit;
-
-namespace Microsoft.Dism.Tests
-{
- public class CheckImageHealthAsyncTest : DismTestBase
- {
- public CheckImageHealthAsyncTest(TestWimTemplate template, ITestOutputHelper testOutput)
- : base(template, testOutput)
- {
- }
-
- [Fact]
- public async Task CheckImageHealthAsyncOnlineSession()
- {
- using DismSession session = DismApi.OpenOnlineSession();
-
- DismImageHealthState imageHealthState = await DismApi.CheckImageHealthAsync(session, scanImage: false, cancellationToken: TestContext.Current.CancellationToken);
-
- imageHealthState.ShouldBe(DismImageHealthState.Healthy);
- }
-
- [Fact]
- public async Task CheckImageHealthAsyncCancellation()
- {
- using DismSession session = DismApi.OpenOnlineSession();
- using CancellationTokenSource cts = new();
- cts.Cancel();
-
- bool canceled = false;
-
- try
- {
- await DismApi.CheckImageHealthAsync(session, scanImage: false, cancellationToken: cts.Token);
- }
- catch (OperationCanceledException)
- {
- canceled = true;
- }
-
- canceled.ShouldBeTrue();
- }
-
- [Fact]
- public async Task CheckImageHealthAsyncWithProgress()
- {
- int current = -1;
- int total = -1;
-
- using DismSession session = DismApi.OpenOnlineSession();
- using CancellationTokenSource cts = new();
-
- SynchronousProgress progress = new(p =>
- {
- current = p.Current;
- total = p.Total;
-
- // Cancel the operation, otherwise it takes ~1 min
- cts.Cancel();
- });
-
- try
- {
- await DismApi.CheckImageHealthAsync(session, scanImage: true, progress: progress, cancellationToken: cts.Token);
- }
- catch (OperationCanceledException)
- {
- }
-
- current.ShouldBe(50);
- total.ShouldBeGreaterThanOrEqualTo(1000);
- }
-
- private sealed class SynchronousProgress : IProgress
- {
- private readonly Action _handler;
-
- public SynchronousProgress(Action handler)
- {
- _handler = handler;
- }
-
- public void Report(T value)
- {
- _handler(value);
- }
- }
- }
-}
-#endif
diff --git a/src/Microsoft.Dism.Tests/CheckImageHealthTest.cs b/src/Microsoft.Dism.Tests/CheckImageHealthTest.cs
index 487fdfb..5c5333f 100644
--- a/src/Microsoft.Dism.Tests/CheckImageHealthTest.cs
+++ b/src/Microsoft.Dism.Tests/CheckImageHealthTest.cs
@@ -3,7 +3,11 @@
// Licensed under the MIT license.
using Shouldly;
+
using System;
+using System.Threading;
+using System.Threading.Tasks;
+
using Xunit;
namespace Microsoft.Dism.Tests
@@ -15,6 +19,67 @@ public CheckImageHealthTest(TestWimTemplate template, ITestOutputHelper testOutp
{
}
+ [Fact]
+ public async Task CheckImageHealthAsyncCancellation()
+ {
+ using DismSession session = DismApi.OpenOnlineSession();
+ using CancellationTokenSource cts = new();
+
+ cts.Cancel();
+
+ bool canceled = false;
+
+ try
+ {
+ await DismApi.CheckImageHealthAsync(session, scanImage: false, cancellationToken: cts.Token);
+ }
+ catch (OperationCanceledException)
+ {
+ canceled = true;
+ }
+
+ canceled.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task CheckImageHealthAsyncOnlineSession()
+ {
+ using DismSession session = DismApi.OpenOnlineSession();
+
+ DismImageHealthState imageHealthState = await DismApi.CheckImageHealthAsync(session, scanImage: false, cancellationToken: TestContext.Current.CancellationToken);
+
+ imageHealthState.ShouldBe(DismImageHealthState.Healthy);
+ }
+
+ [Fact]
+ public async Task CheckImageHealthAsyncWithProgress()
+ {
+ int current = -1;
+ int total = -1;
+
+ using DismSession session = DismApi.OpenOnlineSession();
+ using CancellationTokenSource cts = new();
+
+ Progress progress = new(dismProgress =>
+ {
+ current = dismProgress.Current;
+ total = dismProgress.Total;
+
+ dismProgress.Cancel = true; // Cancel the operation, otherwise it takes a few minutes
+ });
+
+ try
+ {
+ await DismApi.CheckImageHealthAsync(session, scanImage: true, progress: progress, cancellationToken: cts.Token);
+ }
+ catch (OperationCanceledException)
+ {
+ }
+
+ current.ShouldBeGreaterThan(-1);
+ total.ShouldBeGreaterThan(-1);
+ }
+
[Fact]
public void CheckImageHealthOnlineSession()
{
@@ -60,4 +125,4 @@ public void CheckImageHealthOnlineSessionWithCallback()
total.ShouldBeGreaterThanOrEqualTo(1000);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Microsoft.Dism.Tests/CommitImageAsyncTest.cs b/src/Microsoft.Dism.Tests/CommitImageAsyncTest.cs
deleted file mode 100644
index 9254ba6..0000000
--- a/src/Microsoft.Dism.Tests/CommitImageAsyncTest.cs
+++ /dev/null
@@ -1,83 +0,0 @@
-// Copyright (c). All rights reserved.
-//
-// Licensed under the MIT license.
-#if !NETFRAMEWORK
-using Shouldly;
-using System;
-using System.Threading;
-using System.Threading.Tasks;
-using Xunit;
-
-namespace Microsoft.Dism.Tests
-{
- public class CommitImageAsyncTest : DismInstallWimTestBase
- {
- public CommitImageAsyncTest(TestWimTemplate template, ITestOutputHelper testOutput)
- : base(template, testOutput)
- {
- }
-
- [Fact]
- public async Task CommitImageAsyncCancellation()
- {
- using CancellationTokenSource cts = new();
- cts.Cancel();
-
- bool canceled = false;
-
- try
- {
- await DismApi.CommitImageAsync(Session, discardChanges: true, cancellationToken: cts.Token);
- }
- catch (OperationCanceledException)
- {
- canceled = true;
- }
-
- canceled.ShouldBeTrue();
- }
-
- [Fact]
- public async Task CommitImageAsyncWithProgress()
- {
- using CancellationTokenSource cts = new();
-
- SynchronousProgress progress = new(_ =>
- {
- cts.Cancel();
- });
-
- try
- {
- await DismApi.CommitImageAsync(Session, discardChanges: true, progress: progress, cancellationToken: cts.Token);
- }
- catch (OperationCanceledException)
- {
- }
-
- // Progress may or may not be called depending on whether changes exist to commit
- }
-
- [Fact]
- public async Task CommitImageAsyncHappyPath()
- {
- await DismApi.CommitImageAsync(Session, discardChanges: true, cancellationToken: TestContext.Current.CancellationToken);
- }
-
- private sealed class SynchronousProgress : IProgress
- {
- private readonly Action _handler;
-
- public SynchronousProgress(Action handler)
- {
- _handler = handler;
- }
-
- public void Report(T value)
- {
- _handler(value);
- }
- }
- }
-}
-#endif
diff --git a/src/Microsoft.Dism.Tests/DisableFeatureAsyncTest.cs b/src/Microsoft.Dism.Tests/DisableFeatureAsyncTest.cs
deleted file mode 100644
index a9131e2..0000000
--- a/src/Microsoft.Dism.Tests/DisableFeatureAsyncTest.cs
+++ /dev/null
@@ -1,83 +0,0 @@
-// Copyright (c). All rights reserved.
-//
-// Licensed under the MIT license.
-#if !NETFRAMEWORK
-using Shouldly;
-using System;
-using System.Threading;
-using System.Threading.Tasks;
-using Xunit;
-
-namespace Microsoft.Dism.Tests
-{
- public class DisableFeatureAsyncTest : DismTestBase
- {
- public DisableFeatureAsyncTest(TestWimTemplate template, ITestOutputHelper testOutput)
- : base(template, testOutput)
- {
- }
-
- [Fact]
- public async Task DisableFeatureAsyncCancellation()
- {
- using DismSession session = DismApi.OpenOnlineSession();
- using CancellationTokenSource cts = new();
- cts.Cancel();
-
- bool canceled = false;
-
- try
- {
- await DismApi.DisableFeatureAsync(session, "FakeFeature", packageName: string.Empty, removePayload: false, cancellationToken: cts.Token);
- }
- catch (OperationCanceledException)
- {
- canceled = true;
- }
-
- canceled.ShouldBeTrue();
- }
-
- [Fact]
- public async Task DisableFeatureAsyncWithProgress()
- {
- using DismSession session = DismApi.OpenOnlineSession();
- using CancellationTokenSource cts = new();
-
- SynchronousProgress progress = new(_ =>
- {
- cts.Cancel();
- });
-
- try
- {
- await DismApi.DisableFeatureAsync(session, "FakeFeature", packageName: string.Empty, removePayload: false, progress: progress, cancellationToken: cts.Token);
- }
- catch (OperationCanceledException)
- {
- }
- catch (DismException)
- {
- // Expected when the feature does not exist
- }
-
- // Progress may not be called for an invalid feature, so we just verify no hang occurred
- }
-
- private sealed class SynchronousProgress : IProgress
- {
- private readonly Action _handler;
-
- public SynchronousProgress(Action handler)
- {
- _handler = handler;
- }
-
- public void Report(T value)
- {
- _handler(value);
- }
- }
- }
-}
-#endif
diff --git a/src/Microsoft.Dism.Tests/EnableFeatureAsyncTest.cs b/src/Microsoft.Dism.Tests/EnableFeatureAsyncTest.cs
deleted file mode 100644
index 17ae751..0000000
--- a/src/Microsoft.Dism.Tests/EnableFeatureAsyncTest.cs
+++ /dev/null
@@ -1,125 +0,0 @@
-// Copyright (c). All rights reserved.
-//
-// Licensed under the MIT license.
-#if !NETFRAMEWORK
-using Shouldly;
-using System;
-using System.Threading;
-using System.Threading.Tasks;
-using Xunit;
-
-namespace Microsoft.Dism.Tests
-{
- public class EnableFeatureAsyncTest : DismTestBase
- {
- public EnableFeatureAsyncTest(TestWimTemplate template, ITestOutputHelper testOutput)
- : base(template, testOutput)
- {
- }
-
- [Fact]
- public async Task EnableFeatureAsyncCancellation()
- {
- using DismSession session = DismApi.OpenOnlineSession();
- using CancellationTokenSource cts = new();
- cts.Cancel();
-
- bool canceled = false;
-
- try
- {
- await DismApi.EnableFeatureAsync(session, "FakeFeature", limitAccess: true, enableAll: false, cancellationToken: cts.Token);
- }
- catch (OperationCanceledException)
- {
- canceled = true;
- }
-
- canceled.ShouldBeTrue();
- }
-
- [Fact]
- public async Task EnableFeatureByPackageNameAsyncCancellation()
- {
- using DismSession session = DismApi.OpenOnlineSession();
- using CancellationTokenSource cts = new();
- cts.Cancel();
-
- bool canceled = false;
-
- try
- {
- await DismApi.EnableFeatureByPackageNameAsync(session, "FakeFeature", "FakePackage", limitAccess: true, enableAll: false, cancellationToken: cts.Token);
- }
- catch (OperationCanceledException)
- {
- canceled = true;
- }
-
- canceled.ShouldBeTrue();
- }
-
- [Fact]
- public async Task EnableFeatureByPackagePathAsyncCancellation()
- {
- using DismSession session = DismApi.OpenOnlineSession();
- using CancellationTokenSource cts = new();
- cts.Cancel();
-
- bool canceled = false;
-
- try
- {
- await DismApi.EnableFeatureByPackagePathAsync(session, "FakeFeature", "FakePackage.cab", limitAccess: true, enableAll: false, cancellationToken: cts.Token);
- }
- catch (OperationCanceledException)
- {
- canceled = true;
- }
-
- canceled.ShouldBeTrue();
- }
-
- [Fact]
- public async Task EnableFeatureAsyncWithProgress()
- {
- using DismSession session = DismApi.OpenOnlineSession();
- using CancellationTokenSource cts = new();
-
- SynchronousProgress progress = new(_ =>
- {
- cts.Cancel();
- });
-
- try
- {
- await DismApi.EnableFeatureAsync(session, "FakeFeature", limitAccess: true, enableAll: false, progress: progress, cancellationToken: cts.Token);
- }
- catch (OperationCanceledException)
- {
- }
- catch (DismException)
- {
- // Expected when the feature does not exist
- }
-
- // Progress may not be called for an invalid feature, so we just verify no hang occurred
- }
-
- private sealed class SynchronousProgress : IProgress
- {
- private readonly Action _handler;
-
- public SynchronousProgress(Action handler)
- {
- _handler = handler;
- }
-
- public void Report(T value)
- {
- _handler(value);
- }
- }
- }
-}
-#endif
diff --git a/src/Microsoft.Dism.Tests/GetCurrentEditionTests.cs b/src/Microsoft.Dism.Tests/GetCurrentEditionTests.cs
index bb63b6b..51acd86 100644
--- a/src/Microsoft.Dism.Tests/GetCurrentEditionTests.cs
+++ b/src/Microsoft.Dism.Tests/GetCurrentEditionTests.cs
@@ -7,7 +7,7 @@
namespace Microsoft.Dism.Tests
{
- public class GetCurrentEditionTests : DismInstallWimTestBase
+ public class GetCurrentEditionTests : DismTestBase
{
public GetCurrentEditionTests(TestWimTemplate template, ITestOutputHelper testOutput)
: base(template, testOutput)
diff --git a/src/Microsoft.Dism.Tests/Microsoft.Dism.Tests.csproj b/src/Microsoft.Dism.Tests/Microsoft.Dism.Tests.csproj
index 7ddc9d0..6f9c8de 100644
--- a/src/Microsoft.Dism.Tests/Microsoft.Dism.Tests.csproj
+++ b/src/Microsoft.Dism.Tests/Microsoft.Dism.Tests.csproj
@@ -1,7 +1,7 @@
Exe
- net472;net10.0
+ net472;net8.0;net10.0
x64
$(NoWarn);SA0001;SA1600;RS0016
diff --git a/src/Microsoft.Dism.Tests/MountImageAsyncTest.cs b/src/Microsoft.Dism.Tests/MountImageAsyncTest.cs
deleted file mode 100644
index 9e818c9..0000000
--- a/src/Microsoft.Dism.Tests/MountImageAsyncTest.cs
+++ /dev/null
@@ -1,142 +0,0 @@
-// Copyright (c). All rights reserved.
-//
-// Licensed under the MIT license.
-
-#if !NETFRAMEWORK
-using Shouldly;
-using System;
-using System.Threading;
-using System.Threading.Tasks;
-using Xunit;
-
-namespace Microsoft.Dism.Tests
-{
- public class MountImageAsyncTest : DismTestBase
- {
- public MountImageAsyncTest(TestWimTemplate template, ITestOutputHelper testOutput)
- : base(template, testOutput)
- {
- }
-
- [Fact]
- public async Task MountImageAsyncByIndexHappyPath()
- {
- foreach (DismMountedImageInfo mountedImageInfo in DismApi.GetMountedImages())
- {
- DismApi.UnmountImage(mountedImageInfo.MountPath, false);
- }
-
- DismApi.CleanupMountpoints();
-
- try
- {
- await DismApi.MountImageAsync(InstallWimPath.FullName, MountPath.FullName, imageIndex: 1, readOnly: true, options: DismMountImageOptions.None, progress: null, cancellationToken: CancellationToken.None);
- }
- finally
- {
- try
- {
- DismApi.UnmountImage(MountPath.FullName, commitChanges: false);
- }
- catch
- {
- // Best effort cleanup
- }
- }
- }
-
- [Fact]
- public async Task MountImageAsyncByIndexCancellation()
- {
- using CancellationTokenSource cts = new();
- cts.Cancel();
-
- bool canceled = false;
-
- try
- {
- await DismApi.MountImageAsync(InstallWimPath.FullName, MountPath.FullName, imageIndex: 1, readOnly: true, options: DismMountImageOptions.None, progress: null, cancellationToken: cts.Token);
- }
- catch (OperationCanceledException)
- {
- canceled = true;
- }
-
- canceled.ShouldBeTrue();
- }
-
- [Fact]
- public async Task MountImageAsyncByNameCancellation()
- {
- using CancellationTokenSource cts = new();
- cts.Cancel();
-
- bool canceled = false;
-
- try
- {
- await DismApi.MountImageAsync(InstallWimPath.FullName, MountPath.FullName, imageName: "FakeImage", readOnly: true, options: DismMountImageOptions.None, progress: null, cancellationToken: cts.Token);
- }
- catch (OperationCanceledException)
- {
- canceled = true;
- }
-
- canceled.ShouldBeTrue();
- }
-
- [Fact]
- public async Task MountImageAsyncWithProgress()
- {
- bool progressCalled = false;
-
- foreach (DismMountedImageInfo mountedImageInfo in DismApi.GetMountedImages())
- {
- DismApi.UnmountImage(mountedImageInfo.MountPath, false);
- }
-
- DismApi.CleanupMountpoints();
-
- using CancellationTokenSource cts = new();
-
- SynchronousProgress progress = new(_ =>
- {
- progressCalled = true;
- });
-
- try
- {
- await DismApi.MountImageAsync(InstallWimPath.FullName, MountPath.FullName, imageIndex: 1, readOnly: true, options: DismMountImageOptions.None, progress: progress, cancellationToken: cts.Token);
- }
- finally
- {
- try
- {
- DismApi.UnmountImage(MountPath.FullName, commitChanges: false);
- }
- catch
- {
- // Best effort cleanup
- }
- }
-
- progressCalled.ShouldBeTrue();
- }
-
- private sealed class SynchronousProgress : IProgress
- {
- private readonly Action _handler;
-
- public SynchronousProgress(Action handler)
- {
- _handler = handler;
- }
-
- public void Report(T value)
- {
- _handler(value);
- }
- }
- }
-}
-#endif
diff --git a/src/Microsoft.Dism.Tests/MountImageTest.cs b/src/Microsoft.Dism.Tests/MountImageTest.cs
new file mode 100644
index 0000000..066a1e0
--- /dev/null
+++ b/src/Microsoft.Dism.Tests/MountImageTest.cs
@@ -0,0 +1,92 @@
+// Copyright (c). All rights reserved.
+//
+// Licensed under the MIT license.
+
+using Shouldly;
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+using Xunit;
+
+namespace Microsoft.Dism.Tests
+{
+ public class MountImageTest : DismTestBase
+ {
+ public MountImageTest(TestWimTemplate template, ITestOutputHelper testOutput)
+ : base(template, testOutput)
+ {
+ }
+
+ [Fact]
+ public async Task MountImageAsyncByIndexWithCancellation()
+ {
+ using CancellationTokenSource cts = new();
+ cts.Cancel();
+
+ bool canceled = false;
+
+ try
+ {
+ await DismApi.MountImageAsync(InstallWimPath.FullName, MountPath.FullName, imageIndex: 1, readOnly: true, options: DismMountImageOptions.None, progress: null, cancellationToken: cts.Token);
+ }
+ catch (OperationCanceledException)
+ {
+ canceled = true;
+ }
+
+ canceled.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task MountImageAsyncByNameWithCancellation()
+ {
+ using CancellationTokenSource cts = new();
+ cts.Cancel();
+
+ bool canceled = false;
+
+ try
+ {
+ await DismApi.MountImageAsync(InstallWimPath.FullName, MountPath.FullName, imageName: "FakeImage", readOnly: true, options: DismMountImageOptions.None, progress: null, cancellationToken: cts.Token);
+ }
+ catch (OperationCanceledException)
+ {
+ canceled = true;
+ }
+
+ canceled.ShouldBeTrue();
+ }
+
+ [Fact]
+ public async Task MountImageAsyncInstallWim()
+ {
+ await DismApi.MountImageAsync(InstallWimPath.FullName, MountPath.FullName, imageIndex: 1, readOnly: true, DismMountImageOptions.None, progress: null, TestContext.Current.CancellationToken);
+
+ await DismApi.UnmountImageAsync(MountPath.FullName, commitChanges: false, progress: null, cancellationToken: TestContext.Current.CancellationToken);
+ }
+
+ [Fact]
+ public async Task MountImageAsyncWithProgress()
+ {
+ bool progressCalled = false;
+
+ using CancellationTokenSource cts = new();
+
+ Progress progress = new(_ =>
+ {
+ progressCalled = true;
+ });
+
+ await DismApi.MountImageAsync(InstallWimPath.FullName, MountPath.FullName, imageIndex: 1, readOnly: true, options: DismMountImageOptions.None, progress: progress, cancellationToken: cts.Token);
+
+ try
+ {
+ progressCalled.ShouldBeTrue();
+ }
+ finally
+ {
+ await DismApi.UnmountImageAsync(MountPath.FullName, commitChanges: false, progress: null, TestContext.Current.CancellationToken);
+ }
+ }
+ }
+}
diff --git a/src/Microsoft.Dism.Tests/RemoveCapabilityAsyncTest.cs b/src/Microsoft.Dism.Tests/RemoveCapabilityAsyncTest.cs
deleted file mode 100644
index fbf955b..0000000
--- a/src/Microsoft.Dism.Tests/RemoveCapabilityAsyncTest.cs
+++ /dev/null
@@ -1,83 +0,0 @@
-// Copyright (c). All rights reserved.
-//
-// Licensed under the MIT license.
-#if !NETFRAMEWORK
-using Shouldly;
-using System;
-using System.Threading;
-using System.Threading.Tasks;
-using Xunit;
-
-namespace Microsoft.Dism.Tests
-{
- public class RemoveCapabilityAsyncTest : DismTestBase
- {
- public RemoveCapabilityAsyncTest(TestWimTemplate template, ITestOutputHelper testOutput)
- : base(template, testOutput)
- {
- }
-
- [Fact]
- public async Task RemoveCapabilityAsyncCancellation()
- {
- using DismSession session = DismApi.OpenOnlineSession();
- using CancellationTokenSource cts = new();
- cts.Cancel();
-
- bool canceled = false;
-
- try
- {
- await DismApi.RemoveCapabilityAsync(session, "FakeCapability", cancellationToken: cts.Token);
- }
- catch (OperationCanceledException)
- {
- canceled = true;
- }
-
- canceled.ShouldBeTrue();
- }
-
- [Fact]
- public async Task RemoveCapabilityAsyncWithProgress()
- {
- using DismSession session = DismApi.OpenOnlineSession();
- using CancellationTokenSource cts = new();
-
- SynchronousProgress progress = new(_ =>
- {
- cts.Cancel();
- });
-
- try
- {
- await DismApi.RemoveCapabilityAsync(session, "FakeCapability", progress: progress, cancellationToken: cts.Token);
- }
- catch (OperationCanceledException)
- {
- }
- catch (DismException)
- {
- // Expected when the capability does not exist
- }
-
- // Progress may not be called for an invalid capability, so we just verify no hang occurred
- }
-
- private sealed class SynchronousProgress : IProgress
- {
- private readonly Action _handler;
-
- public SynchronousProgress(Action handler)
- {
- _handler = handler;
- }
-
- public void Report(T value)
- {
- _handler(value);
- }
- }
- }
-}
-#endif
diff --git a/src/Microsoft.Dism.Tests/RemovePackageAsyncTest.cs b/src/Microsoft.Dism.Tests/RemovePackageAsyncTest.cs
deleted file mode 100644
index e609256..0000000
--- a/src/Microsoft.Dism.Tests/RemovePackageAsyncTest.cs
+++ /dev/null
@@ -1,104 +0,0 @@
-// Copyright (c). All rights reserved.
-//
-// Licensed under the MIT license.
-#if !NETFRAMEWORK
-using Shouldly;
-using System;
-using System.Threading;
-using System.Threading.Tasks;
-using Xunit;
-
-namespace Microsoft.Dism.Tests
-{
- public class RemovePackageAsyncTest : DismTestBase
- {
- public RemovePackageAsyncTest(TestWimTemplate template, ITestOutputHelper testOutput)
- : base(template, testOutput)
- {
- }
-
- [Fact]
- public async Task RemovePackageByNameAsyncCancellation()
- {
- using DismSession session = DismApi.OpenOnlineSession();
- using CancellationTokenSource cts = new();
- cts.Cancel();
-
- bool canceled = false;
-
- try
- {
- await DismApi.RemovePackageByNameAsync(session, "FakePackage", cancellationToken: cts.Token);
- }
- catch (OperationCanceledException)
- {
- canceled = true;
- }
-
- canceled.ShouldBeTrue();
- }
-
- [Fact]
- public async Task RemovePackageByPathAsyncCancellation()
- {
- using DismSession session = DismApi.OpenOnlineSession();
- using CancellationTokenSource cts = new();
- cts.Cancel();
-
- bool canceled = false;
-
- try
- {
- await DismApi.RemovePackageByPathAsync(session, "nonexistent.cab", cancellationToken: cts.Token);
- }
- catch (OperationCanceledException)
- {
- canceled = true;
- }
-
- canceled.ShouldBeTrue();
- }
-
- [Fact]
- public async Task RemovePackageByNameAsyncWithProgress()
- {
- using DismSession session = DismApi.OpenOnlineSession();
- using CancellationTokenSource cts = new();
-
- SynchronousProgress progress = new(_ =>
- {
- cts.Cancel();
- });
-
- try
- {
- await DismApi.RemovePackageByNameAsync(session, "FakePackage", progress: progress, cancellationToken: cts.Token);
- }
- catch (OperationCanceledException)
- {
- }
- catch (DismException)
- {
- // Expected when the package does not exist
- }
-
- // Progress may not be called for an invalid package, so we just verify no hang occurred
- }
-
- private sealed class SynchronousProgress : IProgress
- {
- private readonly Action _handler;
-
- public SynchronousProgress(Action handler)
- {
- _handler = handler;
- }
-
- public void Report(T value)
- {
- _handler(value);
- }
- }
- }
-}
-#endif
diff --git a/src/Microsoft.Dism.Tests/RestoreImageHealthAsyncTest.cs b/src/Microsoft.Dism.Tests/RestoreImageHealthAsyncTest.cs
deleted file mode 100644
index d162b77..0000000
--- a/src/Microsoft.Dism.Tests/RestoreImageHealthAsyncTest.cs
+++ /dev/null
@@ -1,79 +0,0 @@
-// Copyright (c). All rights reserved.
-//
-// Licensed under the MIT license.
-#if !NETFRAMEWORK
-using Shouldly;
-using System;
-using System.Threading;
-using System.Threading.Tasks;
-using Xunit;
-
-namespace Microsoft.Dism.Tests
-{
- public class RestoreImageHealthAsyncTest : DismTestBase
- {
- public RestoreImageHealthAsyncTest(TestWimTemplate template, ITestOutputHelper testOutput)
- : base(template, testOutput)
- {
- }
-
- [Fact]
- public async Task RestoreImageHealthAsyncCancellation()
- {
- using DismSession session = DismApi.OpenOnlineSession();
- using CancellationTokenSource cts = new();
- cts.Cancel();
-
- bool canceled = false;
-
- try
- {
- await DismApi.RestoreImageHealthAsync(session, limitAccess: true, cancellationToken: cts.Token);
- }
- catch (OperationCanceledException)
- {
- canceled = true;
- }
-
- canceled.ShouldBeTrue();
- }
-
- [Fact]
- public async Task RestoreImageHealthAsyncWithProgress()
- {
- using DismSession session = DismApi.OpenOnlineSession();
- using CancellationTokenSource cts = new();
-
- SynchronousProgress progress = new(_ =>
- {
- cts.Cancel();
- });
-
- try
- {
- await DismApi.RestoreImageHealthAsync(session, limitAccess: true, progress: progress, cancellationToken: cts.Token);
- }
- catch (OperationCanceledException)
- {
- }
-
- // Progress may or may not be called depending on image state, so we just verify no hang occurred
- }
-
- private sealed class SynchronousProgress : IProgress
- {
- private readonly Action _handler;
-
- public SynchronousProgress(Action handler)
- {
- _handler = handler;
- }
-
- public void Report(T value)
- {
- _handler(value);
- }
- }
- }
-}
-#endif
diff --git a/src/Microsoft.Dism.Tests/SetEditionAsyncTest.cs b/src/Microsoft.Dism.Tests/SetEditionAsyncTest.cs
deleted file mode 100644
index 02989cb..0000000
--- a/src/Microsoft.Dism.Tests/SetEditionAsyncTest.cs
+++ /dev/null
@@ -1,101 +0,0 @@
-// Copyright (c). All rights reserved.
-//
-// Licensed under the MIT license.
-#if !NETFRAMEWORK
-using Shouldly;
-using System;
-using System.Threading;
-using System.Threading.Tasks;
-using Xunit;
-
-namespace Microsoft.Dism.Tests
-{
- public class SetEditionAsyncTest : DismInstallWimTestBase
- {
- public SetEditionAsyncTest(TestWimTemplate template, ITestOutputHelper testOutput)
- : base(template, testOutput)
- {
- }
-
- [Fact]
- public async Task SetEditionAsyncCancellation()
- {
- using CancellationTokenSource cts = new();
- cts.Cancel();
-
- bool canceled = false;
-
- try
- {
- await DismApi.SetEditionAsync(Session, "FakeEdition", cancellationToken: cts.Token);
- }
- catch (OperationCanceledException)
- {
- canceled = true;
- }
-
- canceled.ShouldBeTrue();
- }
-
- [Fact]
- public async Task SetEditionAndProductKeyAsyncCancellation()
- {
- using CancellationTokenSource cts = new();
- cts.Cancel();
-
- bool canceled = false;
-
- try
- {
- await DismApi.SetEditionAndProductKeyAsync(Session, "FakeEdition", "XXXXX-XXXXX-XXXXX-XXXXX-XXXXX", cancellationToken: cts.Token);
- }
- catch (OperationCanceledException)
- {
- canceled = true;
- }
-
- canceled.ShouldBeTrue();
- }
-
- [Fact]
- public async Task SetEditionAsyncWithProgress()
- {
- using CancellationTokenSource cts = new();
-
- SynchronousProgress progress = new(_ =>
- {
- cts.Cancel();
- });
-
- try
- {
- await DismApi.SetEditionAsync(Session, "FakeEdition", progress: progress, cancellationToken: cts.Token);
- }
- catch (OperationCanceledException)
- {
- }
- catch (DismException)
- {
- // Expected when the edition does not exist
- }
-
- // Progress may not be called for an invalid edition, so we just verify no hang occurred
- }
-
- private sealed class SynchronousProgress : IProgress
- {
- private readonly Action _handler;
-
- public SynchronousProgress(Action handler)
- {
- _handler = handler;
- }
-
- public void Report(T value)
- {
- _handler(value);
- }
- }
- }
-}
-#endif
diff --git a/src/Microsoft.Dism.Tests/TestWimTemplate.cs b/src/Microsoft.Dism.Tests/TestWimTemplate.cs
index 5994188..d0a2bc0 100644
--- a/src/Microsoft.Dism.Tests/TestWimTemplate.cs
+++ b/src/Microsoft.Dism.Tests/TestWimTemplate.cs
@@ -87,7 +87,7 @@ private string CaptureTemplateImage(string capturePath)
using WimHandle imageHandle = WimgApi.CaptureImage(wimHandle, capturePath, WimCaptureImageOptions.DisableDirectoryAcl | WimCaptureImageOptions.DisableFileAcl | WimCaptureImageOptions.DisableRPFix);
}
- XPathNavigator xml = WimgApi.GetImageInformation(wimHandle!) !.CreateNavigator() !;
+ XPathNavigator xml = WimgApi.GetImageInformation(wimHandle!)!.CreateNavigator()!;
xml.ShouldNotBeNull();
@@ -172,7 +172,7 @@ private string CreateTemplateImage()
}
}
- [CollectionDefinition(nameof(TestWimTemplate))]
+ [CollectionDefinition(nameof(TestWimTemplate), DisableParallelization = true)]
public class TestWimTemplateCollectionDefinition : ICollectionFixture
{
}
diff --git a/src/Microsoft.Dism.Tests/UnmountImageAsyncTest.cs b/src/Microsoft.Dism.Tests/UnmountImageAsyncTest.cs
deleted file mode 100644
index 3829b38..0000000
--- a/src/Microsoft.Dism.Tests/UnmountImageAsyncTest.cs
+++ /dev/null
@@ -1,109 +0,0 @@
-// Copyright (c). All rights reserved.
-//
-// Licensed under the MIT license.
-#if !NETFRAMEWORK
-using Shouldly;
-using System;
-using System.Threading;
-using System.Threading.Tasks;
-using Xunit;
-
-namespace Microsoft.Dism.Tests
-{
- public class UnmountImageAsyncTest : DismTestBase
- {
- public UnmountImageAsyncTest(TestWimTemplate template, ITestOutputHelper testOutput)
- : base(template, testOutput)
- {
- }
-
- [Fact]
- public async Task UnmountImageAsyncCancellation()
- {
- using CancellationTokenSource cts = new();
- cts.Cancel();
-
- bool canceled = false;
-
- try
- {
- await DismApi.UnmountImageAsync(MountPath.FullName, commitChanges: false, cancellationToken: cts.Token);
- }
- catch (OperationCanceledException)
- {
- canceled = true;
- }
-
- canceled.ShouldBeTrue();
- }
-
- [Fact]
- public async Task UnmountImageAsyncWithProgress()
- {
- // Mount an image first so we can unmount it
- foreach (DismMountedImageInfo mountedImageInfo in DismApi.GetMountedImages())
- {
- DismApi.UnmountImage(mountedImageInfo.MountPath, false);
- }
-
- DismApi.CleanupMountpoints();
- DismApi.MountImage(InstallWimPath.FullName, MountPath.FullName, 1);
-
- using CancellationTokenSource cts = new();
-
- SynchronousProgress progress = new(_ =>
- {
- });
-
- try
- {
- await DismApi.UnmountImageAsync(MountPath.FullName, commitChanges: false, progress: progress, cancellationToken: cts.Token);
- }
- catch (DismException)
- {
- // Attempt to clean up
- try
- {
- DismApi.UnmountImage(MountPath.FullName, commitChanges: false);
- }
- catch
- {
- // Best effort cleanup
- }
- }
-
- // Progress may or may not be called depending on image size
- }
-
- [Fact]
- public async Task UnmountImageAsyncHappyPath()
- {
- // Mount an image first so we can unmount it
- foreach (DismMountedImageInfo mountedImageInfo in DismApi.GetMountedImages())
- {
- DismApi.UnmountImage(mountedImageInfo.MountPath, false);
- }
-
- DismApi.CleanupMountpoints();
- DismApi.MountImage(InstallWimPath.FullName, MountPath.FullName, 1);
-
- await DismApi.UnmountImageAsync(MountPath.FullName, commitChanges: false, cancellationToken: TestContext.Current.CancellationToken);
- }
-
- private sealed class SynchronousProgress : IProgress
- {
- private readonly Action _handler;
-
- public SynchronousProgress(Action handler)
- {
- _handler = handler;
- }
-
- public void Report(T value)
- {
- _handler(value);
- }
- }
- }
-}
-#endif
diff --git a/src/Microsoft.Dism/CallerMemberNameAttribute.cs b/src/Microsoft.Dism/CallerMemberNameAttribute.cs
deleted file mode 100644
index d5432d0..0000000
--- a/src/Microsoft.Dism/CallerMemberNameAttribute.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-// Copyright (c). All rights reserved.
-//
-// Licensed under the MIT license.
-
-#if NET40
-namespace System.Runtime.CompilerServices
-{
- ///
- /// Allows you to obtain the method or property name of the caller to the method.
- ///
- [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
- internal class CallerMemberNameAttribute : Attribute
- {
- }
-}
-#endif
\ No newline at end of file
diff --git a/src/Microsoft.Dism/DismApi.AddCapability.cs b/src/Microsoft.Dism/DismApi.AddCapability.cs
index 2d897ec..903befc 100644
--- a/src/Microsoft.Dism/DismApi.AddCapability.cs
+++ b/src/Microsoft.Dism/DismApi.AddCapability.cs
@@ -5,6 +5,7 @@
using Microsoft.Win32.SafeHandles;
using System;
using System.Collections.Generic;
+using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
@@ -52,20 +53,14 @@ public static void AddCapability(DismSession session, string capabilityName, boo
/// Optional user data to pass to the DismProgressCallback method.
/// When a failure occurs.
/// When the operation requires a reboot to complete.
- public static void AddCapability(DismSession session, string capabilityName, bool limitAccess, List? sourcePaths, Microsoft.Dism.DismProgressCallback? progressCallback, object? userData)
+ public static void AddCapability(DismSession session, string capabilityName, bool limitAccess, List? sourcePaths, DismProgressCallback? progressCallback, object? userData)
{
- // Get the list of source paths as an array
- string[] sourcePathsArray = sourcePaths?.ToArray() ?? [];
-
// Create a DismProgress object to wrap the callback and allow cancellation
- DismProgress progress = new(progressCallback, userData);
+ using DismProgress progress = new(progressCallback, userData);
- int hresult = NativeMethods.DismAddCapability(session, capabilityName, limitAccess, sourcePathsArray, (uint)sourcePathsArray.Length, progress.EventHandle, progress.DismProgressCallbackNative, IntPtr.Zero);
-
- DismUtilities.ThrowIfFail(hresult, session);
+ AddCapability(session, capabilityName, limitAccess, sourcePaths, progress);
}
-#if !NET40
///
/// Asynchronously adds a capability to an image.
///
@@ -73,61 +68,70 @@ public static void AddCapability(DismSession session, string capabilityName, boo
/// The name of the capability that is being added.
/// The flag indicates whether WU/WSUS should be contacted as a source location for downloading the payload of a capability. If payload of the capability to be added exists, the flag is ignored.
/// A list of source locations. The function shall look up removed payload files from the locations specified in SourcePaths, and if not found, continue the search by contacting WU/WSUS depending on parameter LimitAccess.
- /// An optional progress provider to receive progress updates.
- /// A cancellation token to cancel the operation.
+ /// A token to monitor for cancellation requests. The default value is .
/// A representing the asynchronous operation.
/// When a failure occurs.
/// When the operation is canceled.
/// When the operation requires a reboot to complete.
- public static Task AddCapabilityAsync(DismSession session, string capabilityName, bool limitAccess, List? sourcePaths, IProgress? progress = null, CancellationToken cancellationToken = default)
+ public static Task AddCapabilityAsync(DismSession session, string capabilityName, bool limitAccess, List? sourcePaths, CancellationToken cancellationToken = default)
{
- TaskCompletionSource tcs = new();
+ return AddCapabilityAsync(session, capabilityName, limitAccess, sourcePaths, progress: null, cancellationToken);
+ }
- CancellationTokenRegistration ctsRegistration = default;
+ ///
+ /// Asynchronously adds a capability to an image.
+ ///
+ /// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the method.
+ /// The name of the capability that is being added.
+ /// The flag indicates whether WU/WSUS should be contacted as a source location for downloading the payload of a capability. If payload of the capability to be added exists, the flag is ignored.
+ /// A list of source locations. The function shall look up removed payload files from the locations specified in SourcePaths, and if not found, continue the search by contacting WU/WSUS depending on parameter LimitAccess.
+ /// An optional provider to receive progress updates.
+ /// A token to monitor for cancellation requests. The default value is .
+ /// A representing the asynchronous operation.
+ /// When a failure occurs.
+ /// When the operation is canceled.
+ /// When the operation requires a reboot to complete.
+ public static Task AddCapabilityAsync(DismSession session, string capabilityName, bool limitAccess, List? sourcePaths, IProgress? progress, CancellationToken cancellationToken = default)
+ {
+ return AddCapabilityAsync(session, capabilityName, limitAccess, sourcePaths, progress, userData: null, cancellationToken);
+ }
- Task.Factory.StartNew(
- () =>
+ ///
+ /// Asynchronously adds a capability to an image.
+ ///
+ /// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the method.
+ /// The name of the capability that is being added.
+ /// The flag indicates whether WU/WSUS should be contacted as a source location for downloading the payload of a capability. If payload of the capability to be added exists, the flag is ignored.
+ /// A list of source locations. The function shall look up removed payload files from the locations specified in SourcePaths, and if not found, continue the search by contacting WU/WSUS depending on parameter LimitAccess.
+ /// An optional provider to receive progress updates.
+ /// Optional user data to pass to the specified .
+ /// A token to monitor for cancellation requests. The default value is .
+ /// A representing the asynchronous operation.
+ /// When a failure occurs.
+ /// When the operation is canceled.
+ /// When the operation requires a reboot to complete.
+ public static Task AddCapabilityAsync(DismSession session, string capabilityName, bool limitAccess, List? sourcePaths, IProgress? progress, object? userData, CancellationToken cancellationToken = default)
+ {
+ return DismUtilities.RunAsync(
+ static (state, progress) =>
{
- try
- {
- string[] sourcePathsArray = sourcePaths?.ToArray() ?? [];
-
- DismProgress dismProgress = new(progress != null ? p => progress.Report(p) : null, null);
+ AddCapability(state.session, state.capabilityName, state.limitAccess, state.sourcePaths, progress);
- ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
+ return true;
+ },
+ (session, capabilityName, limitAccess, sourcePaths),
+ progress, userData, cancellationToken);
+ }
- int hresult = NativeMethods.DismAddCapability(session, capabilityName, limitAccess, sourcePathsArray, (uint)sourcePathsArray.Length, dismProgress.EventHandle, dismProgress.DismProgressCallbackNative, IntPtr.Zero);
+ private static void AddCapability(DismSession session, string capabilityName, bool limitAccess, List? sourcePaths, DismProgress progress)
+ {
+ // Get the list of source paths as an array
+ string[] sourcePathsArray = sourcePaths?.ToArray() ?? [];
- if (cancellationToken.IsCancellationRequested)
- {
- tcs.TrySetCanceled(cancellationToken);
- }
- else
- {
- DismUtilities.ThrowIfFail(hresult, session);
- tcs.TrySetResult(true);
- }
- }
- catch (OperationCanceledException)
- {
- tcs.TrySetCanceled(cancellationToken);
- }
- catch (Exception ex)
- {
- tcs.TrySetException(ex);
- }
- finally
- {
- ctsRegistration.Dispose();
- }
- },
- CancellationToken.None,
- TaskCreationOptions.LongRunning,
- TaskScheduler.Default);
+ int hresult = NativeMethods.DismAddCapability(session, capabilityName, limitAccess, sourcePathsArray, (uint)sourcePathsArray.Length, progress.EventHandle, progress.DismProgressCallbackNative, IntPtr.Zero);
- return tcs.Task;
+ DismUtilities.ThrowIfFail(hresult, session);
}
-#endif
internal static partial class NativeMethods
{
@@ -143,17 +147,23 @@ internal static partial class NativeMethods
/// Pointer to a client defined callback function to report progress.
/// User defined custom data. This will be passed back to the user through the callback.
/// Returns S_OK on success.
- ///
- ///
- /// HRESULT WINAPI DismAddCapability(_In_ DismSession Session, _In_ PCWSTR Name, _In_ BOOL LimitAccess, _In_ PCWSTR* SourcePaths, _In_opt_ UINT SourcePathCount, _In_opt_ HANDLE CancelEvent, _In_opt_ DISM_PROGRESS_CALLBACK Progress, _In_opt_ PVOID UserData);
- ///
- #if NET7_0_OR_GREATER
+ /// HRESULT WINAPI DismAddCapability(_In_ DismSession Session, _In_ PCWSTR Name, _In_ BOOL LimitAccess, _In_ PCWSTR* SourcePaths, _In_opt_ UINT SourcePathCount, _In_opt_ HANDLE CancelEvent, _In_opt_ DISM_PROGRESS_CALLBACK Progress, _In_opt_ PVOID UserData);
+#if NET7_0_OR_GREATER
[LibraryImport(DismDllName, StringMarshalling = DismStringMarshalling)]
- public static partial int DismAddCapability(DismSession session, string name, [MarshalAs(UnmanagedType.Bool)] bool limitAccess, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 6)] string[] sourcePaths, UInt32 sourcePathCount, SafeWaitHandle cancelEvent, DismProgressCallback progress, IntPtr userData);
- #else
+ public static partial
+#else
[DllImport(DismDllName, CharSet = DismCharacterSet)]
- public static extern int DismAddCapability(DismSession session, string name, [MarshalAs(UnmanagedType.Bool)] bool limitAccess, [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 6)] string[] sourcePaths, UInt32 sourcePathCount, SafeWaitHandle cancelEvent, DismProgressCallback progress, IntPtr userData);
- #endif
+ public static extern
+#endif
+ int DismAddCapability(
+ DismSession session,
+ string name,
+ [MarshalAs(UnmanagedType.Bool)] bool limitAccess,
+ [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 6)] string[] sourcePaths,
+ UInt32 sourcePathCount,
+ SafeWaitHandle cancelEvent,
+ DismProgressCallbackNative progress,
+ IntPtr userData);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Microsoft.Dism/DismApi.AddDriver.cs b/src/Microsoft.Dism/DismApi.AddDriver.cs
index 4a2e936..607c461 100644
--- a/src/Microsoft.Dism/DismApi.AddDriver.cs
+++ b/src/Microsoft.Dism/DismApi.AddDriver.cs
@@ -30,7 +30,7 @@ public static void AddDriver(DismSession session, string driverPath, bool forceU
/// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the method.
/// A relative or absolute path to a directory containing driver .inf files.
/// Indicates whether to accept unsigned drivers to an x64-based image. Unsigned drivers will automatically be added to an x86-based image.
- /// true to search recursively for driver files, otherwise false.
+ /// to search recursively for driver files, otherwise to only enumrate the specified directory.
/// The directory specified by the parameter does not exist.
public static void AddDriversEx(DismSession session, string driverDirectory, bool forceUnsigned, bool recursive)
{
@@ -55,11 +55,15 @@ internal static partial class NativeMethods
///
#if NET7_0_OR_GREATER
[LibraryImport(DismDllName, StringMarshalling = DismStringMarshalling)]
- public static partial int DismAddDriver(DismSession session, string driverPath, [MarshalAs(UnmanagedType.Bool)] bool forceUnsigned);
- #else
+ public static partial
+#else
[DllImport(DismDllName, CharSet = DismCharacterSet)]
- public static extern int DismAddDriver(DismSession session, string driverPath, [MarshalAs(UnmanagedType.Bool)] bool forceUnsigned);
- #endif
+ public static extern
+#endif
+ int DismAddDriver(
+ DismSession session,
+ string driverPath,
+ [MarshalAs(UnmanagedType.Bool)] bool forceUnsigned);
}
}
}
\ No newline at end of file
diff --git a/src/Microsoft.Dism/DismApi.AddPackage.cs b/src/Microsoft.Dism/DismApi.AddPackage.cs
index d952236..3f85eb6 100644
--- a/src/Microsoft.Dism/DismApi.AddPackage.cs
+++ b/src/Microsoft.Dism/DismApi.AddPackage.cs
@@ -39,7 +39,7 @@ public static void AddPackage(DismSession session, string packagePath, bool igno
/// When the user requested the operation be canceled.
/// When the operation requires a reboot to complete.
/// When the package is not applicable to the specified session.
- public static void AddPackage(DismSession session, string packagePath, bool ignoreCheck, bool preventPending, Microsoft.Dism.DismProgressCallback? progressCallback)
+ public static void AddPackage(DismSession session, string packagePath, bool ignoreCheck, bool preventPending, DismProgressCallback? progressCallback)
{
AddPackage(session, packagePath, ignoreCheck, preventPending, progressCallback, userData: null);
}
@@ -57,17 +57,14 @@ public static void AddPackage(DismSession session, string packagePath, bool igno
/// When the user requested the operation be canceled.
/// When the operation requires a reboot to complete.
/// When the package is not applicable to the specified session.
- public static void AddPackage(DismSession session, string packagePath, bool ignoreCheck, bool preventPending, Microsoft.Dism.DismProgressCallback? progressCallback, object? userData)
+ public static void AddPackage(DismSession session, string packagePath, bool ignoreCheck, bool preventPending, DismProgressCallback? progressCallback, object? userData)
{
// Create a DismProgress object to wrap the callback and allow cancellation
- DismProgress progress = new(progressCallback, userData);
+ using DismProgress progress = new(progressCallback, userData);
- int hresult = NativeMethods.DismAddPackage(session, packagePath, ignoreCheck, preventPending, progress.EventHandle, progress.DismProgressCallbackNative, IntPtr.Zero);
-
- DismUtilities.ThrowIfFail(hresult, session);
+ AddPackage(session, packagePath, ignoreCheck, preventPending, progress);
}
-#if !NET40
///
/// Asynchronously adds a single .cab or .msu file to a Windows® image.
///
@@ -75,60 +72,72 @@ public static void AddPackage(DismSession session, string packagePath, bool igno
/// A relative or absolute path to the .cab or .msu file being added or a folder containing the expanded files of a single .cab file.
/// Specifies whether to ignore the internal applicability checks that are done when a package is added.
/// Specifies whether to add a package if it has pending online actions.
- /// An optional progress provider to receive progress updates.
- /// A cancellation token to cancel the operation.
+ /// A token to monitor for cancellation requests. The default value is .
/// A representing the asynchronous operation.
/// When a failure occurs.
/// When the operation is canceled.
/// When the operation requires a reboot to complete.
/// When the package is not applicable to the specified session.
- public static Task AddPackageAsync(DismSession session, string packagePath, bool ignoreCheck, bool preventPending, IProgress? progress = null, CancellationToken cancellationToken = default)
+ public static Task AddPackageAsync(DismSession session, string packagePath, bool ignoreCheck, bool preventPending, CancellationToken cancellationToken = default)
{
- TaskCompletionSource tcs = new();
+ return AddPackageAsync(session, packagePath, ignoreCheck, preventPending, progress: null, cancellationToken);
+ }
- CancellationTokenRegistration ctsRegistration = default;
+ ///
+ /// Asynchronously adds a single .cab or .msu file to a Windows® image.
+ ///
+ /// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the OpenSession method.
+ /// A relative or absolute path to the .cab or .msu file being added or a folder containing the expanded files of a single .cab file.
+ /// Specifies whether to ignore the internal applicability checks that are done when a package is added.
+ /// Specifies whether to add a package if it has pending online actions.
+ /// An optional provider to receive progress updates.
+ /// A token to monitor for cancellation requests. The default value is .
+ /// A representing the asynchronous operation.
+ /// When a failure occurs.
+ /// When the operation is canceled.
+ /// When the operation requires a reboot to complete.
+ /// When the package is not applicable to the specified session.
+ public static Task AddPackageAsync(DismSession session, string packagePath, bool ignoreCheck, bool preventPending, IProgress? progress, CancellationToken cancellationToken = default)
+ {
+ return AddPackageAsync(session, packagePath, ignoreCheck, preventPending, progress, userData: null, cancellationToken);
+ }
- Task.Factory.StartNew(
- () =>
+ ///
+ /// Asynchronously adds a single .cab or .msu file to a Windows® image.
+ ///
+ /// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the OpenSession method.
+ /// A relative or absolute path to the .cab or .msu file being added or a folder containing the expanded files of a single .cab file.
+ /// Specifies whether to ignore the internal applicability checks that are done when a package is added.
+ /// Specifies whether to add a package if it has pending online actions.
+ /// An optional provider to receive progress updates.
+ /// Optional user data to pass to the specified .
+ /// A token to monitor for cancellation requests. The default value is .
+ /// A representing the asynchronous operation.
+ /// When a failure occurs.
+ /// When the operation is canceled.
+ /// When the operation requires a reboot to complete.
+ /// When the package is not applicable to the specified session.
+ public static Task AddPackageAsync(DismSession session, string packagePath, bool ignoreCheck, bool preventPending, IProgress? progress, object? userData, CancellationToken cancellationToken = default)
+ {
+ return DismUtilities.RunAsync(
+ static (state, progress) =>
{
- try
- {
- DismProgress dismProgress = new(progress != null ? p => progress.Report(p) : null, null);
-
- ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
-
- int hresult = NativeMethods.DismAddPackage(session, packagePath, ignoreCheck, preventPending, dismProgress.EventHandle, dismProgress.DismProgressCallbackNative, IntPtr.Zero);
+ AddPackage(state.session, state.packagePath, state.ignoreCheck, state.preventPending, progress);
- if (cancellationToken.IsCancellationRequested)
- {
- tcs.TrySetCanceled(cancellationToken);
- }
- else
- {
- DismUtilities.ThrowIfFail(hresult, session);
- tcs.TrySetResult(true);
- }
- }
- catch (OperationCanceledException)
- {
- tcs.TrySetCanceled(cancellationToken);
- }
- catch (Exception ex)
- {
- tcs.TrySetException(ex);
- }
- finally
- {
- ctsRegistration.Dispose();
- }
+ return true;
},
- CancellationToken.None,
- TaskCreationOptions.LongRunning,
- TaskScheduler.Default);
+ (session, packagePath, ignoreCheck, preventPending),
+ progress,
+ userData,
+ cancellationToken);
+ }
+
+ private static void AddPackage(DismSession session, string packagePath, bool ignoreCheck, bool preventPending, DismProgress progress)
+ {
+ int hresult = NativeMethods.DismAddPackage(session, packagePath, ignoreCheck, preventPending, progress.EventHandle, progress.DismProgressCallbackNative, IntPtr.Zero);
- return tcs.Task;
+ DismUtilities.ThrowIfFail(hresult, session);
}
-#endif
internal static partial class NativeMethods
{
@@ -143,19 +152,26 @@ internal static partial class NativeMethods
/// Optional. A pointer to a client-defined DismProgressCallback Function.
/// Optional. User defined custom data.
/// Returns S_OK on success.
- /// Only .cab files can be added to an online image. Either .cab or .msu files can be added to an offline image.
+ ///
+ /// Only .cab files can be added to an online image. Either .cab or .msu files can be added to an offline image.
///
- /// This function will return a special error code if the package is not applicable. You can use the DismGetPackageInfo Function to determine if a package is applicable to the target image.
- ///
- /// HRESULT WINAPI DismAddPackage (_In_ DismSession Session, _In_ PCWSTR PackagePath, _In_ BOOL IgnoreCheck, _In_ BOOL PreventPending _In_opt_ HANDLE CancelEvent, _In_opt_ DISM_PROGRESS_CALLBACK Progress, _In_opt_ PVOID UserData)
+ /// This function will return a special error code if the package is not applicable. You can use the DismGetPackageInfo Function to determine if a package is applicable to the target image. HRESULT WINAPI DismAddPackage (_In_ DismSession Session, _In_ PCWSTR PackagePath, _In_ BOOL IgnoreCheck, _In_ BOOL PreventPending _In_opt_ HANDLE CancelEvent, _In_opt_ DISM_PROGRESS_CALLBACK Progress, _In_opt_ PVOID UserData)
///
- #if NET7_0_OR_GREATER
+#if NET7_0_OR_GREATER
[LibraryImport(DismDllName, StringMarshalling = DismStringMarshalling)]
- public static partial int DismAddPackage(DismSession session, string packagePath, [MarshalAs(UnmanagedType.Bool)] bool ignoreCheck, [MarshalAs(UnmanagedType.Bool)] bool preventPending, SafeWaitHandle cancelEvent, DismProgressCallback progress, IntPtr userData);
- #else
+ public static partial
+#else
[DllImport(DismDllName, CharSet = DismCharacterSet)]
- public static extern int DismAddPackage(DismSession session, string packagePath, [MarshalAs(UnmanagedType.Bool)] bool ignoreCheck, [MarshalAs(UnmanagedType.Bool)] bool preventPending, SafeWaitHandle cancelEvent, DismProgressCallback progress, IntPtr userData);
- #endif
+ public static extern
+#endif
+ int DismAddPackage(
+ DismSession session,
+ string packagePath,
+ [MarshalAs(UnmanagedType.Bool)] bool ignoreCheck,
+ [MarshalAs(UnmanagedType.Bool)] bool preventPending,
+ SafeWaitHandle cancelEvent,
+ DismProgressCallbackNative progress,
+ IntPtr userData);
}
}
}
diff --git a/src/Microsoft.Dism/DismApi.AddProvisionedAppxPackage.cs b/src/Microsoft.Dism/DismApi.AddProvisionedAppxPackage.cs
index ecf1321..54eb674 100644
--- a/src/Microsoft.Dism/DismApi.AddProvisionedAppxPackage.cs
+++ b/src/Microsoft.Dism/DismApi.AddProvisionedAppxPackage.cs
@@ -122,28 +122,12 @@ internal static partial class NativeMethods
///
#if NET7_0_OR_GREATER
[LibraryImport(DismDllName, StringMarshalling = DismStringMarshalling)]
- public static partial int _DismAddProvisionedAppxPackage(
- DismSession Session,
- [MarshalAs(UnmanagedType.LPWStr)]
- string AppPath,
- [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 3)]
- string[] DependencyPackages,
- uint DependencyPackageCount,
- [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 5)]
- string[] OptionalPackages,
- uint OptionalPackageCount,
- [MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 7)]
- string[] LicensePaths,
- uint LicensePathCount,
- [MarshalAs(UnmanagedType.Bool)] bool SkipLicense,
- [MarshalAs(UnmanagedType.LPWStr)]
- string CustomDataPath,
- [MarshalAs(UnmanagedType.LPWStr)]
- string? Regions,
- DismStubPackageOption stubPackageOption);
- #else
+ public static partial
+#else
[DllImport(DismDllName, CharSet = DismCharacterSet)]
- public static extern int _DismAddProvisionedAppxPackage(
+ public static extern
+#endif
+ int _DismAddProvisionedAppxPackage(
DismSession Session,
[MarshalAs(UnmanagedType.LPWStr)]
string AppPath,
@@ -156,13 +140,12 @@ public static extern int _DismAddProvisionedAppxPackage(
[MarshalAs(UnmanagedType.LPArray, ArraySubType = UnmanagedType.LPWStr, SizeParamIndex = 7)]
string[] LicensePaths,
uint LicensePathCount,
- bool SkipLicense,
+ [MarshalAs(UnmanagedType.Bool)] bool SkipLicense,
[MarshalAs(UnmanagedType.LPWStr)]
string CustomDataPath,
[MarshalAs(UnmanagedType.LPWStr)]
string? Regions,
DismStubPackageOption stubPackageOption);
- #endif
}
}
}
\ No newline at end of file
diff --git a/src/Microsoft.Dism/DismApi.ApplyFfuImage.cs b/src/Microsoft.Dism/DismApi.ApplyFfuImage.cs
index 6bbb0a1..1657483 100644
--- a/src/Microsoft.Dism/DismApi.ApplyFfuImage.cs
+++ b/src/Microsoft.Dism/DismApi.ApplyFfuImage.cs
@@ -40,11 +40,15 @@ internal static partial class NativeMethods
/// Returns S_OK on success.
#if NET7_0_OR_GREATER
[LibraryImport(DismDllName, StringMarshalling = DismStringMarshalling)]
- public static partial int _DismApplyFfuImage([MarshalAs(UnmanagedType.LPWStr)] string ImagePath, [MarshalAs(UnmanagedType.LPWStr)] string ApplyPath, [MarshalAs(UnmanagedType.LPWStr)] string PartPath);
- #else
+ public static partial
+#else
[DllImport(DismDllName, CharSet = DismCharacterSet)]
- public static extern int _DismApplyFfuImage([MarshalAs(UnmanagedType.LPWStr)] string ImagePath, [MarshalAs(UnmanagedType.LPWStr)] string ApplyPath, [MarshalAs(UnmanagedType.LPWStr)] string PartPath);
- #endif
+ public static extern
+#endif
+ int _DismApplyFfuImage(
+ [MarshalAs(UnmanagedType.LPWStr)] string ImagePath,
+ [MarshalAs(UnmanagedType.LPWStr)] string ApplyPath,
+ [MarshalAs(UnmanagedType.LPWStr)] string PartPath);
}
}
}
\ No newline at end of file
diff --git a/src/Microsoft.Dism/DismApi.ApplyUnattend.cs b/src/Microsoft.Dism/DismApi.ApplyUnattend.cs
index 219e0b6..56a62f9 100644
--- a/src/Microsoft.Dism/DismApi.ApplyUnattend.cs
+++ b/src/Microsoft.Dism/DismApi.ApplyUnattend.cs
@@ -37,11 +37,15 @@ internal static partial class NativeMethods
///
#if NET7_0_OR_GREATER
[LibraryImport(DismDllName, StringMarshalling = DismStringMarshalling)]
- public static partial int DismApplyUnattend(DismSession session, string unattendFile, [MarshalAs(UnmanagedType.Bool)] bool singleSession);
- #else
+ public static partial
+#else
[DllImport(DismDllName, CharSet = DismCharacterSet)]
- public static extern int DismApplyUnattend(DismSession session, string unattendFile, [MarshalAs(UnmanagedType.Bool)] bool singleSession);
- #endif
+ public static extern
+#endif
+ int DismApplyUnattend(
+ DismSession session,
+ string unattendFile,
+ [MarshalAs(UnmanagedType.Bool)] bool singleSession);
}
}
}
\ No newline at end of file
diff --git a/src/Microsoft.Dism/DismApi.CheckImageHealth.cs b/src/Microsoft.Dism/DismApi.CheckImageHealth.cs
index f1ed48f..a707a7b 100644
--- a/src/Microsoft.Dism/DismApi.CheckImageHealth.cs
+++ b/src/Microsoft.Dism/DismApi.CheckImageHealth.cs
@@ -33,7 +33,7 @@ public static DismImageHealthState CheckImageHealth(DismSession session, bool sc
/// A indicating the health state of the image.
/// When a failure occurs.
/// When the user requested the operation be canceled.
- public static DismImageHealthState CheckImageHealth(DismSession session, bool scanImage, Microsoft.Dism.DismProgressCallback? progressCallback)
+ public static DismImageHealthState CheckImageHealth(DismSession session, bool scanImage, DismProgressCallback? progressCallback)
{
return CheckImageHealth(session, scanImage, progressCallback, userData: null);
}
@@ -48,76 +48,77 @@ public static DismImageHealthState CheckImageHealth(DismSession session, bool sc
/// A indicating the health state of the image.
/// When a failure occurs.
/// When the user requested the operation be canceled.
- public static DismImageHealthState CheckImageHealth(DismSession session, bool scanImage, Microsoft.Dism.DismProgressCallback? progressCallback, object? userData)
+ public static DismImageHealthState CheckImageHealth(DismSession session, bool scanImage, DismProgressCallback? progressCallback, object? userData)
{
// Create a DismProgress object to wrap the callback and allow cancellation
- DismProgress progress = new(progressCallback, userData);
+ using DismProgress progress = new(progressCallback, userData);
- int hresult = NativeMethods.DismCheckImageHealth(session, scanImage, progress.EventHandle, progress.DismProgressCallbackNative, IntPtr.Zero, out DismImageHealthState imageHealthState);
-
- DismUtilities.ThrowIfFail(hresult, session);
+ return CheckImageHealth(session, scanImage, progress);
+ }
- return imageHealthState;
+ ///
+ /// Asynchronously checks whether the image can be serviced or whether it is corrupted.
+ ///
+ /// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.
+ /// Specifies whether to scan the image or just check for flags from a previous scan.
+ /// A token to monitor for cancellation requests. The default value is .
+ /// A representing the asynchronous operation, containing the health state of the image.
+ /// When a failure occurs.
+ /// When the operation is canceled.
+ public static Task CheckImageHealthAsync(DismSession session, bool scanImage, CancellationToken cancellationToken = default)
+ {
+ return CheckImageHealthAsync(session, scanImage, progress: null, cancellationToken);
}
-#if !NET40
///
/// Asynchronously checks whether the image can be serviced or whether it is corrupted.
///
/// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.
/// Specifies whether to scan the image or just check for flags from a previous scan.
/// An optional progress provider to receive progress updates.
- /// A cancellation token to cancel the operation.
+ /// A token to monitor for cancellation requests. The default value is .
/// A representing the asynchronous operation, containing the health state of the image.
/// When a failure occurs.
/// When the operation is canceled.
- public static Task CheckImageHealthAsync(DismSession session, bool scanImage, IProgress? progress = null, CancellationToken cancellationToken = default)
+ public static Task CheckImageHealthAsync(DismSession session, bool scanImage, IProgress? progress, CancellationToken cancellationToken = default)
{
- TaskCompletionSource tcs = new();
-
- CancellationTokenRegistration ctsRegistration = default;
+ return CheckImageHealthAsync(session, scanImage, progress, userData: null, cancellationToken);
+ }
- Task.Factory.StartNew(
- () =>
+ ///
+ /// Asynchronously checks whether the image can be serviced or whether it is corrupted.
+ ///
+ /// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.
+ /// Specifies whether to scan the image or just check for flags from a previous scan.
+ /// An optional provider to receive progress updates.
+ /// Optional user data to pass to the specified .
+ /// A token to monitor for cancellation requests. The default value is .
+ /// A representing the asynchronous operation, containing the health state of the image.
+ /// When a failure occurs.
+ /// When the operation is canceled.
+ public static Task CheckImageHealthAsync(DismSession session, bool scanImage, IProgress? progress, object? userData, CancellationToken cancellationToken = default)
+ {
+ return DismUtilities.RunAsync(
+ static (state, progress) =>
{
- try
- {
- DismProgress dismProgress = new(progress != null ? p => progress.Report(p) : null, null);
+ DismImageHealthState imageHealthState = CheckImageHealth(state.session, state.scanImage, progress);
- ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
+ return imageHealthState;
+ },
+ (session, scanImage),
+ progress,
+ userData,
+ cancellationToken);
+ }
- int hresult = NativeMethods.DismCheckImageHealth(session, scanImage, dismProgress.EventHandle, dismProgress.DismProgressCallbackNative, IntPtr.Zero, out DismImageHealthState imageHealthState);
+ private static DismImageHealthState CheckImageHealth(DismSession session, bool scanImage, DismProgress progress)
+ {
+ int hresult = NativeMethods.DismCheckImageHealth(session, scanImage, progress.EventHandle, progress.DismProgressCallbackNative, IntPtr.Zero, out DismImageHealthState imageHealthState);
- if (cancellationToken.IsCancellationRequested)
- {
- tcs.TrySetCanceled(cancellationToken);
- }
- else
- {
- DismUtilities.ThrowIfFail(hresult, session);
- tcs.TrySetResult(imageHealthState);
- }
- }
- catch (OperationCanceledException)
- {
- tcs.TrySetCanceled(cancellationToken);
- }
- catch (Exception ex)
- {
- tcs.TrySetException(ex);
- }
- finally
- {
- ctsRegistration.Dispose();
- }
- },
- CancellationToken.None,
- TaskCreationOptions.LongRunning,
- TaskScheduler.Default);
+ DismUtilities.ThrowIfFail(hresult, session);
- return tcs.Task;
+ return imageHealthState;
}
-#endif
internal static partial class NativeMethods
{
@@ -131,18 +132,25 @@ internal static partial class NativeMethods
/// Optional. User defined custom data.
/// A pointer to the DismImageHealthState Enumeration. The enumeration value is set during this operation.
/// Returns S_OK on success.
- /// If ScanImage is set to True, this function will take longer to finish.
+ ///
+ /// If ScanImage is set to True, this function will take longer to finish.
///
- ///
- /// HRESULT WINAPI DismCheckImageHealth(_In_ DismSession Session, _In_ BOOL ScanImage, _In_opt_ HANDLE CancelEvent, _In_opt_ DISM_PROGRESS_CALLBACK Progress, _In_opt_ PVOID UserData, _Out_ DismImageHealthState* ImageHealth);
+ /// HRESULT WINAPI DismCheckImageHealth(_In_ DismSession Session, _In_ BOOL ScanImage, _In_opt_ HANDLE CancelEvent, _In_opt_ DISM_PROGRESS_CALLBACK Progress, _In_opt_ PVOID UserData, _Out_ DismImageHealthState* ImageHealth);
///
- #if NET7_0_OR_GREATER
+#if NET7_0_OR_GREATER
[LibraryImport(DismDllName, StringMarshalling = DismStringMarshalling)]
- public static partial int DismCheckImageHealth(DismSession session, [MarshalAs(UnmanagedType.Bool)] bool scanImage, SafeWaitHandle cancelEvent, DismProgressCallback progress, IntPtr userData, out DismImageHealthState imageHealth);
- #else
+ public static partial
+#else
[DllImport(DismDllName, CharSet = DismCharacterSet)]
- public static extern int DismCheckImageHealth(DismSession session, [MarshalAs(UnmanagedType.Bool)] bool scanImage, SafeWaitHandle cancelEvent, DismProgressCallback progress, IntPtr userData, out DismImageHealthState imageHealth);
- #endif
+ public static extern
+#endif
+ int DismCheckImageHealth(
+ DismSession session,
+ [MarshalAs(UnmanagedType.Bool)] bool scanImage,
+ SafeWaitHandle cancelEvent,
+ DismProgressCallbackNative progress,
+ IntPtr userData,
+ out DismImageHealthState imageHealth);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Microsoft.Dism/DismApi.CleanupMountpoints.cs b/src/Microsoft.Dism/DismApi.CleanupMountpoints.cs
index 44cc2d9..c99571d 100644
--- a/src/Microsoft.Dism/DismApi.CleanupMountpoints.cs
+++ b/src/Microsoft.Dism/DismApi.CleanupMountpoints.cs
@@ -30,11 +30,12 @@ internal static partial class NativeMethods
/// HRESULT WINAPI DismCleanupMountpoints( );
#if NET7_0_OR_GREATER
[LibraryImport(DismDllName, StringMarshalling = DismStringMarshalling)]
- public static partial int DismCleanupMountpoints();
- #else
+ public static partial
+#else
[DllImport(DismDllName, CharSet = DismCharacterSet)]
- public static extern int DismCleanupMountpoints();
- #endif
+ public static extern
+#endif
+ int DismCleanupMountpoints();
}
}
}
\ No newline at end of file
diff --git a/src/Microsoft.Dism/DismApi.CloseSession.cs b/src/Microsoft.Dism/DismApi.CloseSession.cs
index f32b035..0f82da8 100644
--- a/src/Microsoft.Dism/DismApi.CloseSession.cs
+++ b/src/Microsoft.Dism/DismApi.CloseSession.cs
@@ -38,11 +38,13 @@ internal static partial class NativeMethods
/// HRESULT WINAPI DismCloseSession(_In_ DismSession Session);
#if NET7_0_OR_GREATER
[LibraryImport(DismDllName, StringMarshalling = DismStringMarshalling)]
- public static partial int DismCloseSession(IntPtr session);
- #else
+ public static partial
+#else
[DllImport(DismDllName, CharSet = DismCharacterSet)]
- public static extern int DismCloseSession(IntPtr session);
- #endif
+ public static extern
+#endif
+ int DismCloseSession(
+ IntPtr session);
}
}
}
\ No newline at end of file
diff --git a/src/Microsoft.Dism/DismApi.CommitImage.cs b/src/Microsoft.Dism/DismApi.CommitImage.cs
index 37d79fa..79bc7f4 100644
--- a/src/Microsoft.Dism/DismApi.CommitImage.cs
+++ b/src/Microsoft.Dism/DismApi.CommitImage.cs
@@ -16,7 +16,7 @@ public static partial class DismApi
/// Commits the changes made to a Windows® image in a mounted .wim or .vhd file.
///
/// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the method.
- /// true or false to discard changes made to the image.
+ /// to discard changes made to the image, otherwise to keep changes made to the image.
/// When a failure occurs.
public static void CommitImage(DismSession session, bool discardChanges)
{
@@ -27,11 +27,11 @@ public static void CommitImage(DismSession session, bool discardChanges)
/// Commits the changes made to a Windows® image in a mounted .wim or .vhd file.
///
/// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the method.
- /// true or false to discard changes made to the image.
+ /// to discard changes made to the image, otherwise to keep changes made to the image.
/// A progress callback method to invoke when progress is made.
/// When a failure occurs.
/// When the user requested the operation be canceled.
- public static void CommitImage(DismSession session, bool discardChanges, Microsoft.Dism.DismProgressCallback? progressCallback)
+ public static void CommitImage(DismSession session, bool discardChanges, DismProgressCallback? progressCallback)
{
CommitImage(session, discardChanges, progressCallback, userData: null);
}
@@ -40,84 +40,81 @@ public static void CommitImage(DismSession session, bool discardChanges, Microso
/// Commits the changes made to a Windows® image in a mounted .wim or .vhd file.
///
/// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the method.
- /// true or false to discard changes made to the image.
+ /// to discard changes made to the image, otherwise to keep changes made to the image.
/// A progress callback method to invoke when progress is made.
/// Optional user data to pass to the DismProgressCallback method.
/// When a failure occurs.
/// When the user requested the operation be canceled.
- public static void CommitImage(DismSession session, bool discardChanges, Microsoft.Dism.DismProgressCallback? progressCallback, object? userData)
+ public static void CommitImage(DismSession session, bool discardChanges, DismProgressCallback? progressCallback, object? userData)
{
- // Create the flags
- UInt32 flags = discardChanges ? DISM_DISCARD_IMAGE : DISM_COMMIT_IMAGE;
-
- // Create a DismProgress object to wrap the callback and allow cancellation
- DismProgress progress = new(progressCallback, userData);
+ using DismProgress progress = new(progressCallback, userData);
- int hresult = NativeMethods.DismCommitImage(session, flags, progress.EventHandle, progress.DismProgressCallbackNative, IntPtr.Zero);
-
- DismUtilities.ThrowIfFail(hresult, session);
+ CommitImage(session, discardChanges, progress);
}
-#if !NET40
///
/// Asynchronously commits the changes made to a Windows® image in a mounted .wim or .vhd file.
///
/// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the method.
- /// true or false to discard changes made to the image.
- /// An optional progress provider to receive progress updates.
- /// A cancellation token to cancel the operation.
+ /// to discard changes made to the image, otherwise to keep changes made to the image.
+ /// A token to monitor for cancellation requests. The default value is .
/// A representing the asynchronous operation.
/// When a failure occurs.
/// When the operation is canceled.
- public static Task CommitImageAsync(DismSession session, bool discardChanges, IProgress? progress = null, CancellationToken cancellationToken = default)
+ public static Task CommitImageAsync(DismSession session, bool discardChanges, CancellationToken cancellationToken = default)
{
- TaskCompletionSource tcs = new();
+ return CommitImageAsync(session, discardChanges, progress: null, cancellationToken);
+ }
- CancellationTokenRegistration ctsRegistration = default;
+ ///
+ /// Asynchronously commits the changes made to a Windows® image in a mounted .wim or .vhd file.
+ ///
+ /// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the method.
+ /// to discard changes made to the image, otherwise to keep changes made to the image.
+ /// An optional provider to receive progress updates.
+ /// A token to monitor for cancellation requests. The default value is .
+ /// A representing the asynchronous operation.
+ /// When a failure occurs.
+ /// When the operation is canceled.
+ public static Task CommitImageAsync(DismSession session, bool discardChanges, IProgress? progress, CancellationToken cancellationToken = default)
+ {
+ return CommitImageAsync(session, discardChanges, progress, userData: null, cancellationToken);
+ }
- Task.Factory.StartNew(
- () =>
+ ///
+ /// Asynchronously commits the changes made to a Windows® image in a mounted .wim or .vhd file.
+ ///
+ /// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the method.
+ /// to discard changes made to the image, otherwise to keep changes made to the image.
+ /// An optional provider to receive progress updates.
+ /// Optional user data to pass to the specified .
+ /// A token to monitor for cancellation requests. The default value is .
+ /// A representing the asynchronous operation.
+ /// When a failure occurs.
+ /// When the operation is canceled.
+ public static Task CommitImageAsync(DismSession session, bool discardChanges, IProgress? progress, object? userData, CancellationToken cancellationToken = default)
+ {
+ return DismUtilities.RunAsync(
+ static (state, progress) =>
{
- try
- {
- UInt32 flags = discardChanges ? DISM_DISCARD_IMAGE : DISM_COMMIT_IMAGE;
+ CommitImage(state.session, state.discardChanges, progress);
- DismProgress dismProgress = new(progress != null ? p => progress.Report(p) : null, null);
-
- ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
+ return true;
+ },
+ (session, discardChanges),
+ progress,
+ userData,
+ cancellationToken);
+ }
- int hresult = NativeMethods.DismCommitImage(session, flags, dismProgress.EventHandle, dismProgress.DismProgressCallbackNative, IntPtr.Zero);
+ private static void CommitImage(DismSession session, bool discardChanges, DismProgress progress)
+ {
+ UInt32 flags = discardChanges ? DISM_DISCARD_IMAGE : DISM_COMMIT_IMAGE;
- if (cancellationToken.IsCancellationRequested)
- {
- tcs.TrySetCanceled(cancellationToken);
- }
- else
- {
- DismUtilities.ThrowIfFail(hresult, session);
- tcs.TrySetResult(true);
- }
- }
- catch (OperationCanceledException)
- {
- tcs.TrySetCanceled(cancellationToken);
- }
- catch (Exception ex)
- {
- tcs.TrySetException(ex);
- }
- finally
- {
- ctsRegistration.Dispose();
- }
- },
- CancellationToken.None,
- TaskCreationOptions.LongRunning,
- TaskScheduler.Default);
+ int hresult = NativeMethods.DismCommitImage(session, flags, progress.EventHandle, progress.DismProgressCallbackNative, IntPtr.Zero);
- return tcs.Task;
+ DismUtilities.ThrowIfFail(hresult, session);
}
-#endif
internal static partial class NativeMethods
{
@@ -130,19 +127,24 @@ internal static partial class NativeMethods
/// Optional. A pointer to a client-defined DismProgressCallback Function.
/// Optional. User defined custom data.
/// Returns S_OK on success.
- /// The DismCommitImage function does not unmount the image.
+ ///
+ /// The DismCommitImage function does not unmount the image.
/// DismCommitImage can only be used on an image that is mounted within the DISM infrastructure. It does not apply to images mounted by another tool, such as the DiskPart tool, which are serviced using the DismOpenSession Function. You must use the DismMountImage Function to mount an image within the DISM infrastructure.
- ///
- ///
- /// HRESULT WINAPI DismCommitImage(_In_ DismSession Session, _In_ DWORD Flags, _In_opt_ HANDLE CancelEvent, _In_opt_ DISM_PROGRESS_CALLBACK Progress, _In_opt_ PVOID UserData);
+ /// HRESULT WINAPI DismCommitImage(_In_ DismSession Session, _In_ DWORD Flags, _In_opt_ HANDLE CancelEvent, _In_opt_ DISM_PROGRESS_CALLBACK Progress, _In_opt_ PVOID UserData);
///
- #if NET7_0_OR_GREATER
+#if NET7_0_OR_GREATER
[LibraryImport(DismDllName, StringMarshalling = DismStringMarshalling)]
- public static partial int DismCommitImage(DismSession session, UInt32 flags, SafeWaitHandle cancelEvent, DismProgressCallback progress, IntPtr userData);
- #else
+ public static partial
+#else
[DllImport(DismDllName, CharSet = DismCharacterSet)]
- public static extern int DismCommitImage(DismSession session, UInt32 flags, SafeWaitHandle cancelEvent, DismProgressCallback progress, IntPtr userData);
- #endif
+ public static extern
+#endif
+ int DismCommitImage(
+ DismSession session,
+ UInt32 flags,
+ SafeWaitHandle cancelEvent,
+ DismProgressCallbackNative progress,
+ IntPtr userData);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Microsoft.Dism/DismApi.Delete.cs b/src/Microsoft.Dism/DismApi.Delete.cs
index 20359d4..d8e2eba 100644
--- a/src/Microsoft.Dism/DismApi.Delete.cs
+++ b/src/Microsoft.Dism/DismApi.Delete.cs
@@ -33,11 +33,13 @@ internal static partial class NativeMethods
///
#if NET7_0_OR_GREATER
[LibraryImport(DismDllName, StringMarshalling = DismStringMarshalling)]
- public static partial int DismDelete(IntPtr dismStructure);
- #else
+ public static partial
+#else
[DllImport(DismDllName, CharSet = DismCharacterSet)]
- public static extern int DismDelete(IntPtr dismStructure);
- #endif
+ public static extern
+#endif
+ int DismDelete(
+ IntPtr dismStructure);
}
}
}
\ No newline at end of file
diff --git a/src/Microsoft.Dism/DismApi.DisableFeature.cs b/src/Microsoft.Dism/DismApi.DisableFeature.cs
index e25a0ce..33ac004 100644
--- a/src/Microsoft.Dism/DismApi.DisableFeature.cs
+++ b/src/Microsoft.Dism/DismApi.DisableFeature.cs
@@ -17,9 +17,11 @@ public static partial class DismApi
///
/// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.
/// The name of the feature that you want to disable. To disable more than one feature, separate each feature name with a semicolon.
- /// Optional. The name of the parent package that the feature is a part of.
+ ///
+ /// Optional. The name of the parent package that the feature is a part of.
///
- /// This is an optional parameter. If no package is specified, then the default Windows® Foundation package is used.
+ /// This is an optional parameter. If no package is specified, then the default Windows® Foundation package is used.
+ ///
/// Specifies whether to remove the files required to enable the feature.
/// When a failure occurs.
/// When the operation requires a reboot to complete.
@@ -33,15 +35,17 @@ public static void DisableFeature(DismSession session, string featureName, strin
///
/// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.
/// The name of the feature that you want to disable. To disable more than one feature, separate each feature name with a semicolon.
- /// Optional. The name of the parent package that the feature is a part of.
+ ///
+ /// Optional. The name of the parent package that the feature is a part of.
///
- /// This is an optional parameter. If no package is specified, then the default Windows® Foundation package is used.
+ /// This is an optional parameter. If no package is specified, then the default Windows® Foundation package is used.
+ ///
/// Specifies whether to remove the files required to enable the feature.
/// A progress callback method to invoke when progress is made.
/// When a failure occurs.
/// When the user requested the operation be canceled.
/// When the operation requires a reboot to complete.
- public static void DisableFeature(DismSession session, string featureName, string packageName, bool removePayload, Microsoft.Dism.DismProgressCallback? progressCallback)
+ public static void DisableFeature(DismSession session, string featureName, string packageName, bool removePayload, DismProgressCallback? progressCallback)
{
DisableFeature(session, featureName, packageName, removePayload, progressCallback, userData: null);
}
@@ -51,88 +55,107 @@ public static void DisableFeature(DismSession session, string featureName, strin
///
/// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.
/// The name of the feature that you want to disable. To disable more than one feature, separate each feature name with a semicolon.
- /// Optional. The name of the parent package that the feature is a part of.
+ ///
+ /// Optional. The name of the parent package that the feature is a part of.
///
- /// This is an optional parameter. If no package is specified, then the default Windows® Foundation package is used.
+ /// This is an optional parameter. If no package is specified, then the default Windows® Foundation package is used.
+ ///
/// Specifies whether to remove the files required to enable the feature.
/// A progress callback method to invoke when progress is made.
/// Optional user data to pass to the DismProgressCallback method.
/// When a failure occurs.
/// When the user requested the operation be canceled.
/// When the operation requires a reboot to complete.
- public static void DisableFeature(DismSession session, string featureName, string packageName, bool removePayload, Microsoft.Dism.DismProgressCallback? progressCallback, object? userData)
+ public static void DisableFeature(DismSession session, string featureName, string packageName, bool removePayload, DismProgressCallback? progressCallback, object? userData)
{
// Create a DismProgress object to wrap the callback and allow cancellation
- DismProgress progress = new(progressCallback, userData);
+ using DismProgress progress = new(progressCallback, userData);
- int hresult = NativeMethods.DismDisableFeature(session, featureName, packageName, removePayload, progress.EventHandle, progress.DismProgressCallbackNative, IntPtr.Zero);
-
- DismUtilities.ThrowIfFail(hresult, session);
+ DisableFeature(session, featureName, packageName, removePayload, progress);
}
-#if !NET40
///
/// Asynchronously disables a feature in the current image.
///
/// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.
/// The name of the feature that you want to disable. To disable more than one feature, separate each feature name with a semicolon.
- /// Optional. The name of the parent package that the feature is a part of.
+ ///
+ /// Optional. The name of the parent package that the feature is a part of.
///
- /// This is an optional parameter. If no package is specified, then the default Windows® Foundation package is used.
+ /// This is an optional parameter. If no package is specified, then the default Windows® Foundation package is used.
+ ///
/// Specifies whether to remove the files required to enable the feature.
- /// An optional progress provider to receive progress updates.
- /// A cancellation token to cancel the operation.
+ /// A token to monitor for cancellation requests. The default value is .
/// A representing the asynchronous operation.
/// When a failure occurs.
/// When the operation is canceled.
/// When the operation requires a reboot to complete.
- public static Task DisableFeatureAsync(DismSession session, string featureName, string packageName, bool removePayload, IProgress? progress = null, CancellationToken cancellationToken = default)
+ public static Task DisableFeatureAsync(DismSession session, string featureName, string packageName, bool removePayload, CancellationToken cancellationToken = default)
{
- TaskCompletionSource tcs = new();
+ return DisableFeatureAsync(session, featureName, packageName, removePayload, progress: null, cancellationToken);
+ }
- CancellationTokenRegistration ctsRegistration = default;
+ ///
+ /// Asynchronously disables a feature in the current image.
+ ///
+ /// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.
+ /// The name of the feature that you want to disable. To disable more than one feature, separate each feature name with a semicolon.
+ ///
+ /// Optional. The name of the parent package that the feature is a part of.
+ ///
+ /// This is an optional parameter. If no package is specified, then the default Windows® Foundation package is used.
+ ///
+ /// Specifies whether to remove the files required to enable the feature.
+ /// An optional provider to receive progress updates.
+ /// A token to monitor for cancellation requests. The default value is .
+ /// A representing the asynchronous operation.
+ /// When a failure occurs.
+ /// When the operation is canceled.
+ /// When the operation requires a reboot to complete.
+ public static Task DisableFeatureAsync(DismSession session, string featureName, string packageName, bool removePayload, IProgress? progress, CancellationToken cancellationToken = default)
+ {
+ return DisableFeatureAsync(session, featureName, packageName, removePayload, progress, userData: null, cancellationToken);
+ }
- Task.Factory.StartNew(
- () =>
+ ///
+ /// Asynchronously disables a feature in the current image.
+ ///
+ /// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.
+ /// The name of the feature that you want to disable. To disable more than one feature, separate each feature name with a semicolon.
+ ///
+ /// Optional. The name of the parent package that the feature is a part of.
+ ///
+ /// This is an optional parameter. If no package is specified, then the default Windows® Foundation package is used.
+ ///
+ /// Specifies whether to remove the files required to enable the feature.
+ /// An optional provider to receive progress updates.
+ /// Optional user data to pass to the specified .
+ /// A token to monitor for cancellation requests. The default value is .
+ /// A representing the asynchronous operation.
+ /// When a failure occurs.
+ /// When the operation is canceled.
+ /// When the operation requires a reboot to complete.
+ public static Task DisableFeatureAsync(DismSession session, string featureName, string packageName, bool removePayload, IProgress? progress, object? userData, CancellationToken cancellationToken = default)
+ {
+ return DismUtilities.RunAsync(
+ static (state, progress) =>
{
- try
- {
- DismProgress dismProgress = new(progress != null ? p => progress.Report(p) : null, null);
+ DisableFeature(state.session, state.featureName, state.packageName, state.removePayload, progress);
- ctsRegistration = cancellationToken.Register(() => dismProgress.Cancel = true);
-
- int hresult = NativeMethods.DismDisableFeature(session, featureName, packageName, removePayload, dismProgress.EventHandle, dismProgress.DismProgressCallbackNative, IntPtr.Zero);
-
- if (cancellationToken.IsCancellationRequested)
- {
- tcs.TrySetCanceled(cancellationToken);
- }
- else
- {
- DismUtilities.ThrowIfFail(hresult, session);
- tcs.TrySetResult(true);
- }
- }
- catch (OperationCanceledException)
- {
- tcs.TrySetCanceled(cancellationToken);
- }
- catch (Exception ex)
- {
- tcs.TrySetException(ex);
- }
- finally
- {
- ctsRegistration.Dispose();
- }
+ return true;
},
- CancellationToken.None,
- TaskCreationOptions.LongRunning,
- TaskScheduler.Default);
+ (session, featureName, packageName, removePayload),
+ progress,
+ userData,
+ cancellationToken);
+ }
- return tcs.Task;
+ private static void DisableFeature(DismSession session, string featureName, string packageName, bool removePayload, DismProgress progress)
+ {
+ int hresult = NativeMethods.DismDisableFeature(session, featureName, packageName, removePayload, progress.EventHandle, progress.DismProgressCallbackNative, IntPtr.Zero);
+
+ DismUtilities.ThrowIfFail(hresult, session);
}
-#endif
internal static partial class NativeMethods
{
@@ -141,25 +164,32 @@ internal static partial class NativeMethods
///
/// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.
/// The name of the feature that you want to disable. To disable more than one feature, separate each feature name with a semicolon.
- /// Optional. The name of the parent package that the feature is a part of.
+ ///
+ /// Optional. The name of the parent package that the feature is a part of.
///
- /// This is an optional parameter. If no package is specified, then the default Windows® Foundation package is used.
+ /// This is an optional parameter. If no package is specified, then the default Windows® Foundation package is used.
+ ///
/// A Boolean value specifying whether to remove the files required to enable the feature.
/// Optional. You can set a CancelEvent for this function in order to cancel the operation in progress when signaled by the client. If the CancelEvent is received at a stage when the operation cannot be canceled, the operation will continue and return a success code. If the CancelEvent is received and the operation is canceled, the image state is unknown. You should verify the image state before continuing or discard the changes and start again.
/// Optional. A pointer to a client-defined DismProgressCallback Function.
/// Optional. User specified data.
/// Returns S_OK on success.
- ///
- ///
- /// HRESULT WINAPI DismDisableFeature (_In_ DismSession Session, _In_ PCWSTR FeatureName, _In_opt_ PCWSTR PackageName, _In_ BOOL RemovePayload, _In_opt_ HANDLE CancelEvent, _In_opt_ DISM_PROGRESS_CALLBACK Progress, _In_opt_ PVOID UserData);
- ///
- #if NET7_0_OR_GREATER
+ /// HRESULT WINAPI DismDisableFeature (_In_ DismSession Session, _In_ PCWSTR FeatureName, _In_opt_ PCWSTR PackageName, _In_ BOOL RemovePayload, _In_opt_ HANDLE CancelEvent, _In_opt_ DISM_PROGRESS_CALLBACK Progress, _In_opt_ PVOID UserData);
+#if NET7_0_OR_GREATER
[LibraryImport(DismDllName, StringMarshalling = DismStringMarshalling)]
- public static partial int DismDisableFeature(DismSession session, string featureName, string packageName, [MarshalAs(UnmanagedType.Bool)] bool removePayload, SafeWaitHandle cancelEvent, DismProgressCallback progress, IntPtr userData);
- #else
+ public static partial
+#else
[DllImport(DismDllName, CharSet = DismCharacterSet)]
- public static extern int DismDisableFeature(DismSession session, string featureName, string packageName, [MarshalAs(UnmanagedType.Bool)] bool removePayload, SafeWaitHandle cancelEvent, DismProgressCallback progress, IntPtr userData);
- #endif
+ public static extern
+#endif
+ int DismDisableFeature(
+ DismSession session,
+ string featureName,
+ string packageName,
+ [MarshalAs(UnmanagedType.Bool)] bool removePayload,
+ SafeWaitHandle cancelEvent,
+ DismProgressCallbackNative progress,
+ IntPtr userData);
}
}
-}
\ No newline at end of file
+}
diff --git a/src/Microsoft.Dism/DismApi.EnableFeature.cs b/src/Microsoft.Dism/DismApi.EnableFeature.cs
index bfb9e9b..a390e49 100644
--- a/src/Microsoft.Dism/DismApi.EnableFeature.cs
+++ b/src/Microsoft.Dism/DismApi.EnableFeature.cs
@@ -13,6 +13,127 @@ namespace Microsoft.Dism
{
public static partial class DismApi
{
+ ///
+ /// Enables a feature from the specified package path.
+ ///
+ /// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.
+ /// The name of the feature that is being enabled. To enable more than one feature, separate each feature name with a semicolon.
+ /// Specifies whether Windows Update (WU) should be contacted as a source location for downloading files if none are found in other specified locations. Before checking WU, DISM will check for the files in the SourcePaths provided and in any locations specified in the registry by group policy. If the files required to enable the feature are still present on the computer, this flag is ignored.
+ /// Specifies whether to enable all dependencies of the feature. If the specified feature or any one of its dependencies cannot be enabled, none of them will be changed from their existing state.
+ /// When a failure occurs.
+ public static void EnableFeature(DismSession session, string featureName, bool limitAccess, bool enableAll)
+ {
+ EnableFeature(session, featureName, identifier: null, DismPackageIdentifier.None, limitAccess, enableAll, sourcePaths: null, progressCallback: null, userData: null);
+ }
+
+ ///
+ /// Enables a feature from the specified package path.
+ ///
+ /// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.
+ /// The name of the feature that is being enabled. To enable more than one feature, separate each feature name with a semicolon.
+ /// Specifies whether Windows Update (WU) should be contacted as a source location for downloading files if none are found in other specified locations. Before checking WU, DISM will check for the files in the SourcePaths provided and in any locations specified in the registry by group policy. If the files required to enable the feature are still present on the computer, this flag is ignored.
+ /// Specifies whether to enable all dependencies of the feature. If the specified feature or any one of its dependencies cannot be enabled, none of them will be changed from their existing state.
+ /// A list of source locations to check for files needed to enable the feature.
+ /// When a failure occurs.
+ public static void EnableFeature(DismSession session, string featureName, bool limitAccess, bool enableAll, List? sourcePaths)
+ {
+ EnableFeature(session, featureName, identifier: null, DismPackageIdentifier.None, limitAccess, enableAll, sourcePaths, progressCallback: null, userData: null);
+ }
+
+ ///
+ /// Enables a feature from the specified package path.
+ ///
+ /// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.
+ /// The name of the feature that is being enabled. To enable more than one feature, separate each feature name with a semicolon.
+ /// Specifies whether Windows Update (WU) should be contacted as a source location for downloading files if none are found in other specified locations. Before checking WU, DISM will check for the files in the SourcePaths provided and in any locations specified in the registry by group policy. If the files required to enable the feature are still present on the computer, this flag is ignored.
+ /// Specifies whether to enable all dependencies of the feature. If the specified feature or any one of its dependencies cannot be enabled, none of them will be changed from their existing state.
+ /// A list of source locations to check for files needed to enable the feature.
+ /// A progress callback method to invoke when progress is made.
+ /// When a failure occurs.
+ public static void EnableFeature(DismSession session, string featureName, bool limitAccess, bool enableAll, List? sourcePaths, DismProgressCallback? progressCallback)
+ {
+ EnableFeature(session, featureName, identifier: null, DismPackageIdentifier.None, limitAccess, enableAll, sourcePaths, progressCallback, userData: null);
+ }
+
+ ///
+ /// Enables a feature from the specified package path.
+ ///
+ /// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.
+ /// The name of the feature that is being enabled. To enable more than one feature, separate each feature name with a semicolon.
+ /// Specifies whether Windows Update (WU) should be contacted as a source location for downloading files if none are found in other specified locations. Before checking WU, DISM will check for the files in the SourcePaths provided and in any locations specified in the registry by group policy. If the files required to enable the feature are still present on the computer, this flag is ignored.
+ /// Specifies whether to enable all dependencies of the feature. If the specified feature or any one of its dependencies cannot be enabled, none of them will be changed from their existing state.
+ /// A list of source locations to check for files needed to enable the feature.
+ /// A progress callback method to invoke when progress is made.
+ /// Optional user data to pass to the DismProgressCallback method.
+ /// When a failure occurs.
+ public static void EnableFeature(DismSession session, string featureName, bool limitAccess, bool enableAll, List? sourcePaths, DismProgressCallback? progressCallback, object? userData)
+ {
+ EnableFeature(session, featureName, identifier: null, DismPackageIdentifier.None, limitAccess, enableAll, sourcePaths, progressCallback, userData);
+ }
+
+ ///
+ /// Enables a feature from the specified package path.
+ ///
+ /// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.
+ /// The name of the feature that is being enabled. To enable more than one feature, separate each feature name with a semicolon.
+ /// Specifies whether Windows Update (WU) should be contacted as a source location for downloading files if none are found in other specified locations. Before checking WU, DISM will check for the files in the SourcePaths provided and in any locations specified in the registry by group policy. If the files required to enable the feature are still present on the computer, this flag is ignored.
+ /// Specifies whether to enable all dependencies of the feature. If the specified feature or any one of its dependencies cannot be enabled, none of them will be changed from their existing state.
+ /// token to monitor for cancellation requests. The default value is .
+ /// When a failure occurs.
+ public static Task EnableFeatureAsync(DismSession session, string featureName, bool limitAccess, bool enableAll, CancellationToken cancellationToken = default)
+ {
+ return EnableFeatureAsync(session, featureName, limitAccess, enableAll, sourcePaths: null, cancellationToken);
+ }
+
+ ///
+ /// Enables a feature from the specified package path.
+ ///
+ /// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.
+ /// The name of the feature that is being enabled. To enable more than one feature, separate each feature name with a semicolon.
+ /// Specifies whether Windows Update (WU) should be contacted as a source location for downloading files if none are found in other specified locations. Before checking WU, DISM will check for the files in the SourcePaths provided and in any locations specified in the registry by group policy. If the files required to enable the feature are still present on the computer, this flag is ignored.
+ /// Specifies whether to enable all dependencies of the feature. If the specified feature or any one of its dependencies cannot be enabled, none of them will be changed from their existing state.
+ /// A list of source locations to check for files needed to enable the feature.
+ /// token to monitor for cancellation requests. The default value is .
+ /// When a failure occurs.
+ public static Task EnableFeatureAsync(DismSession session, string featureName, bool limitAccess, bool enableAll, List? sourcePaths, CancellationToken cancellationToken = default)
+ {
+ return EnableFeatureAsync(session, featureName, limitAccess, enableAll, sourcePaths, progress: null, cancellationToken);
+ }
+
+ ///
+ /// Enables a feature from the specified package path.
+ ///
+ /// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.
+ /// The name of the feature that is being enabled. To enable more than one feature, separate each feature name with a semicolon.
+ /// Specifies whether Windows Update (WU) should be contacted as a source location for downloading files if none are found in other specified locations. Before checking WU, DISM will check for the files in the SourcePaths provided and in any locations specified in the registry by group policy. If the files required to enable the feature are still present on the computer, this flag is ignored.
+ /// Specifies whether to enable all dependencies of the feature. If the specified feature or any one of its dependencies cannot be enabled, none of them will be changed from their existing state.
+ /// A list of source locations to check for files needed to enable the feature.
+ /// An optional provider to receive progress updates.
+ /// token to monitor for cancellation requests. The default value is .
+ /// When a failure occurs.
+ public static Task EnableFeatureAsync(DismSession session, string featureName, bool limitAccess, bool enableAll, List? sourcePaths, IProgress? progress, CancellationToken cancellationToken = default)
+ {
+ return EnableFeatureAsync(session, featureName, limitAccess, enableAll, sourcePaths, progress, userData: null, cancellationToken);
+ }
+
+ ///
+ /// Enables a feature from the specified package path.
+ ///
+ /// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.
+ /// The name of the feature that is being enabled. To enable more than one feature, separate each feature name with a semicolon.
+ /// Specifies whether Windows Update (WU) should be contacted as a source location for downloading files if none are found in other specified locations. Before checking WU, DISM will check for the files in the SourcePaths provided and in any locations specified in the registry by group policy. If the files required to enable the feature are still present on the computer, this flag is ignored.
+ /// Specifies whether to enable all dependencies of the feature. If the specified feature or any one of its dependencies cannot be enabled, none of them will be changed from their existing state.
+ /// A list of source locations to check for files needed to enable the feature.
+ /// An optional provider to receive progress updates.
+ /// Optional user data to pass to the specified .
+ /// token to monitor for cancellation requests. The default value is .
+ /// A that represents the asynchronous operation.
+ /// When a failure occurs.
+ public static Task EnableFeatureAsync(DismSession session, string featureName, bool limitAccess, bool enableAll, List? sourcePaths, IProgress? progress, object? userData, CancellationToken cancellationToken = default)
+ {
+ return EnableFeatureAsync(session, featureName, identifier: null, DismPackageIdentifier.None, limitAccess, enableAll, sourcePaths, progress, userData, cancellationToken);
+ }
+
///
/// Enables a feature from the specified package name.
///
@@ -57,7 +178,7 @@ public static void EnableFeatureByPackageName(DismSession session, string featur
/// When a failure occurs.
/// When the user requested the operation be canceled.
/// When the operation requires a reboot to complete.
- public static void EnableFeatureByPackageName(DismSession session, string featureName, string packageName, bool limitAccess, bool enableAll, List? sourcePaths, Microsoft.Dism.DismProgressCallback? progressCallback)
+ public static void EnableFeatureByPackageName(DismSession session, string featureName, string packageName, bool limitAccess, bool enableAll, List? sourcePaths, DismProgressCallback? progressCallback)
{
EnableFeatureByPackageName(session, featureName, packageName, limitAccess, enableAll, sourcePaths, progressCallback, null);
}
@@ -76,77 +197,87 @@ public static void EnableFeatureByPackageName(DismSession session, string featur
/// When a failure occurs.
/// When the user requested the operation be canceled.
/// When the operation requires a reboot to complete.
- public static void EnableFeatureByPackageName(DismSession session, string featureName, string packageName, bool limitAccess, bool enableAll, List? sourcePaths, Microsoft.Dism.DismProgressCallback? progressCallback, object? userData)
+ public static void EnableFeatureByPackageName(DismSession session, string featureName, string packageName, bool limitAccess, bool enableAll, List? sourcePaths, DismProgressCallback? progressCallback, object? userData)
{
EnableFeature(session, featureName, packageName, DismPackageIdentifier.Name, limitAccess, enableAll, sourcePaths, progressCallback, userData);
}
///
- /// Enables a feature from the specified package path.
+ /// Enables a feature from the specified package name.
///
/// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.
/// The name of the feature that is being enabled. To enable more than one feature, separate each feature name with a semicolon.
- /// The path of the package that contains the feature.
+ /// The name of the package that contains the feature.
/// Specifies whether Windows Update (WU) should be contacted as a source location for downloading files if none are found in other specified locations. Before checking WU, DISM will check for the files in the SourcePaths provided and in any locations specified in the registry by group policy. If the files required to enable the feature are still present on the computer, this flag is ignored.
/// Specifies whether to enable all dependencies of the feature. If the specified feature or any one of its dependencies cannot be enabled, none of them will be changed from their existing state.
+ /// The token to monitor for cancellation requests. The default value is .
+ /// A that represents the asynchronous operation.
/// When a failure occurs.
+ /// When the user requested the operation be canceled.
/// When the operation requires a reboot to complete.
- public static void EnableFeatureByPackagePath(DismSession session, string featureName, string packagePath, bool limitAccess, bool enableAll)
+ public static Task EnableFeatureByPackageNameAsync(DismSession session, string featureName, string packageName, bool limitAccess, bool enableAll, CancellationToken cancellationToken = default)
{
- EnableFeatureByPackagePath(session, featureName, packagePath, limitAccess, enableAll, sourcePaths: null, progressCallback: null);
+ return EnableFeatureByPackageNameAsync(session, featureName, packageName, limitAccess, enableAll, sourcePaths: null, cancellationToken);
}
///
- /// Enables a feature from the specified package path.
+ /// Enables a feature from the specified package name.
///
/// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.
/// The name of the feature that is being enabled. To enable more than one feature, separate each feature name with a semicolon.
- /// The path of the package that contains the feature.
+ /// The name of the package that contains the feature.
/// Specifies whether Windows Update (WU) should be contacted as a source location for downloading files if none are found in other specified locations. Before checking WU, DISM will check for the files in the SourcePaths provided and in any locations specified in the registry by group policy. If the files required to enable the feature are still present on the computer, this flag is ignored.
/// Specifies whether to enable all dependencies of the feature. If the specified feature or any one of its dependencies cannot be enabled, none of them will be changed from their existing state.
/// A list of source locations to check for files needed to enable the feature.
+ /// The token to monitor for cancellation requests. The default value is .
+ /// A that represents the asynchronous operation.
/// When a failure occurs.
+ /// When the user requested the operation be canceled.
/// When the operation requires a reboot to complete.
- public static void EnableFeatureByPackagePath(DismSession session, string featureName, string packagePath, bool limitAccess, bool enableAll, List? sourcePaths)
+ public static Task EnableFeatureByPackageNameAsync(DismSession session, string featureName, string packageName, bool limitAccess, bool enableAll, List? sourcePaths, CancellationToken cancellationToken = default)
{
- EnableFeatureByPackagePath(session, featureName, packagePath, limitAccess, enableAll, sourcePaths, progressCallback: null);
+ return EnableFeatureByPackageNameAsync(session, featureName, packageName, limitAccess, enableAll, sourcePaths, progress: null, cancellationToken);
}
///
- /// Enables a feature from the specified package path.
+ /// Enables a feature from the specified package name.
///
/// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.
/// The name of the feature that is being enabled. To enable more than one feature, separate each feature name with a semicolon.
- /// The path of the package that contains the feature.
+ /// The name of the package that contains the feature.
/// Specifies whether Windows Update (WU) should be contacted as a source location for downloading files if none are found in other specified locations. Before checking WU, DISM will check for the files in the SourcePaths provided and in any locations specified in the registry by group policy. If the files required to enable the feature are still present on the computer, this flag is ignored.
/// Specifies whether to enable all dependencies of the feature. If the specified feature or any one of its dependencies cannot be enabled, none of them will be changed from their existing state.
/// A list of source locations to check for files needed to enable the feature.
- /// A progress callback method to invoke when progress is made.
+ /// An optional provider to receive progress updates.
+ /// token to monitor for cancellation requests. The default value is .
+ /// A that represents the asynchronous operation.
/// When a failure occurs.
/// When the user requested the operation be canceled.
/// When the operation requires a reboot to complete.
- public static void EnableFeatureByPackagePath(DismSession session, string featureName, string packagePath, bool limitAccess, bool enableAll, List? sourcePaths, Microsoft.Dism.DismProgressCallback? progressCallback)
+ public static Task EnableFeatureByPackageNameAsync(DismSession session, string featureName, string packageName, bool limitAccess, bool enableAll, List? sourcePaths, IProgress? progress, CancellationToken cancellationToken = default)
{
- EnableFeatureByPackagePath(session, featureName, packagePath, limitAccess, enableAll, sourcePaths, progressCallback, userData: null);
+ return EnableFeatureByPackageNameAsync(session, featureName, packageName, limitAccess, enableAll, sourcePaths, progress, userData: null, cancellationToken);
}
///
- /// Enables a feature from the specified package path.
+ /// Enables a feature from the specified package name.
///
/// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.
/// The name of the feature that is being enabled. To enable more than one feature, separate each feature name with a semicolon.
- /// The path of the package that contains the feature.
+ /// The name of the package that contains the feature.
/// Specifies whether Windows Update (WU) should be contacted as a source location for downloading files if none are found in other specified locations. Before checking WU, DISM will check for the files in the SourcePaths provided and in any locations specified in the registry by group policy. If the files required to enable the feature are still present on the computer, this flag is ignored.
/// Specifies whether to enable all dependencies of the feature. If the specified feature or any one of its dependencies cannot be enabled, none of them will be changed from their existing state.
/// A list of source locations to check for files needed to enable the feature.
- /// A progress callback method to invoke when progress is made.
- /// Optional user data to pass to the DismProgressCallback method.
+ /// An optional provider to receive progress updates.
+ /// Optional user data to pass to the specified .
+ /// token to monitor for cancellation requests. The default value is .
+ /// A that represents the asynchronous operation.
/// When a failure occurs.
/// When the user requested the operation be canceled.
/// When the operation requires a reboot to complete.
- public static void EnableFeatureByPackagePath(DismSession session, string featureName, string packagePath, bool limitAccess, bool enableAll, List? sourcePaths, Microsoft.Dism.DismProgressCallback? progressCallback, object? userData)
+ public static Task EnableFeatureByPackageNameAsync(DismSession session, string featureName, string packageName, bool limitAccess, bool enableAll, List? sourcePaths, IProgress? progress, object? userData, CancellationToken cancellationToken = default)
{
- EnableFeature(session, featureName, packagePath, DismPackageIdentifier.Path, limitAccess, enableAll, sourcePaths, progressCallback, userData);
+ return EnableFeatureAsync(session, featureName, packageName, DismPackageIdentifier.Name, limitAccess, enableAll, sourcePaths, progress, userData, cancellationToken);
}
///
@@ -154,12 +285,14 @@ public static void EnableFeatureByPackagePath(DismSession session, string featur
///
/// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.
/// The name of the feature that is being enabled. To enable more than one feature, separate each feature name with a semicolon.
+ /// The path of the package that contains the feature.
/// Specifies whether Windows Update (WU) should be contacted as a source location for downloading files if none are found in other specified locations. Before checking WU, DISM will check for the files in the SourcePaths provided and in any locations specified in the registry by group policy. If the files required to enable the feature are still present on the computer, this flag is ignored.
/// Specifies whether to enable all dependencies of the feature. If the specified feature or any one of its dependencies cannot be enabled, none of them will be changed from their existing state.
/// When a failure occurs.
- public static void EnableFeature(DismSession session, string featureName, bool limitAccess, bool enableAll)
+ /// When the operation requires a reboot to complete.
+ public static void EnableFeatureByPackagePath(DismSession session, string featureName, string packagePath, bool limitAccess, bool enableAll)
{
- EnableFeature(session, featureName, identifier: null, DismPackageIdentifier.None, limitAccess, enableAll, sourcePaths: null, progressCallback: null, userData: null);
+ EnableFeatureByPackagePath(session, featureName, packagePath, limitAccess, enableAll, sourcePaths: null, progressCallback: null);
}
///
@@ -167,13 +300,15 @@ public static void EnableFeature(DismSession session, string featureName, bool l
///
/// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.
/// The name of the feature that is being enabled. To enable more than one feature, separate each feature name with a semicolon.
+ /// The path of the package that contains the feature.
/// Specifies whether Windows Update (WU) should be contacted as a source location for downloading files if none are found in other specified locations. Before checking WU, DISM will check for the files in the SourcePaths provided and in any locations specified in the registry by group policy. If the files required to enable the feature are still present on the computer, this flag is ignored.
/// Specifies whether to enable all dependencies of the feature. If the specified feature or any one of its dependencies cannot be enabled, none of them will be changed from their existing state.
/// A list of source locations to check for files needed to enable the feature.
/// When a failure occurs.
- public static void EnableFeature(DismSession session, string featureName, bool limitAccess, bool enableAll, List? sourcePaths)
+ /// When the operation requires a reboot to complete.
+ public static void EnableFeatureByPackagePath(DismSession session, string featureName, string packagePath, bool limitAccess, bool enableAll, List? sourcePaths)
{
- EnableFeature(session, featureName, identifier: null, DismPackageIdentifier.None, limitAccess, enableAll, sourcePaths, progressCallback: null, userData: null);
+ EnableFeatureByPackagePath(session, featureName, packagePath, limitAccess, enableAll, sourcePaths, progressCallback: null);
}
///
@@ -181,14 +316,17 @@ public static void EnableFeature(DismSession session, string featureName, bool l
///
/// A valid DISM Session. The DISM Session must be associated with an image. You can associate a session with an image by using the DismOpenSession Function.
/// The name of the feature that is being enabled. To enable more than one feature, separate each feature name with a semicolon.
+ /// The path of the package that contains the feature.
/// Specifies whether Windows Update (WU) should be contacted as a source location for downloading files if none are found in other specified locations. Before checking WU, DISM will check for the files in the SourcePaths provided and in any locations specified in the registry by group policy. If the files required to enable the feature are still present on the computer, this flag is ignored.
/// Specifies whether to enable all dependencies of the feature. If the specified feature or any one of its dependencies cannot be enabled, none of them will be changed from their existing state.
/// A list of source locations to check for files needed to enable the feature.
/// A progress callback method to invoke when progress is made.
/// When a failure occurs.
- public static void EnableFeature(DismSession session, string featureName, bool limitAccess, bool enableAll, List? sourcePaths, Microsoft.Dism.DismProgressCallback? progressCallback)
+ ///