我一直在使用托管 IronPython、IronRuby 和(希望如此)PowerShell 的 ac# 应用程序。由于 IronPython 和 IronRuby 完全建立在 DLR 之上,因此使用它们的 API 几乎相同。
IronPython.Hosting.Python.CreateEngine()
和
IronRuby.Ruby.CreateEngine()
两者都创建Microsoft.Scripting.Hosting.ScriptEngine的实例。有没有希望强制 PowerShell 3.0 创建一个 ScriptEngine?我在这个主题上找不到太多东西,除了 PowerShell 3.0 似乎比以前的版本更多地构建在 DLR 上(参见http://huddledmasses.org/powershell-3-finally-on-the-dlr。
您似乎无法将使用以下内容创建的 PowerShell 引擎强制转换为 ScriptEngine。
System.Management.Automation.PowerShell.Create()
我怀疑如果我真的想通过相同的 API 处理 PowerShell,我需要创建自己的 ScriptEngine 来包装 PowerShell 主机。