.NET scripting solution? RRS feed

  • Question

  • Hi all,


    I've been doing some research into .NET scripting solutions (something like VBA or Windows Scripting Host). It looks like VSA has been deprecated and VSTA is the new way two go. Well, VSTA is royalty based and that's not going to fly in my company. I'm not entirely sure VSTA is what we need to begin with. I need to be able to do the following.

    • Have a way for end users to register a script file and associate it with an application task (e.g. "After document is saved" ->
    • I need to be able to load the script file, pass it 1 or more business objects and execute it.
    • After the script executes I want to be able reference the BO(s) and used them.
    • The scripting language should be a real scripting language and not a file containing VB.NET or C# code.

    VBA seems capable of doing this but we use generics a lot and I dread having to write a whole bunch of COM wrappers for my BOs.


    We're at a crucial point and we need to make a decision soon. Can anybody recommend a good strategy?




    Thursday, March 6, 2008 6:17 PM


  • Hi,


    If you're not interested in going the VSTA route, I would suggest taking a look at the System.CodeDom.Compiler namespace, specifically the CodeDomProvider class, and its CompileAssemblyFromSource method.

    I have used these classes to do basically what you are attempting.

    If you define a strict design, such as the 'script' as the body of a well known method contract, or interface, then you can 'wrap' the script that the user writes in your contract code (such as a class and namespace), then use the compiler to generate an in-memory assembly which you can the grab a type from, and execute its methods passing your environment variables which the script is expecting.

    This works well for simple scenarios.

    I say 'simple' scenarios, because obviously you still have no design environment for assisting the user in creating their scripts.

    If you wanted to go further, you could grab a C# parser (such as the great CSParser), and create a simple IDE for assisting the user in creating their scripts. The CodeDomProvider will return a list of compilation errors should there be any.

    Alternately, theres also a few good pure .net syntax highlighting text controls available.

    So, all the tools are there for avoiding VSTA - but you're obviously going to miss out on inline debugging aswell... all the niceities that come with VSTA.




    Adam Langley

    Thursday, March 6, 2008 8:56 PM