How to enable C # script in VS 2015?

How to configure VS 2015 to enable Roslyn C # scripting features?

I tried installing various Nuget packages, including versions 1.0 and 1.1.0 beta of Microsoft.CodeAnalysis.CSharp, Microsoft.CodeAnalysis.Scripting.CSharp, etc., but I can not get any of the examples I found online for work. I get "type not found" errors, i.e.

var scriptEngine = new ScriptEngine ();

... failed because the type "ScriptEngine" was not found.

Can anyone provide as a recipe, which includes which nuget packages for installation, which use operators, are required, etc. for implementing Roslyn scripts?

UPDATE # 1:

I have made some progress, but still have problems. I get a bunch of compiler warnings, and then a TypeInitilizationException, which seems to be due to component version mismatch.

Now I use the following sample code (taken from the test), and there are no missing types:

using System; using Microsoft.CodeAnalysis.Scripting.CSharp; namespace RoslynScriptingTest { class Program { static void Main(string[] args) { var script = CSharpScript.Create("1 + 2"); var fn = script.CreateDelegate(); var value = fn(); Console.WriteLine("value={0}", value.ToString()); } } } 

I downloaded all the nightly packages available at https://www.myget.org/F/roslyn-nightly/ .

I get a series of build warnings that are related to Microsoft.CodeAnalysis, v1.1.0.0.

Running exe, despite the warnings, throws the TypeInitilizationException mentioned above. Based on stacktrace, TypeInitializationError is caused by a version mismatch for System.Reflection.Metadata.dll.

I'm not sure where to go from here. I do not understand how the packages / components related to the scripts fit together. I saw several posts earlier this year that fully described the construction of Roslin. I didn’t do it. It's necessary?

This reminds me of a hellish DLL from ancient times.

+7
c # scripting roslyn
source share
2 answers

Scripting APIs are still in progress and removed from release packages.

Try the night hours.

+5
source share

With Visual Studio 2015 update, REPL and api script have been updated.

Here's what Microsoft says about it:

In this release, the C # interactive window is in Visual Studio, as well as in the C # REPL command prompt window. (An interactive window is a REPL window inside Visual Studio.)

We also released scripting APIs that allow you to create and run C # as a script. Scripting APIs are available on GitHub.

In addition, we released csi.exe, which is a tool that you can use to run the C # script (.csx) file from the Developer command line. For example, just type csi myScript.csx to run the script file. Or you can enter command line REPL mode to interactively evaluate C # code snippets. To enter this mode, run the csi command without any arguments from the Developer command line.

Link: https://www.visualstudio.com/news/vs2015-update1-vs#Csharp

+2
source share

All Articles