Merge pull request #7284 from daxian-dbw/removeVB
Remove the 'VisualBasic' support from Add-Type
This commit is contained in:
commit
ab07b85f01
|
@ -58,9 +58,6 @@
|
||||||
<Component Id="cmp3CC027D3F160412C9F0044EBED3115DD" Guid="{8D7CAA67-8F28-422C-85FB-BDE04902E64F}">
|
<Component Id="cmp3CC027D3F160412C9F0044EBED3115DD" Guid="{8D7CAA67-8F28-422C-85FB-BDE04902E64F}">
|
||||||
<File Id="filFD2EF6BC74AF459D1BB52CA1E8C6E33B" KeyPath="yes" Source="$(env.ProductSourcePath)\NJsonSchema.dll" />
|
<File Id="filFD2EF6BC74AF459D1BB52CA1E8C6E33B" KeyPath="yes" Source="$(env.ProductSourcePath)\NJsonSchema.dll" />
|
||||||
</Component>
|
</Component>
|
||||||
<Component Id="cmp98A11B3F71BACCA2DD0A4856577CD343" Guid="{4EFB61AC-361B-42D0-B9A1-C1FEE287CD13}">
|
|
||||||
<File Id="fil9286A659888A5C12030A9CF0B215D062" KeyPath="yes" Source="$(env.ProductSourcePath)\Microsoft.CodeAnalysis.VisualBasic.dll" />
|
|
||||||
</Component>
|
|
||||||
<Component Id="cmp3B130879A26D2E954251BB81E8948069" Guid="{CD268615-4603-4A5F-B126-340ADF2EDDD5}">
|
<Component Id="cmp3B130879A26D2E954251BB81E8948069" Guid="{CD268615-4603-4A5F-B126-340ADF2EDDD5}">
|
||||||
<File Id="filAACDEEE28FEA076C73D082A0AD21B8E0" KeyPath="yes" Source="$(env.ProductSourcePath)\Microsoft.CSharp.dll" />
|
<File Id="filAACDEEE28FEA076C73D082A0AD21B8E0" KeyPath="yes" Source="$(env.ProductSourcePath)\Microsoft.CSharp.dll" />
|
||||||
</Component>
|
</Component>
|
||||||
|
@ -1937,7 +1934,6 @@
|
||||||
<ComponentRef Id="cmp30C10EC477714A76B2A8D0A957D1D6F3" />
|
<ComponentRef Id="cmp30C10EC477714A76B2A8D0A957D1D6F3" />
|
||||||
<ComponentRef Id="cmp31176C5A3BDB4A9F95171A4780D7D4D2" />
|
<ComponentRef Id="cmp31176C5A3BDB4A9F95171A4780D7D4D2" />
|
||||||
<ComponentRef Id="cmp3CC027D3F160412C9F0044EBED3115DD" />
|
<ComponentRef Id="cmp3CC027D3F160412C9F0044EBED3115DD" />
|
||||||
<ComponentRef Id="cmp98A11B3F71BACCA2DD0A4856577CD343" />
|
|
||||||
<ComponentRef Id="cmp3B130879A26D2E954251BB81E8948069" />
|
<ComponentRef Id="cmp3B130879A26D2E954251BB81E8948069" />
|
||||||
<ComponentRef Id="cmp02ABBE4A3EDBEBFD05DC17A009A2B79D" />
|
<ComponentRef Id="cmp02ABBE4A3EDBEBFD05DC17A009A2B79D" />
|
||||||
<ComponentRef Id="cmpAA10498DF244C013CB5043C62E3AA83A" />
|
<ComponentRef Id="cmpAA10498DF244C013CB5043C62E3AA83A" />
|
||||||
|
|
|
@ -66,7 +66,6 @@
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="2.8.2" />
|
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="2.8.2" />
|
||||||
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic" Version="2.8.2" />
|
|
||||||
<PackageReference Include="NJsonSchema" Version="9.10.63" />
|
<PackageReference Include="NJsonSchema" Version="9.10.63" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,6 @@ using Microsoft.CodeAnalysis;
|
||||||
using Microsoft.CodeAnalysis.CSharp;
|
using Microsoft.CodeAnalysis.CSharp;
|
||||||
using Microsoft.CodeAnalysis.Emit;
|
using Microsoft.CodeAnalysis.Emit;
|
||||||
using Microsoft.CodeAnalysis.Text;
|
using Microsoft.CodeAnalysis.Text;
|
||||||
using Microsoft.CodeAnalysis.VisualBasic;
|
|
||||||
|
|
||||||
using PathType = System.IO.Path;
|
using PathType = System.IO.Path;
|
||||||
|
|
||||||
|
@ -37,12 +36,7 @@ namespace Microsoft.PowerShell.Commands
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The C# programming language.
|
/// The C# programming language.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
CSharp,
|
CSharp
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// The Visual Basic programming language.
|
|
||||||
/// </summary>
|
|
||||||
VisualBasic
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -166,8 +160,7 @@ namespace Microsoft.PowerShell.Commands
|
||||||
foreach (string path in pathValue)
|
foreach (string path in pathValue)
|
||||||
{
|
{
|
||||||
// Try to resolve the path
|
// Try to resolve the path
|
||||||
ProviderInfo provider = null;
|
Collection<string> newPaths = SessionState.Path.GetResolvedProviderPathFromPSPath(path, out ProviderInfo _);
|
||||||
Collection<string> newPaths = SessionState.Path.GetResolvedProviderPathFromPSPath(path, out provider);
|
|
||||||
|
|
||||||
// If it didn't resolve, add the original back
|
// If it didn't resolve, add the original back
|
||||||
// for a better error message.
|
// for a better error message.
|
||||||
|
@ -218,12 +211,8 @@ namespace Microsoft.PowerShell.Commands
|
||||||
|
|
||||||
private void ProcessPaths(List<string> resolvedPaths)
|
private void ProcessPaths(List<string> resolvedPaths)
|
||||||
{
|
{
|
||||||
// Now, get the file type. At the same time, make sure
|
// Validate file extensions.
|
||||||
// we aren't attempting to mix languages, as that is
|
// Make sure we don't mix source files from different languages (if we support any other languages in future).
|
||||||
// not supported by the Roslyn. While it
|
|
||||||
// would be possible to partition the files into
|
|
||||||
// languages, that would be much too complex to
|
|
||||||
// describe.
|
|
||||||
string activeExtension = null;
|
string activeExtension = null;
|
||||||
foreach (string path in resolvedPaths)
|
foreach (string path in resolvedPaths)
|
||||||
{
|
{
|
||||||
|
@ -235,10 +224,6 @@ namespace Microsoft.PowerShell.Commands
|
||||||
Language = Language.CSharp;
|
Language = Language.CSharp;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ".VB":
|
|
||||||
Language = Language.VisualBasic;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ".DLL":
|
case ".DLL":
|
||||||
loadAssembly = true;
|
loadAssembly = true;
|
||||||
break;
|
break;
|
||||||
|
@ -253,7 +238,6 @@ namespace Microsoft.PowerShell.Commands
|
||||||
currentExtension);
|
currentExtension);
|
||||||
|
|
||||||
ThrowTerminatingError(errorRecord);
|
ThrowTerminatingError(errorRecord);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -273,9 +257,9 @@ namespace Microsoft.PowerShell.Commands
|
||||||
|
|
||||||
ThrowTerminatingError(errorRecord);
|
ThrowTerminatingError(errorRecord);
|
||||||
}
|
}
|
||||||
|
|
||||||
_paths = resolvedPaths.ToArray();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_paths = resolvedPaths.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
private string[] _paths;
|
private string[] _paths;
|
||||||
|
@ -425,15 +409,12 @@ namespace Microsoft.PowerShell.Commands
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Roslyn command line parameters.
|
/// Roslyn command line parameters.
|
||||||
/// https://github.com/dotnet/roslyn/blob/master/docs/compilers/CSharp/CommandLine.md
|
/// https://github.com/dotnet/roslyn/blob/master/docs/compilers/CSharp/CommandLine.md
|
||||||
/// https://github.com/dotnet/roslyn/blob/master/docs/compilers/Visual%20Basic/CommandLine.md
|
|
||||||
///
|
///
|
||||||
/// Parser options:
|
/// Parser options:
|
||||||
/// langversion:string - language version from:
|
/// langversion:string - language version from:
|
||||||
/// [enum]::GetNames([Microsoft.CodeAnalysis.CSharp.LanguageVersion])
|
/// [enum]::GetNames([Microsoft.CodeAnalysis.CSharp.LanguageVersion])
|
||||||
/// [enum]::GetNames([Microsoft.CodeAnalysis.VisualBasic.LanguageVersion])
|
|
||||||
/// define:symbol list - preprocessor symbols:
|
/// define:symbol list - preprocessor symbols:
|
||||||
/// /define:UNIX,DEBUG - CSharp
|
/// /define:UNIX,DEBUG - CSharp
|
||||||
/// /define:UNIX=1,DEBUG=1 - VisualBasic
|
|
||||||
///
|
///
|
||||||
/// Compilation options:
|
/// Compilation options:
|
||||||
/// optimize{+|-} - optimization level
|
/// optimize{+|-} - optimization level
|
||||||
|
@ -444,7 +425,6 @@ namespace Microsoft.PowerShell.Commands
|
||||||
/// nowarn - disable all warnings
|
/// nowarn - disable all warnings
|
||||||
/// nowarn:strings - disable a list of individual warnings
|
/// nowarn:strings - disable a list of individual warnings
|
||||||
/// usings:strings - ';'-delimited usings for CSharp
|
/// usings:strings - ';'-delimited usings for CSharp
|
||||||
/// imports:strings - ';'-delimited imports for VisualBasic
|
|
||||||
///
|
///
|
||||||
/// Emit options:
|
/// Emit options:
|
||||||
/// platform:string - limit which platforms this code can run on; must be x86, x64, Itanium, arm, AnyCPU32BitPreferred or anycpu (default)
|
/// platform:string - limit which platforms this code can run on; must be x86, x64, Itanium, arm, AnyCPU32BitPreferred or anycpu (default)
|
||||||
|
@ -497,18 +477,9 @@ namespace Microsoft.PowerShell.Commands
|
||||||
" {{\n" +
|
" {{\n" +
|
||||||
" {1}\n" +
|
" {1}\n" +
|
||||||
" }}\n";
|
" }}\n";
|
||||||
case Language.VisualBasic:
|
|
||||||
return
|
|
||||||
" public Class {0}\n" +
|
|
||||||
" \n" +
|
|
||||||
" {1}\n" +
|
|
||||||
" \n" +
|
|
||||||
" End Class\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Diagnostics.Assert(false, "GetMethodTemplate: Unsupported language.");
|
throw PSTraceSource.NewNotSupportedException();
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the -FromMember namespace template for a given language
|
// Get the -FromMember namespace template for a given language
|
||||||
|
@ -522,17 +493,9 @@ namespace Microsoft.PowerShell.Commands
|
||||||
"{{\n" +
|
"{{\n" +
|
||||||
"{1}\n" +
|
"{1}\n" +
|
||||||
"}}\n";
|
"}}\n";
|
||||||
case Language.VisualBasic:
|
|
||||||
return
|
|
||||||
"Namespace {0}\n" +
|
|
||||||
"\n" +
|
|
||||||
"{1}\n" +
|
|
||||||
"End Namespace\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Diagnostics.Assert(false, "GetNamespaceTemplate: Unsupported language.");
|
throw PSTraceSource.NewNotSupportedException();
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the -FromMember namespace template for a given language
|
// Get the -FromMember namespace template for a given language
|
||||||
|
@ -546,17 +509,9 @@ namespace Microsoft.PowerShell.Commands
|
||||||
"using System.Runtime.InteropServices;\n" +
|
"using System.Runtime.InteropServices;\n" +
|
||||||
"{0}" +
|
"{0}" +
|
||||||
"\n";
|
"\n";
|
||||||
case Language.VisualBasic:
|
|
||||||
return
|
|
||||||
"Imports System\n" +
|
|
||||||
"Imports System.Runtime.InteropServices\n" +
|
|
||||||
"{0}" +
|
|
||||||
"\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Diagnostics.Assert(false, "GetUsingTemplate: Unsupported language.");
|
throw PSTraceSource.NewNotSupportedException();
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate the code for the using statements
|
// Generate the code for the using statements
|
||||||
|
@ -572,15 +527,9 @@ namespace Microsoft.PowerShell.Commands
|
||||||
usingNamespaceSet.Append("using " + namespaceValue + ";\n");
|
usingNamespaceSet.Append("using " + namespaceValue + ";\n");
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Language.VisualBasic:
|
|
||||||
foreach (string namespaceValue in UsingNamespace)
|
|
||||||
{
|
|
||||||
usingNamespaceSet.Append("Imports " + namespaceValue + "\n");
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
Diagnostics.Assert(false, "GetUsingSet: Unsupported language.");
|
throw PSTraceSource.NewNotSupportedException();
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return usingNamespaceSet.ToString();
|
return usingNamespaceSet.ToString();
|
||||||
|
@ -910,14 +859,10 @@ namespace Microsoft.PowerShell.Commands
|
||||||
{
|
{
|
||||||
case Language.CSharp:
|
case Language.CSharp:
|
||||||
return CSharpCommandLineParser.Default.Parse(args, baseDirectory, sdkDirectory, additionalReferenceDirectories);
|
return CSharpCommandLineParser.Default.Parse(args, baseDirectory, sdkDirectory, additionalReferenceDirectories);
|
||||||
case Language.VisualBasic:
|
|
||||||
return VisualBasicCommandLineParser.Default.Parse(args, baseDirectory, sdkDirectory, additionalReferenceDirectories);
|
|
||||||
default:
|
|
||||||
Diagnostics.Assert(false, "ParseCompilerOption: Unsupported language family.");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
default:
|
||||||
|
throw PSTraceSource.NewNotSupportedException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private SyntaxTree ParseSourceText(SourceText sourceText, ParseOptions parseOptions, string path = "")
|
private SyntaxTree ParseSourceText(SourceText sourceText, ParseOptions parseOptions, string path = "")
|
||||||
|
@ -927,15 +872,9 @@ namespace Microsoft.PowerShell.Commands
|
||||||
case Language.CSharp:
|
case Language.CSharp:
|
||||||
return CSharpSyntaxTree.ParseText(sourceText, (CSharpParseOptions) parseOptions, path);
|
return CSharpSyntaxTree.ParseText(sourceText, (CSharpParseOptions) parseOptions, path);
|
||||||
|
|
||||||
case Language.VisualBasic:
|
|
||||||
return VisualBasicSyntaxTree.ParseText(sourceText, (VisualBasicParseOptions) parseOptions, path);
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Diagnostics.Assert(false, "ParseSourceText: Unsupported language family.");
|
throw PSTraceSource.NewNotSupportedException();
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private CompilationOptions GetDefaultCompilationOptions()
|
private CompilationOptions GetDefaultCompilationOptions()
|
||||||
|
@ -945,15 +884,9 @@ namespace Microsoft.PowerShell.Commands
|
||||||
case Language.CSharp:
|
case Language.CSharp:
|
||||||
return new CSharpCompilationOptions(OutputAssemblyTypeToOutputKind(OutputType));
|
return new CSharpCompilationOptions(OutputAssemblyTypeToOutputKind(OutputType));
|
||||||
|
|
||||||
case Language.VisualBasic:
|
|
||||||
return new VisualBasicCompilationOptions(outputKind: OutputAssemblyTypeToOutputKind(OutputType));
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Diagnostics.Assert(false, "GetDefaultCompilationOptions: Unsupported language family.");
|
throw PSTraceSource.NewNotSupportedException();
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool isSourceCodeUpdated(List<SyntaxTree> syntaxTrees, out Assembly assembly)
|
private bool isSourceCodeUpdated(List<SyntaxTree> syntaxTrees, out Assembly assembly)
|
||||||
|
@ -1069,16 +1002,12 @@ namespace Microsoft.PowerShell.Commands
|
||||||
references: references,
|
references: references,
|
||||||
options: (CSharpCompilationOptions)compilationOptions);
|
options: (CSharpCompilationOptions)compilationOptions);
|
||||||
break;
|
break;
|
||||||
case Language.VisualBasic:
|
|
||||||
compilation = VisualBasicCompilation.Create(
|
default:
|
||||||
PathType.GetRandomFileName(),
|
throw PSTraceSource.NewNotSupportedException();
|
||||||
syntaxTrees: syntaxTrees,
|
|
||||||
references: references,
|
|
||||||
options: (VisualBasicCompilationOptions)compilationOptions);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DoEmitAndLoadAssemply(compilation, emitOptions);
|
DoEmitAndLoadAssembly(compilation, emitOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CheckDuplicateTypes(Compilation compilation, out ConcurrentBag<String> newTypes)
|
private void CheckDuplicateTypes(Compilation compilation, out ConcurrentBag<String> newTypes)
|
||||||
|
@ -1162,12 +1091,12 @@ namespace Microsoft.PowerShell.Commands
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void CacheAssemply(Assembly assembly)
|
private void CacheAssembly(Assembly assembly)
|
||||||
{
|
{
|
||||||
s_sourceAssemblyCache.Add(_syntaxTreesHash, assembly);
|
s_sourceAssemblyCache.Add(_syntaxTreesHash, assembly);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void DoEmitAndLoadAssemply(Compilation compilation, EmitOptions emitOptions)
|
private void DoEmitAndLoadAssembly(Compilation compilation, EmitOptions emitOptions)
|
||||||
{
|
{
|
||||||
EmitResult emitResult;
|
EmitResult emitResult;
|
||||||
|
|
||||||
|
@ -1189,7 +1118,7 @@ namespace Microsoft.PowerShell.Commands
|
||||||
Assembly assembly = AssemblyLoadContext.Default.LoadFromStream(ms);
|
Assembly assembly = AssemblyLoadContext.Default.LoadFromStream(ms);
|
||||||
|
|
||||||
CacheNewTypes(newTypes);
|
CacheNewTypes(newTypes);
|
||||||
CacheAssemply(assembly);
|
CacheAssembly(assembly);
|
||||||
|
|
||||||
if (PassThru)
|
if (PassThru)
|
||||||
{
|
{
|
||||||
|
@ -1212,7 +1141,7 @@ namespace Microsoft.PowerShell.Commands
|
||||||
Assembly assembly = Assembly.LoadFrom(_outputAssembly);
|
Assembly assembly = Assembly.LoadFrom(_outputAssembly);
|
||||||
|
|
||||||
CacheNewTypes(newTypes);
|
CacheNewTypes(newTypes);
|
||||||
CacheAssemply(assembly);
|
CacheAssembly(assembly);
|
||||||
|
|
||||||
WriteTypes(assembly);
|
WriteTypes(assembly);
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,30 +34,6 @@ Describe "Add-Type" -Tags "CI" {
|
||||||
Set-Content -Path $CSharpFile1 -Value $CSharpCode1 -Force
|
Set-Content -Path $CSharpFile1 -Value $CSharpCode1 -Force
|
||||||
Set-Content -Path $CSharpFile2 -Value $CSharpCode2 -Force
|
Set-Content -Path $CSharpFile2 -Value $CSharpCode2 -Force
|
||||||
|
|
||||||
$VBCode1 = @"
|
|
||||||
Namespace Test.AddType
|
|
||||||
Public Class VBTest1$guid
|
|
||||||
Public Shared Function Add1(a As Integer, b As Integer) As String
|
|
||||||
return (a + b)
|
|
||||||
End Function
|
|
||||||
End Class
|
|
||||||
End Namespace
|
|
||||||
"@
|
|
||||||
$VBCode2 = @"
|
|
||||||
Namespace Test.AddType
|
|
||||||
Public Class VBTest2$guid
|
|
||||||
Public Shared Function Add2(a As Integer, b As Integer) As String
|
|
||||||
return (a + b)
|
|
||||||
End Function
|
|
||||||
End Class
|
|
||||||
End Namespace
|
|
||||||
"@
|
|
||||||
$VBFile1 = Join-Path -Path $TestDrive -ChildPath "VBFile1.vb"
|
|
||||||
$VBFile2 = Join-Path -Path $TestDrive -ChildPath "VBFile2.vb"
|
|
||||||
|
|
||||||
Set-Content -Path $VBFile1 -Value $VBCode1 -Force
|
|
||||||
Set-Content -Path $VBFile2 -Value $VBCode2 -Force
|
|
||||||
|
|
||||||
$codeWarning = @"
|
$codeWarning = @"
|
||||||
namespace Test.AddType
|
namespace Test.AddType
|
||||||
{
|
{
|
||||||
|
@ -74,7 +50,7 @@ Describe "Add-Type" -Tags "CI" {
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Public 'Language' enumeration contains all members" {
|
It "Public 'Language' enumeration contains all members" {
|
||||||
[Enum]::GetNames("Microsoft.PowerShell.Commands.Language") -join "," | Should -BeExactly "CSharp,VisualBasic"
|
[Enum]::GetNames("Microsoft.PowerShell.Commands.Language") -join "," | Should -BeExactly "CSharp"
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should not throw given a simple C# class definition" {
|
It "Should not throw given a simple C# class definition" {
|
||||||
|
@ -85,13 +61,6 @@ Describe "Add-Type" -Tags "CI" {
|
||||||
[CSharpfooType].Name | Should BeExactly "CSharpfooType"
|
[CSharpfooType].Name | Should BeExactly "CSharpfooType"
|
||||||
}
|
}
|
||||||
|
|
||||||
It "Should not throw given a simple VisualBasic class definition" {
|
|
||||||
# In subsequent launches from the same session
|
|
||||||
# the test will be passed without real compile - it will return an assembly previously compiled.
|
|
||||||
{ Add-Type -TypeDefinition "Public Class VBfooType `n End Class" -Language VisualBasic } | Should Not Throw
|
|
||||||
[VBfooType].Name | Should BeExactly "VBfooType"
|
|
||||||
}
|
|
||||||
|
|
||||||
It "Can use System.Management.Automation.CmdletAttribute" {
|
It "Can use System.Management.Automation.CmdletAttribute" {
|
||||||
$code = @"
|
$code = @"
|
||||||
using System.Management.Automation;
|
using System.Management.Automation;
|
||||||
|
@ -127,13 +96,6 @@ public class AttributeTest$guid : PSCmdlet
|
||||||
file2 = $CSharpFile2
|
file2 = $CSharpFile2
|
||||||
sourceLanguage = "CSharp"
|
sourceLanguage = "CSharp"
|
||||||
}
|
}
|
||||||
@{
|
|
||||||
type1 = "[Test.AddType.VBTest1$guid]"
|
|
||||||
type2 = "[Test.AddType.VBTest2$guid]"
|
|
||||||
file1 = $VBFile1
|
|
||||||
file2 = $VBFile2
|
|
||||||
sourceLanguage = "VisualBasic"
|
|
||||||
}
|
|
||||||
) {
|
) {
|
||||||
param($type1, $type2, $file1, $file2, $sourceLanguage)
|
param($type1, $type2, $file1, $file2, $sourceLanguage)
|
||||||
|
|
||||||
|
@ -167,16 +129,6 @@ public class AttributeTest$guid : PSCmdlet
|
||||||
expectedResult = "System.Text.UTF8Encoding+UTF8EncodingSealed"
|
expectedResult = "System.Text.UTF8Encoding+UTF8EncodingSealed"
|
||||||
sourceLanguage = "CSharp"
|
sourceLanguage = "CSharp"
|
||||||
}
|
}
|
||||||
@{
|
|
||||||
sourceCode = "Public Shared Function TestString() As String `n Return UTF8Encoding.UTF8.ToString() `n End Function"
|
|
||||||
sourceType = "TestVisualBasicType1"
|
|
||||||
sourceNS = "TestVisualBasicNS"
|
|
||||||
sourceUsingNS = "System.Text"
|
|
||||||
sourceRunType = "TestVisualBasicNS.TestVisualBasicType1"
|
|
||||||
sourceDefaultNSRunType = "Microsoft.PowerShell.Commands.AddType.AutoGeneratedTypes.TestVisualBasicType1"
|
|
||||||
expectedResult = "System.Text.UTF8Encoding+UTF8EncodingSealed"
|
|
||||||
sourceLanguage = "VisualBasic"
|
|
||||||
}
|
|
||||||
) {
|
) {
|
||||||
param($sourceCode, $sourceType, $sourceNS, $sourceUsingNS, $sourceRunType, $sourceDefaultNSRunType, $expectedResult, $sourceLanguage)
|
param($sourceCode, $sourceType, $sourceNS, $sourceUsingNS, $sourceRunType, $sourceDefaultNSRunType, $expectedResult, $sourceLanguage)
|
||||||
|
|
||||||
|
@ -253,7 +205,6 @@ public class AttributeTest$guid : PSCmdlet
|
||||||
|
|
||||||
# Catch non-termination information error for CompilerOptions.
|
# Catch non-termination information error for CompilerOptions.
|
||||||
{ Add-Type -CompilerOptions "/platform:anycpuERROR" -Language CSharp -MemberDefinition "public static string TestString() { return ""}" -Name "TestType1" -Namespace "TestNS" -ErrorAction Stop } | Should -Throw -ErrorId "SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand"
|
{ Add-Type -CompilerOptions "/platform:anycpuERROR" -Language CSharp -MemberDefinition "public static string TestString() { return ""}" -Name "TestType1" -Namespace "TestNS" -ErrorAction Stop } | Should -Throw -ErrorId "SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand"
|
||||||
{ Add-Type -CompilerOptions "/platform:anycpuERROR" -Language VisualBasic -MemberDefinition "Public Shared Function TestString() As String `n Return `"`" `n End Function" -Name "TestType1" -Namespace "TestNS" -ErrorAction Stop } | Should -Throw -ErrorId "SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
It "OutputType parameter requires that the OutputAssembly parameter be specified." {
|
It "OutputType parameter requires that the OutputAssembly parameter be specified." {
|
||||||
|
@ -269,4 +220,10 @@ public class AttributeTest$guid : PSCmdlet
|
||||||
Add-Type -TypeDefinition $codeWarning -IgnoreWarnings -WarningVariable warnVar -WarningAction SilentlyContinue
|
Add-Type -TypeDefinition $codeWarning -IgnoreWarnings -WarningVariable warnVar -WarningAction SilentlyContinue
|
||||||
$warnVar.Count | Should -Be 1
|
$warnVar.Count | Should -Be 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
It "Throw terminating error when file with non-supported extension is passed to -Path" {
|
||||||
|
$VBFile = Join-Path -Path $TestDrive -ChildPath "VBFile.vb"
|
||||||
|
New-Item -Path $VBFile -ItemType File -Force > $null
|
||||||
|
{ Add-Type -Path $VBFile } | Should -Throw -ErrorId "EXTENSION_NOT_SUPPORTED,Microsoft.PowerShell.Commands.AddTypeCommand"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue