Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/328.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用与其他DLR语言类似的API在c#应用程序中托管PowerShell 3.0_C#_Powershell_Powershell 3.0_Dynamic Language Runtime - Fatal编程技术网

如何使用与其他DLR语言类似的API在c#应用程序中托管PowerShell 3.0

如何使用与其他DLR语言类似的API在c#应用程序中托管PowerShell 3.0,c#,powershell,powershell-3.0,dynamic-language-runtime,C#,Powershell,Powershell 3.0,Dynamic Language Runtime,我一直在玩一个c#应用程序,它托管IronPython、IronRuby和(希望是)PowerShell。由于IronPython和IronRuby完全构建在DLR上,因此使用它们的API几乎完全相同 IronPython.Hosting.Python.CreateEngine() 及 两者都创建Microsoft.Scripting.Hosting.ScriptEngine的实例。是否有希望强制PowerShell 3.0创建脚本引擎?除了PowerShell 3.0之外,我还没有找到更多关

我一直在玩一个c#应用程序,它托管IronPython、IronRuby和(希望是)PowerShell。由于IronPython和IronRuby完全构建在DLR上,因此使用它们的API几乎完全相同

IronPython.Hosting.Python.CreateEngine()

两者都创建Microsoft.Scripting.Hosting.ScriptEngine的实例。是否有希望强制PowerShell 3.0创建脚本引擎?除了PowerShell 3.0之外,我还没有找到更多关于此主题的内容,它似乎比以前的版本更适合在DLR上构建(请参阅)

您似乎无法将使用以下内容创建的PowerShell引擎强制转换为ScriptEngine

System.Management.Automation.PowerShell.Create()

我怀疑,如果我真的想通过相同的API处理PowerShell,我需要创建自己的脚本引擎来包装PowerShell主机。

PowerShell与dotnet程序集一起工作,当您拥有管理员profil 你想制作高级指令。但你是一名开发人员,为什么要包装PowerShell,你可以从代码中访问所有的dotnet程序集。最好编写你想要的代码,而不是包装PowerShell
最好的方面

PowerShell V3确实使用了一些DLR,但只使用了.Net Framework V4中提供的部分。DLR项目有许多有用的API未包含在.Net中,例如Microsoft.Scripting.Hosting.ScriptEngine

System.Management.Automation.PowerShell.Create()
如果PowerShell想要实现ScriptEngine API,PowerShell必须将这些API作为PowerShell的一部分提供。PowerShell团队不愿意拥有这些API


因此,如果要实现ScriptEngine,您可以正确地假设需要使用自己的代码包装PowerShell。

我知道PowerShell的功能有多强大。我正在尝试构建自己的脚本环境,以了解如何嵌入DLR语言。我真的希望能够在同一环境中使用PowerShell和IronPython。大多数DLR语言年龄在嵌入方面表现相同。PowerShell早于DLR,因此我想知道是否有任何方法可以使其表现得像其他DLR语言。
System.Management.Automation.PowerShell.Create()