How can I host PowerShell 3.0 in a C # application using a similar API for other DLR languages

I played with a C # application that contains IronPython, IronRuby, and (hopefully) PowerShell. Since IronPython and IronRuby were completely DLR-based, the APIs for using them are pretty much identical.

IronPython.Hosting.Python.CreateEngine() 

and

 IronRuby.Ruby.CreateEngine() 

both create instances of Microsoft.Scripting.Hosting.ScriptEngine . Is there any hope of forcing PowerShell 3.0 to create ScriptEngine? I couldnโ€™t find much on this subject, except PowerShell 3.0 seems to be built on DLR more than the previous version (see http://huddledmasses.org/powershell-3-finally-on-the-dlr .

It doesn't look like you can include a PowerShell engine created with the following in ScriptEngine.

 System.Management.Automation.PowerShell.Create() 

I suspect that if I really want to handle PowerShell through the same API, I need to create my own ScriptEngine that wraps the PowerShell node.

+8
c # powershell dynamic-language-runtime
source share
2 answers

PowerShell V3 does indeed use the DLR part, but only those parts that ship in the .NET Framework V4. There were many useful apis in the DLR project that were not included in .Net, for example. Microsoft.Scripting.Hosting.ScriptEngine.

If PowerShell wants to implement a ScriptEngine script, PowerShell would have to send these apis as part of PowerShell. The PowerShell team was not ready to take responsibility for these apis.

So, you're right that you need to wrap PowerShell with your own code if you want to implement ScriptEngine.

+4
source share

PowerShell works with the dotnet assembly and is very interesting when you have an administrator profile and want to make advanced instructions. But you are a developer, so by wrapping PowerShell you can access the entire dotnet assembly from your code. Best to encode what you want, instead of wrapping PowerShell Best attitude

-one
source share

All Articles