C# 7 support - oleg-shilo/cs-script.net-framework GitHub Wiki
Note this page describes how to enable C# 7 support for standalone script execution (CLI).
Usage
Starting from v3.25.0 CS-Script does support execution of C# 7.0 scripts.
You can enable C#7 syntax support by setting CSSCodeProvider.v4.6.dll (or CSSRoslynProvider.dll in later releases) as your CS-Script code provider. You can do this globally via command line interface (CLI) or via configuration console:
CLI
cscs.exe -config:set:UseAlternativeCompiler=%CSSCRIPT_DIR%\lib\CSSRoslynProvider.dll
In later releases you can use simplified command:
cscs.exe -config:set:roslyn
Config Console
Alternatively you can indicate using C# 7 syntax directly in script code:
//css_args -provider:%CSSCRIPT_DIR%\lib\CSSRoslynProvider.dll
//css_ref %CSSCRIPT_DIR%\lib\Bin\Roslyn\System.ValueTuple.dll
using System;
class Script
{
static public void Main()
{
Unfortunately the default .NET compilers only provide support for C# 5. Both C# 6 and C# 7 syntax flavors are only supported via external compiling services Roslyn.
The default CS-Script distribution includes Roslyn services but they are not activated by default. You can enable them by activating CS-Script wrapper for Roslyn services CSSRoslynProvider.dll
. The activation instructions are above in this section.
Another puzzling C# 7 deployment decision Microsoft has made is about support for tuples. Even with Visual Studio 2017 tuples syntax is no available by default. You need to activate it by importing NuGet ValueTuple package in every Visual Studio project that uses tuple syntax. Of course you can follow this approach and include the same NuGet package or the direct reference to the System.ValueTuple.dll
in every script you execute. However arguably a better approach is to configure CS-Script to include reference System.ValueTuple.dll
automatically for all scripts:
CLI
cscs.exe -config:set:DefaultRefAssemblies="System.Core;System.Linq;System.ValueTuple.dll;"
cscs.exe -config:set:SearchDirs="%CSSCRIPT_DIR%\lib;%CSSCRIPT_INC%;%CSSCRIPT_DIR%\lib\Bin\Roslyn;"
First command above adds System.ValueTuple.dll
to the already defined auto referenced assemblies (System.Core and System.Linq). And second one ensures System.ValueTuple.dll
can be found by adding it's location (%CSSCRIPT_DIR%\lib\Bin\Roslyn
) to the probing directory.