[英]PowerShell on Linux - How to load \ use .Net assemblies?
Now that PowerShell is open sourced and available on Linux , any one knows how to add .Net assemblies under linux? 既然PowerShell是开源的,并且可以在Linux上使用 ,那么任何人都知道如何在Linux下添加.Net程序集吗? if at all possible?
如果可能的话?
I have installed PS on Ubuntu 16.04 as in here and installed Mono as in here . 我已经在Ubuntu 16.04安装PS在这里和安装单在这里 。
After running PS on terminal, this line surprisingly works just fine: 在终端上运行PS后,此行令人惊讶地正常工作:
add-type -assembly "/usr/lib/mono/4.5-api/System.Web.Extensions.dll"
No errors etc... 没有错误等...
Yet when I try to: 但是当我尝试:
$js = New-Object "System.Web.Script.Serialization.JavaScriptSerializer"
I am getting this error: 我收到此错误:
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
Any hints on that one? 有什么暗示吗? Is it a bug maybe as powershell on linux is still "alpha"?
这可能是一个错误,因为Linux上的powershell仍然是“ alpha”吗?
BTW - On windows all is working just fine... 顺便说一句-在Windows上一切正常...
PowerShell on Linux is based on CoreCLR while mono is a clone of the CLR / full framework. Linux上的PowerShell基于CoreCLR,而mono是CLR /完整框架的克隆。 The assembly you are using is a full framework one and cannot load in CoreCLR since it is based on mscorlib and not System.Runtime.
您正在使用的程序集是一个完整的框架,由于它基于mscorlib而不是System.Runtime,因此无法在CoreCLR中加载。
In a year there will be a workaround (maybe) with the upcoming .NET Standard 2.0. 一年之内,即将推出的.NET Standard 2.0可能会有变通办法。
Json serialization should be native in PowerShell, if not use newtonsoft.json. 如果不使用newtonsoft.json,则Json序列化应该在PowerShell中是本机的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.