Running scripts inside C #

I want to run javascript / Python / Ruby inside my application.

I have an application that automatically creates a process based on a user definition. The process is generated in C #. I want advanced users to inject script into predefined locations. These scripts must be run from a C # process. For example, the created process will have some actions, and in the middle a script should be launched, and then the process will continue as before. Is there a mechanism to run these scripts from C #?

+6
c # scripting
source share
8 answers

Basically, you have two problems: how to determine the injection point in the generated code and how to run python / ruby ​​/ whatev scripts.

Depending on how you create the process, one possible solution would be to add a function to each possible injection point. The function will check whether the user has associated any scripts with the given points, and if so, runs the script by calling IronPython / IronRuby (with optional specified parameters).

Disadvantages include: limited availability from scripts to the created process (basically, only variables passed as parameters are available); as well as implementation limits (the current version of IronPython skips several basic system functions).

+5
source share

Take a look at IronPython and IronRuby - they will allow you to easily interact with C #.

+2
source share

You can compile C # code from a C # application using the CSharpCodeProvider class.

If compilation succeeds, you can run the resulting assembly returned using the CompiledAssembly property of the CompilerResults class.

+1
source share

Awesome C # scripting language - Script.Net

+1
source share

.NET has a scripting language, including a PowerShell runtime engine, which can be integrated into any .NET application.

+1
source share

You can compile C # code on the fly to an assembly in memory. I think this is possible with IronPython and IronRuby. Take a look at the CodeDomProvider.CreateProvider method.

If you need to run scripts a lot, or if your process has been running for a long time, you can load these assemblies into another AppDomain. And unload AppDomain after completion with a script. Otherwise, you cannot delete them from memory. This has some implications for the other classes of your project, because you have to sort all the calls.

0
source share

Have you thought about Visual Studio for applications? I have not heard much about this with .NET 1.1, but it may be worth a look.

http://msdn.microsoft.com/en-us/library/ms974548.aspx

0
source share

I did just that recently - allowed the addition of C # scripts at runtime.

This is not complicated, and this article:

http://www.divil.co.uk/net/articles/plugins/scripting.asp

- A very useful summary of details.

0
source share

All Articles