mirror of
https://github.com/PowerShell/PowerShell.git
synced 2024-12-03 23:03:57 +08:00
Change Add-Type -OutputType
to not support ConsoleApplication
and WindowsApplication
(#13440)
This commit is contained in:
parent
fc4c9cbfd7
commit
5f9d2846f7
@ -551,7 +551,21 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
ThrowTerminatingError(
|
||||
new ErrorRecord(
|
||||
new PSNotSupportedException(AddTypeStrings.CannotDefineNewType), "CannotDefineNewType", ErrorCategory.PermissionDenied, null));
|
||||
new PSNotSupportedException(AddTypeStrings.CannotDefineNewType),
|
||||
nameof(AddTypeStrings.CannotDefineNewType),
|
||||
ErrorCategory.PermissionDenied,
|
||||
targetObject: null));
|
||||
}
|
||||
|
||||
// 'ConsoleApplication' and 'WindowsApplication' types are currently not working in .NET Core
|
||||
if (OutputType != OutputAssemblyType.Library)
|
||||
{
|
||||
ThrowTerminatingError(
|
||||
new ErrorRecord(
|
||||
new PSNotSupportedException(AddTypeStrings.AssemblyTypeNotSupported),
|
||||
nameof(AddTypeStrings.AssemblyTypeNotSupported),
|
||||
ErrorCategory.NotImplemented,
|
||||
targetObject: OutputType));
|
||||
}
|
||||
}
|
||||
|
||||
@ -890,12 +904,9 @@ namespace Microsoft.PowerShell.Commands
|
||||
{
|
||||
case OutputAssemblyType.Library:
|
||||
return OutputKind.DynamicallyLinkedLibrary;
|
||||
case OutputAssemblyType.ConsoleApplication:
|
||||
return OutputKind.ConsoleApplication;
|
||||
case OutputAssemblyType.WindowsApplication:
|
||||
return OutputKind.WindowsApplication;
|
||||
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(outputType));
|
||||
throw PSTraceSource.NewNotSupportedException();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -165,4 +165,7 @@
|
||||
<data name="ReferenceAssemblyIgnored" xml:space="preserve">
|
||||
<value>The specified reference assembly '{0}' is unnecessary and ignored.</value>
|
||||
</data>
|
||||
<data name="AssemblyTypeNotSupported" xml:space="preserve">
|
||||
<value>Both the assembly types 'ConsoleApplication' and 'WindowsApplication' are not currently supported.</value>
|
||||
</data>
|
||||
</root>
|
||||
|
@ -246,4 +246,12 @@ public class AttributeTest$guid : PSCmdlet
|
||||
param ($assemblyName, $errorid)
|
||||
{ Add-Type -AssemblyName $assemblyName } | Should -Throw -ErrorId $errorid
|
||||
}
|
||||
|
||||
It "Throw terminating error when '-OutputType' is '<outputType>'" -TestCases @(
|
||||
@{ outputType = 'ConsoleApplication' }
|
||||
@{ outputType = 'WindowsApplication' }
|
||||
) {
|
||||
param($outputType)
|
||||
{ Add-Type -TypeDefinition "Hello" -OutputType $outputType } | Should -Throw -ErrorId 'AssemblyTypeNotSupported,Microsoft.PowerShell.Commands.AddTypeCommand'
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user