2

Is there a way to use C# as a scripting language? I want users to be able to write a method body and work with objects that are passed from the main program to the script method.

And maybe is there something more universal out there? So I can support more than C#?

3
  • but I read its not ready for production use Commented Jun 17, 2013 at 12:02
  • 1
    I would say your best bet would be Powershell, which you can automate from C#. Roslyn certainly look interesting though! Commented Jun 17, 2013 at 12:04
  • 1
    Why not use a language that was designed to be a scripting langauge instead of one that wasn't? A large number of it's design decisions make it a great language for large scale programs, but those same design decisions make it much clunkier and harder to use in a scripting context. Scripting language aren't better or worse, they're just designed to fill a different role. If that's the role you need filled, use the proper language for the job. Commented Jun 17, 2013 at 14:12

1 Answer 1

7

Check out scriptcs. Scott Hanselman has a great blog post about it here. It allows you to do scripting with C#, either by running arbitrary scripts as *.csx files, written with with your favorite text editor or by using the REPL. It also has integration with NuGet to allow you to easily pull down dependencies.

The ScriptCs.Core library can be used to host script execution in your own application, like OctopusDeploy has done.

The scripting engine is pluggable. As of now, it uses Roslyn as the C# scripting engine, but there's also work being done to use mono as an alternative. There's nothing stopping you from implementing f.ex. F# support.

To make bootstrapping of popular frameworks even easier, there's script packs that reduces the amount of code you have to write to get something running quickly.

To get you started, check out the samples repository.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.