From cf2d7021ab58d758507cdd493c9254e888b302f1 Mon Sep 17 00:00:00 2001
From: xtqqczze <45661989+xtqqczze@users.noreply.github.com>
Date: Thu, 28 Aug 2025 06:54:18 +0100
Subject: [PATCH] Remove redundant `System.Runtime.Versioning` attributes
(#25926)
---
.../namespaces/TransactedRegistry.cs | 5 ---
.../namespaces/TransactedRegistryKey.cs | 32 -------------------
.../namespaces/Win32Native.cs | 4 ---
3 files changed, 41 deletions(-)
diff --git a/src/System.Management.Automation/namespaces/TransactedRegistry.cs b/src/System.Management.Automation/namespaces/TransactedRegistry.cs
index 56062e6de6..6465ea1819 100644
--- a/src/System.Management.Automation/namespaces/TransactedRegistry.cs
+++ b/src/System.Management.Automation/namespaces/TransactedRegistry.cs
@@ -42,7 +42,6 @@ namespace Microsoft.PowerShell.Commands.Internal
/// subkeys, there must be a Transaction.Current and the resulting TransactedRegistryKey from those operations ARE associated with
/// the transaction.
///
- [ResourceExposure(ResourceScope.Machine)]
// The TransactedRegistryKey's members cannot be changed.
[SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")]
internal static readonly TransactedRegistryKey CurrentUser = TransactedRegistryKey.GetBaseKey(BaseRegistryKeys.HKEY_CURRENT_USER);
@@ -61,7 +60,6 @@ namespace Microsoft.PowerShell.Commands.Internal
/// subkeys, there must be a Transaction.Current and the resulting TransactedRegistryKey from those operations ARE associated with
/// the transaction.
///
- [ResourceExposure(ResourceScope.Machine)]
// The TransactedRegistryKey's members cannot be changed.
[SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")]
internal static readonly TransactedRegistryKey LocalMachine = TransactedRegistryKey.GetBaseKey(BaseRegistryKeys.HKEY_LOCAL_MACHINE);
@@ -80,7 +78,6 @@ namespace Microsoft.PowerShell.Commands.Internal
/// subkeys, there must be a Transaction.Current and the resulting TransactedRegistryKey from those operations ARE associated with
/// the transaction.
///
- [ResourceExposure(ResourceScope.Machine)]
// The TransactedRegistryKey's members cannot be changed.
[SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")]
internal static readonly TransactedRegistryKey ClassesRoot = TransactedRegistryKey.GetBaseKey(BaseRegistryKeys.HKEY_CLASSES_ROOT);
@@ -99,7 +96,6 @@ namespace Microsoft.PowerShell.Commands.Internal
/// subkeys, there must be a Transaction.Current and the resulting TransactedRegistryKey from those operations ARE associated with
/// the transaction.
///
- [ResourceExposure(ResourceScope.Machine)]
// The TransactedRegistryKey's members cannot be changed.
[SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")]
internal static readonly TransactedRegistryKey Users = TransactedRegistryKey.GetBaseKey(BaseRegistryKeys.HKEY_USERS);
@@ -118,7 +114,6 @@ namespace Microsoft.PowerShell.Commands.Internal
/// subkeys, there must be a Transaction.Current and the resulting TransactedRegistryKey from those operations ARE associated with
/// the transaction.
///
- [ResourceExposure(ResourceScope.Machine)]
// The TransactedRegistryKey's members cannot be changed.
[SuppressMessage("Microsoft.Security", "CA2104:DoNotDeclareReadOnlyMutableReferenceTypes")]
internal static readonly TransactedRegistryKey CurrentConfig = TransactedRegistryKey.GetBaseKey(BaseRegistryKeys.HKEY_CURRENT_CONFIG);
diff --git a/src/System.Management.Automation/namespaces/TransactedRegistryKey.cs b/src/System.Management.Automation/namespaces/TransactedRegistryKey.cs
index 23316a3172..0460ba690d 100644
--- a/src/System.Management.Automation/namespaces/TransactedRegistryKey.cs
+++ b/src/System.Management.Automation/namespaces/TransactedRegistryKey.cs
@@ -346,8 +346,6 @@ namespace Microsoft.PowerShell.Commands.Internal
/// otherwise an ArgumentException is thrown.
/// A TransactedRegistryKey object for the subkey, which is associated with Transaction.Current.
/// returns null if the operation failed.
- [ResourceExposure(ResourceScope.Machine)]
- [ResourceConsumption(ResourceScope.Machine)]
// Suppressed to be consistent with naming in Microsoft.Win32.RegistryKey
[SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly")]
public TransactedRegistryKey CreateSubKey(string subkey)
@@ -366,8 +364,6 @@ namespace Microsoft.PowerShell.Commands.Internal
/// One of the Microsoft.Win32.RegistryKeyPermissionCheck values that
/// specifies whether the key is opened for read or read/write access.
[ComVisible(false)]
- [ResourceExposure(ResourceScope.Machine)]
- [ResourceConsumption(ResourceScope.Machine)]
// Suppressed to be consistent with naming in Microsoft.Win32.RegistryKey
[SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly")]
public TransactedRegistryKey CreateSubKey(string subkey, RegistryKeyPermissionCheck permissionCheck)
@@ -387,8 +383,6 @@ namespace Microsoft.PowerShell.Commands.Internal
/// specifies whether the key is opened for read or read/write access.
/// A TransactedRegistrySecurity object that specifies the access control security for the new key.
[ComVisible(false)]
- [ResourceExposure(ResourceScope.Machine)]
- [ResourceConsumption(ResourceScope.Machine)]
// Suppressed to be consistent with naming in Microsoft.Win32.RegistryKey
[SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly")]
public unsafe TransactedRegistryKey CreateSubKey(string subkey, RegistryKeyPermissionCheck permissionCheck, TransactedRegistrySecurity registrySecurity)
@@ -397,8 +391,6 @@ namespace Microsoft.PowerShell.Commands.Internal
}
[ComVisible(false)]
- [ResourceExposure(ResourceScope.Machine)]
- [ResourceConsumption(ResourceScope.Machine)]
// Suppressed to be consistent with naming in Microsoft.Win32.RegistryKey
[SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly")]
private unsafe TransactedRegistryKey CreateSubKeyInternal(string subkey, RegistryKeyPermissionCheck permissionCheck, object registrySecurityObj)
@@ -489,8 +481,6 @@ namespace Microsoft.PowerShell.Commands.Internal
/// Thrown if the subkey as child subkeys.
///
/// The subkey to delete.
- [ResourceExposure(ResourceScope.Machine)]
- [ResourceConsumption(ResourceScope.Machine)]
// Suppressed to be consistent with naming in Microsoft.Win32.RegistryKey
[SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly")]
public void DeleteSubKey(string subkey)
@@ -510,8 +500,6 @@ namespace Microsoft.PowerShell.Commands.Internal
/// Specify true if an ArgumentException should be thrown if
/// the specified subkey does not exist. If false is specified, a missing subkey does not throw
/// an exception.
- [ResourceExposure(ResourceScope.Machine)]
- [ResourceConsumption(ResourceScope.Machine)]
// Suppressed to be consistent with naming in Microsoft.Win32.RegistryKey
[SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly")]
public void DeleteSubKey(string subkey, bool throwOnMissingSubKey)
@@ -569,8 +557,6 @@ namespace Microsoft.PowerShell.Commands.Internal
/// Utilizes Transaction.Current for its transaction.
///
/// The subkey to delete.
- [ResourceExposure(ResourceScope.Machine)]
- [ResourceConsumption(ResourceScope.Machine)]
// Suppressed to be consistent with naming in Microsoft.Win32.RegistryKey
[SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly")]
public void DeleteSubKeyTree(string subkey)
@@ -626,8 +612,6 @@ namespace Microsoft.PowerShell.Commands.Internal
// An internal version which does no security checks or argument checking. Skipping the
// security checks should give us a slight perf gain on large trees.
- [ResourceExposure(ResourceScope.Machine)]
- [ResourceConsumption(ResourceScope.Machine)]
// Suppressed to be consistent with naming in Microsoft.Win32.RegistryKey
[SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly")]
private void DeleteSubKeyTreeInternal(string subkey)
@@ -672,8 +656,6 @@ namespace Microsoft.PowerShell.Commands.Internal
/// Utilizes Transaction.Current for its transaction.
///
/// Name of the value to delete.
- [ResourceExposure(ResourceScope.None)]
- [ResourceConsumption(ResourceScope.Machine, ResourceScope.Machine)]
public void DeleteValue(string name)
{
DeleteValue(name, true);
@@ -687,8 +669,6 @@ namespace Microsoft.PowerShell.Commands.Internal
/// Specify true if an ArgumentException should be thrown if
/// the specified value does not exist. If false is specified, a missing value does not throw
/// an exception.
- [ResourceExposure(ResourceScope.None)]
- [ResourceConsumption(ResourceScope.Machine, ResourceScope.Machine)]
public void DeleteValue(string name, bool throwOnMissingValue)
{
EnsureWriteable();
@@ -758,8 +738,6 @@ namespace Microsoft.PowerShell.Commands.Internal
/// The subkey requested or null if the operation failed.
/// Name or path of the subkey to open.
/// Set to true of you only need readonly access.
- [ResourceExposure(ResourceScope.Machine)]
- [ResourceConsumption(ResourceScope.Machine)]
// Suppressed to be consistent with naming in Microsoft.Win32.RegistryKey
[SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly")]
public TransactedRegistryKey OpenSubKey(string name, bool writable)
@@ -803,8 +781,6 @@ namespace Microsoft.PowerShell.Commands.Internal
/// One of the Microsoft.Win32.RegistryKeyPermissionCheck values that specifies
/// whether the key is opened for read or read/write access.
[ComVisible(false)]
- [ResourceExposure(ResourceScope.Machine)]
- [ResourceConsumption(ResourceScope.Machine)]
// Suppressed to be consistent with naming in Microsoft.Win32.RegistryKey
[SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly")]
public TransactedRegistryKey OpenSubKey(string name, RegistryKeyPermissionCheck permissionCheck)
@@ -823,8 +799,6 @@ namespace Microsoft.PowerShell.Commands.Internal
/// whether the key is opened for read or read/write access.
/// A bitwise combination of Microsoft.Win32.RegistryRights values that specifies the desired security access.
[ComVisible(false)]
- [ResourceExposure(ResourceScope.Machine)]
- [ResourceConsumption(ResourceScope.Machine)]
// Suppressed to be consistent with naming in Microsoft.Win32.RegistryKey
[SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly")]
public TransactedRegistryKey OpenSubKey(string name, RegistryKeyPermissionCheck permissionCheck, RegistryRights rights)
@@ -832,8 +806,6 @@ namespace Microsoft.PowerShell.Commands.Internal
return InternalOpenSubKey(name, permissionCheck, (int)rights);
}
- [ResourceExposure(ResourceScope.Machine)]
- [ResourceConsumption(ResourceScope.Machine)]
// Suppressed to be consistent with naming in Microsoft.Win32.RegistryKey
[SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly")]
private TransactedRegistryKey InternalOpenSubKey(string name, RegistryKeyPermissionCheck permissionCheck, int rights)
@@ -874,8 +846,6 @@ namespace Microsoft.PowerShell.Commands.Internal
// This required no security checks. This is to get around the Deleting SubKeys which only require
// write permission. They call OpenSubKey which required read. Now instead call this function w/o security checks
- [ResourceExposure(ResourceScope.Machine)]
- [ResourceConsumption(ResourceScope.Machine)]
// Suppressed to be consistent with naming in Microsoft.Win32.RegistryKey
[SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly")]
internal TransactedRegistryKey InternalOpenSubKey(string name, bool writable)
@@ -906,8 +876,6 @@ namespace Microsoft.PowerShell.Commands.Internal
///
/// The subkey requested or null if the operation failed.
/// Name or path of the subkey to open.
- [ResourceExposure(ResourceScope.Machine)]
- [ResourceConsumption(ResourceScope.Machine)]
// Suppressed to be consistent with naming in Microsoft.Win32.RegistryKey
[SuppressMessage("Microsoft.Naming", "CA1702:CompoundWordsShouldBeCasedCorrectly")]
public TransactedRegistryKey OpenSubKey(string name)
diff --git a/src/System.Management.Automation/namespaces/Win32Native.cs b/src/System.Management.Automation/namespaces/Win32Native.cs
index b785cd5fbb..f42951602e 100644
--- a/src/System.Management.Automation/namespaces/Win32Native.cs
+++ b/src/System.Management.Automation/namespaces/Win32Native.cs
@@ -106,7 +106,6 @@ namespace Microsoft.PowerShell.Commands.Internal
///
///
[DllImport(PinvokeDllNames.LookupAccountSidDllName, CharSet = CharSet.Unicode, SetLastError = true, BestFitMapping = false)]
- [ResourceExposure(ResourceScope.Machine)]
[SuppressMessage("Microsoft.Security", "CA2118:ReviewSuppressUnmanagedCodeSecurityUsage")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern unsafe bool LookupAccountSid(string lpSystemName,
@@ -139,7 +138,6 @@ namespace Microsoft.PowerShell.Commands.Internal
}
[DllImport(PinvokeDllNames.CloseHandleDllName, SetLastError = true)]
- [ResourceExposure(ResourceScope.Machine)]
[SuppressMessage("Microsoft.Security", "CA2118:ReviewSuppressUnmanagedCodeSecurityUsage")]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool CloseHandle(IntPtr handle);
@@ -152,7 +150,6 @@ namespace Microsoft.PowerShell.Commands.Internal
/// Process token.
/// The current process token.
[DllImport(PinvokeDllNames.OpenProcessTokenDllName, CharSet = CharSet.Unicode, SetLastError = true, BestFitMapping = false)]
- [ResourceExposure(ResourceScope.Machine)]
[SuppressMessage("Microsoft.Security", "CA2118:ReviewSuppressUnmanagedCodeSecurityUsage")]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool OpenProcessToken(IntPtr processHandle, uint desiredAccess, out IntPtr tokenHandle);
@@ -168,7 +165,6 @@ namespace Microsoft.PowerShell.Commands.Internal
///
///
[DllImport(PinvokeDllNames.GetTokenInformationDllName, CharSet = CharSet.Unicode, SetLastError = true, BestFitMapping = false)]
- [ResourceExposure(ResourceScope.Machine)]
[SuppressMessage("Microsoft.Security", "CA2118:ReviewSuppressUnmanagedCodeSecurityUsage")]
[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool GetTokenInformation(IntPtr tokenHandle,