C# scripting with Project Roslyn allows running C# code without compiling it into an assembly. It provides advantages like customizing software at the customer site and prototyping without Visual Studio. Scripting can be used as "glue" between classical .NET components in a software factory by combining existing components into solutions using scripts. The Roslyn.Scripting namespaces provide APIs for setting up a script engine and session to execute C# code snippets and scripts.
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
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
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
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
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)
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.