Powershell с c # System.Collections.Generic.dll не найден

1

Я пытаюсь написать сценарий powershell с кодом С#. Код сценария

$code = @"
    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Xml.Linq;
    using System.Runtime.InteropServices;
    using System.Text.RegularExpressions;
"@


[Reflection.Assembly]::LoadWithPartialName("System") 
[Reflection.Assembly]::LoadWithPartialName("System.Collections.Generic") 
[Reflection.Assembly]::LoadWithPartialName("System.IO") 
[Reflection.Assembly]::LoadWithPartialName("System.Linq") 
[Reflection.Assembly]::LoadWithPartialName("System.Xml.Linq") 
[Reflection.Assembly]::LoadWithPartialName("System.Runtime.InteropServices") 
[Reflection.Assembly]::LoadWithPartialName("System.Text.RegularExpressions") 

$refs = @("System", "System.Collections.Generic", "System.IO", "System.Linq", "System.Xml.Linq", "System.Runtime.InteropServices", "System.Text.RegularExpressions")

Add-Type -ReferencedAssemblies $refs -TypeDefinition $code

Когда я получаю свой сценарий, у меня есть ошибка

GAC    Version        Location                                                                                                                                                                
---    -------        --------                                                                                                                                                                
True   v4.0.30319     C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll                                                                             
True   v4.0.30319     C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.IO\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.IO.dll                                                                       
True   v4.0.30319     C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Linq\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Linq.dll                                                                   
True   v4.0.30319     C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll                                                           
True   v4.0.30319     C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Runtime.InteropServices\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Runtime.InteropServices.dll                             
True   v4.0.30319     C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Text.RegularExpressions\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Text.RegularExpressions.dll                             
Add-Type : (0) : Metadata file 'System.Collections.Generic.dll' could not be found
(1) :     using System;
At line:22 char:1
+ Add-Type -ReferencedAssemblies $refs -TypeDefinition $code
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (error CS0006: M...ld not be found:CompilerError) [Add-Type], Exception
    + FullyQualifiedErrorId : SOURCE_CODE_ERROR,Microsoft.PowerShell.Commands.AddTypeCommand

Add-Type : Cannot add type. There were compilation errors.
At line:22 char:1
+ Add-Type -ReferencedAssemblies $refs -TypeDefinition $code
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Add-Type], InvalidOperationException
    + FullyQualifiedErrorId : COMPILER_ERRORS,Microsoft.PowerShell.Commands.AddTypeCommand

Как я могу собрать System.Collections.Generic?

Теги:
powershell

1 ответ

2
Лучший ответ

В пространстве имен System.Collections.Generic отсутствует собственная DLL, содержащаяся в mscorlib.dll.

Вместо этого попробуйте использовать System.Core.

Ещё вопросы

Сообщество Overcoder
Наверх
Меню