Linux 上的 PowerShell - 如何加载\使用 .Net 程序集?
PowerShell on Linux - How to load \ use .Net assemblies?
现在 PowerShell 是 open sourced and available on Linux,谁知道如何在 linux 下添加 .Net 程序集?如果可能的话?
我已经在 Ubuntu 16.04 上安装了 PS,如 here and installed Mono as in here。
在终端上 运行 PS 之后,这条线出人意料地工作得很好:
add-type -assembly "/usr/lib/mono/4.5-api/System.Web.Extensions.dll"
没有错误等...
然而当我尝试:
$js = New-Object "System.Web.Script.Serialization.JavaScriptSerializer"
我收到这个错误:
new-object : Cannot find type [System.Web.Script.Serialization.JavaScriptSerializer]: verify that the
assembly containing this type is loaded.
At line:1 char:10
+ $ps_js = new-object "System.Web.Script.Serialization.JavaScriptSerial ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException
+ FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
有什么提示吗?
这是一个错误吗,因为 linux 上的 powershell 仍然是 "alpha"?
顺便说一句 - 在 windows 上一切正常...
Linux 上的 PowerShell 基于 CoreCLR,而 mono 是 CLR/完整框架的克隆。您使用的程序集是一个完整的框架程序集,无法在 CoreCLR 中加载,因为它基于 mscorlib 而不是 System.Runtime.
一年后,即将推出的 .NET Standard 2.0 将有一个解决方法(也许)。
Json 序列化应该在 PowerShell 中是原生的,如果不使用 newtonsoft.json.
现在 PowerShell 是 open sourced and available on Linux,谁知道如何在 linux 下添加 .Net 程序集?如果可能的话?
我已经在 Ubuntu 16.04 上安装了 PS,如 here and installed Mono as in here。
在终端上 运行 PS 之后,这条线出人意料地工作得很好:
add-type -assembly "/usr/lib/mono/4.5-api/System.Web.Extensions.dll"
没有错误等...
然而当我尝试:
$js = New-Object "System.Web.Script.Serialization.JavaScriptSerializer"
我收到这个错误:
new-object : Cannot find type [System.Web.Script.Serialization.JavaScriptSerializer]: verify that the
assembly containing this type is loaded.
At line:1 char:10
+ $ps_js = new-object "System.Web.Script.Serialization.JavaScriptSerial ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidType: (:) [New-Object], PSArgumentException
+ FullyQualifiedErrorId : TypeNotFound,Microsoft.PowerShell.Commands.NewObjectCommand
有什么提示吗? 这是一个错误吗,因为 linux 上的 powershell 仍然是 "alpha"?
顺便说一句 - 在 windows 上一切正常...
Linux 上的 PowerShell 基于 CoreCLR,而 mono 是 CLR/完整框架的克隆。您使用的程序集是一个完整的框架程序集,无法在 CoreCLR 中加载,因为它基于 mscorlib 而不是 System.Runtime.
一年后,即将推出的 .NET Standard 2.0 将有一个解决方法(也许)。
Json 序列化应该在 PowerShell 中是原生的,如果不使用 newtonsoft.json.