C# Scripting with Microsoft's Project Roslyn

  • 730 views
Uploaded on

At BASTA Spring 2014 conference I did a talk about C# Scripting with Microsoft's Project Roslyn. See my blog at http://www.software-architects.com for details.

At BASTA Spring 2014 conference I did a talk about C# Scripting with Microsoft's Project Roslyn. See my blog at http://www.software-architects.com for details.

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
730
On Slideshare
0
From Embeds
0
Number of Embeds
6

Actions

Shares
Downloads
0
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. C# Scripting with Project Roslyn
  • 2. BASTA! Spring 2014 Rainer Stropek software architects gmbh C# Scripting Web http://www.timecockpit.com Mail rainer@timecockpit.com Twitter @rstropek with Project Roslyn Saves the day.
  • 3. Why Scripting?  Typical use cases Automate routine jobs (macros) Interfaces Installation, maintenance, updates Prototyping Software factories  Advantages Possibility to customize and extend at the customer site  business opportunity No complex prerequisites (e.g. Visual Studio), just a text editor REPL and dynamic scripting is efficient in certain situations
  • 4. Why Scripting? Software Factory Projekt A Projekt B Custom Code Custom Code Base Class Library
  • 5. Why Scripting? Software Factory Projekt A Projekt B Model, Extensions, Configuration, Scripts Custom Component Custom Component Model, Extensions, Configuration, Scripts Common Components Base Class Library Custom Component Custom Component
  • 6. Why Scripting? Software Factory  Use classical .NET/C# for building the foundation  Use scripting as the „glue“ between the building blocks Class libraries and APIs Complex business logic Domain-specific libraries Combine existing components to working solutions using scripts Keep simple programs simple by executing text-based code assets
  • 7. Scripting with .NET  Dynamic Language Runtime (DLR) E.g. IronPython (nuget)  JavaScript based on Google‘s V8 E.g. ClearScript (nuget), V8.NET, Javascript.NET, … Embedded browser (e.g. Chromium Embedded Framework (CEF), Awesomium, etc.)  C# or VB Scripting with Project Roslyn Roslyn home Roslyn scripting specs
  • 8. Scripting with .NET   DLR with IronPython Part of .NET for quite a while Very good .NET integration Access to entire .NET framework Open source with active community Production-level quality Simple programming model Language is platform-independent Open source, future? JavaScript with V8 Compatibility to browsers and server (nodejs) Not core part of .NET Weaker .NET integration  C# and VB Scripting Not production yet The programming language you know and love Naturally very good .NET integration Powerful programming model (entire C# compiler pipeline) Dynamic programming (dynamic keyword) currently not supported
  • 9. Getting Started Add nuget package Roslyn.Compilers.CSharp
  • 10. Roslyn.Scripting.CSharp.ScriptEngine  Store a set of assembly references and imported namespaces ScriptEngine.AddReference ScriptEngine.ImportNamespace  You can create multiple engine instances in an AppDomain
  • 11. Script Engine Setting up the basics Demo
  • 12. Roslyn.Scripting.Session  Created based on an engine ScriptEngine.CreateSession References and Namespaces copied from engine when session is created  Add assembly references and imported namespaces to the ones defined on engine-level Session.AddReference Session.ImportNamespace  Represents a cumulative execution context E.g. define function in one code snippet, use it in the second snippet
  • 13. Script Session Setting up the basics Demo
  • 14. Roslyn.Scripting.Session  Executing scripts Session.Execute  returns object Session.Execute<T>  returns T Session.ExecuteFile  Host Object Script host’s object model (e.g. dedicated scripting API) Parameter to ScriptEngine.CreateSession Top-level identifiers are bound to the host object  Returning Delegates With Session.Execute<Func<…>>(…) you can return a delegate (lambda or function)
  • 15. Script Session Having fun with scripting… Demo
  • 16. BASTA! Spring 2014 Rainer Stropek software architects gmbh Q&A Mail rainer@timecockpit.com Web http://www.timecockpit.com Twitter @rstropek Thank your for coming! Saves the day.
  • 17. is the leading time tracking solution for knowledge workers. Graphical time tracking calendar, automatic tracking of your work using signal trackers, high level of extensibility and customizability, full support to work offline, and SaaS deployment model make it the optimal choice especially in the IT consulting business. Try for free and without any risk. You can get your trial account at http://www.timecockpit.com. After the trial period you can use for only 0,20€ per user and month without a minimal subscription time and day without a minimal subscription time and without a minimal number of users.
  • 18. ist die führende Projektzeiterfassung für Knowledge Worker. Grafischer Zeitbuchungskalender, automatische Tätigkeitsaufzeichnung über Signal Tracker, umfassende Erweiterbarkeit und Anpassbarkeit, volle Offlinefähigkeit und einfachste Verwendung durch SaaS machen es zur Optimalen Lösung auch speziell im IT-Umfeld. Probieren Sie kostenlos und ohne Risiko einfach aus. Einen Testzugang erhalten Sie unter http://www.timecockpit.com. Danach nutzen Sie um nur 0,20€ pro Benutzer und Tag ohne Mindestdauer und ohne Mindestbenutzeranzahl.