Click here to Skip to main content
15,887,371 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more: , +
How do I configure VS2015 to support Rosyln C# scripting? Scripting support was not part of the VS2015 RTM, so I've installed packages from roslyn-nightly and dotnet-core but I can't get past component version mismatches.

1 – My goal is to embed C# expressions inside configuration-related scripts used by my program. I am replacing an old VB6 program that used VBA for the same purpose. That solution worked really, really well and made the old program quite flexible.

2 – I am using VS2015 RTM, the Community version. VS2013 Professional is also installed on my PC. The PC is running Win7 SP1.

3 – I've installed various packages from roslyn-nightly and dotnet-core. I started by installing a bare minimum, but based on error messages and advice from various people I have tried many variations of packages. I admit I really have no idea which packages are necessary. Determining which packages are necessary has been my main goal, but perhaps the issue lies elsewhere.

4 – I followed the instructions at the URL below.

https://github.com/dotnet/roslyn#build-tools-that-understand-c-and-visual-basic

That includes a link here:

https://github.com/dotnet/roslyn/wiki/Getting-Started-on-Visual-Studio-2015

5 – I am using the following code to test whether or not I've got VS configured properly to support scripting:
C#
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 lifted code from one of the Roslyn test files then put it in a Console project and added the Console.WriteLine call.

6 – I get various warning messages when I build the project. The specific messages vary based on which packages are installed, but they always include messages about missing files that appear to be caused by version mismatches. Here is an example from the current incantation of the project which includes most (if not all) of the packages available at roslyn-nightly and several from dotnet-core. I do not know how to efficiently communicate which packages I have installed given there are so many (43).

Warning, MissingAnalyzerReference, Analyzer assembly 'C:\Dev\vsProjects\Experiments\RoslynScriptingTest\packages\Microsoft.AnalyzerPowerPack.1.1.0-beta1-20150726-01\analyzers\dotnet\cs\Microsoft.AnalyzerPowerPack.Common.dll' depends on 'Microsoft.CodeAnalysis.Workspaces, Version=1.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' but it was not found. Analyzers may not run correctly.

7 – At runtime, I get a TypeInitializationException on the CSharpScript.Create() call.

I am pulling my hair out and would appreciate some assistance. (Assistance fixing the problem, not with pulling hair out.)
Posted
Updated 29-Jul-15 5:22am
v2
Comments
Kornfeld Eliyahu Peter 29-Jul-15 15:42pm    
It seems that nightly builds you got has some dependency problems...For instance AnalyzerPowerPack had no dependencies at all until now...
Remove the packages (all), clear the package cache, and add stable packages to check if it's work...
JohnnyCee 30-Jul-15 12:41pm    
Scripting is not available in the RTM of VS2015. To get scripting, you have to install packages from the nightly build. It's not clear how to tell which (if any) of those packages are stable, and it's also hard to tell which packages are necessary. I am using about 43 packages now. With the patient help of someone at Microsoft, I've now got scripting working. We narrowed the problem down to an issue with System.Reflection.Metadata. I had to hack around a bit to get a version of System.Reflection.Metadata.dll that would work. I am now trying to build a new project with a minimum of packages/DLLs.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900