diff --git a/src/System.Management.Automation/engine/ArgumentToVersionTransformationAttribute.cs b/src/System.Management.Automation/engine/ArgumentToVersionTransformationAttribute.cs
index facaa9e3e1a..5ac86ac2bde 100644
--- a/src/System.Management.Automation/engine/ArgumentToVersionTransformationAttribute.cs
+++ b/src/System.Management.Automation/engine/ArgumentToVersionTransformationAttribute.cs
@@ -8,6 +8,33 @@
namespace System.Management.Automation
{
+ ///
+ /// To make it easier to specify a version, we add some conversions that wouldn't happen otherwise:
+ /// * A simple integer, i.e. 2;
+ /// * A string without a dot, i.e. "2".
+ /// * the string "off" sets the version to 0.0 (unset).
+ /// * the string "latest" sets to the current version.
+ ///
+ internal sealed class ArgumentToPSVersionTransformationAttribute : ArgumentToVersionTransformationAttribute
+ {
+ protected override bool TryConvertFromString(string versionString, [NotNullWhen(true)] out Version? version)
+ {
+ if (string.Equals("off", versionString, StringComparison.OrdinalIgnoreCase))
+ {
+ version = new Version(0, 0);
+ return true;
+ }
+
+ if (string.Equals("latest", versionString, StringComparison.OrdinalIgnoreCase))
+ {
+ version = PSVersionInfo.PSVersion;
+ return true;
+ }
+
+ return base.TryConvertFromString(versionString, out version);
+ }
+ }
+
///
/// To make it easier to specify a version, we add some conversions that wouldn't happen otherwise:
/// * A simple integer, i.e. 2;
diff --git a/src/System.Management.Automation/engine/InternalCommands.cs b/src/System.Management.Automation/engine/InternalCommands.cs
index c642e30e885..e7f6e90e207 100644
--- a/src/System.Management.Automation/engine/InternalCommands.cs
+++ b/src/System.Management.Automation/engine/InternalCommands.cs
@@ -2635,23 +2635,6 @@ public SwitchParameter Off
private SwitchParameter _off;
- ///
- /// Handle 'latest', which we interpret to be the current version of PowerShell.
- ///
- private sealed class ArgumentToPSVersionTransformationAttribute : ArgumentToVersionTransformationAttribute
- {
- protected override bool TryConvertFromString(string versionString, [NotNullWhen(true)] out Version version)
- {
- if (string.Equals("latest", versionString, StringComparison.OrdinalIgnoreCase))
- {
- version = PSVersionInfo.PSVersion;
- return true;
- }
-
- return base.TryConvertFromString(versionString, out version);
- }
- }
-
private sealed class ValidateVersionAttribute : ValidateArgumentsAttribute
{
protected override void Validate(object arguments, EngineIntrinsics engineIntrinsics)
diff --git a/src/System.Management.Automation/engine/remoting/commands/InvokeCommandCommand.cs b/src/System.Management.Automation/engine/remoting/commands/InvokeCommandCommand.cs
index c194706151d..03bb69f1fcf 100644
--- a/src/System.Management.Automation/engine/remoting/commands/InvokeCommandCommand.cs
+++ b/src/System.Management.Automation/engine/remoting/commands/InvokeCommandCommand.cs
@@ -263,26 +263,6 @@ public override SwitchParameter UseSSL
}
}
- private sealed class ArgumentToPSVersionTransformationAttribute : ArgumentToVersionTransformationAttribute
- {
- protected override bool TryConvertFromString(string versionString, [NotNullWhen(true)] out Version version)
- {
- if (string.Equals("off", versionString, StringComparison.OrdinalIgnoreCase))
- {
- version = new Version(0, 0);
- return true;
- }
-
- if (string.Equals("latest", versionString, StringComparison.OrdinalIgnoreCase))
- {
- version = PSVersionInfo.PSVersion;
- return true;
- }
-
- return base.TryConvertFromString(versionString, out version);
- }
- }
-
private static readonly Version s_OffVersion = new Version(0, 0);
private sealed class ValidateVersionAttribute : ValidateArgumentsAttribute
diff --git a/tools/packaging/packaging.psm1 b/tools/packaging/packaging.psm1
index bca41d3c816..0e064b8fbb8 100644
--- a/tools/packaging/packaging.psm1
+++ b/tools/packaging/packaging.psm1
@@ -2294,6 +2294,8 @@ function CleanupGeneratedSourceCode
'[Microsoft.PowerShell.Commands.SetStrictModeCommand.ArgumentToPSVersionTransformationAttribute]'
'[Microsoft.PowerShell.Commands.HttpVersionCompletionsAttribute]'
'[System.Management.Automation.ArgumentToVersionTransformationAttribute]'
+ '[Microsoft.PowerShell.Commands.InvokeCommandCommand.ValidateVersionAttribute]'
+ '[System.Management.Automation.ArgumentToPSVersionTransformationAttribute]'
)
$patternsToReplace = @(