我如何能够在2015年VS C#脚本? [英] How do I enable C# scripting in VS 2015?

查看:580
本文介绍了我如何能够在2015年VS C#脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何配置VS 2015年使罗斯林的C#脚本功能?

How do I configure VS 2015 to enable Roslyn's C# scripting capabilities?

我已经试过各种安装包的NuGet,包括1.0和1.1.0-β1 Microsoft.CodeAnalysis.CSharp,Microsoft.CodeAnalysis.Scripting.CSharp等版本,但我不能得到任何的我在网上找到工作的例子。我得到类型未找到的错误,即

I've tried installing various Nuget packages, including both the 1.0 and 1.1.0-beta1 versions of Microsoft.CodeAnalysis.CSharp, Microsoft.CodeAnalysis.Scripting.CSharp, etc., but I can't get any of the examples I've found online to work. I am getting "type not found" errors, i.e.,

VAR的ScriptEngine =新的ScriptEngine();

var scriptEngine = new ScriptEngine();

......因为类型的ScriptEngine找不到失败。

... fails because the type "ScriptEngine" is not found.

有人可以提供尽可能的食谱,包括的NuGet要安装的软件包,其中using语句是必需的,等等。 ?,实现罗斯林脚本

Can someone provide as recipe that includes which nuget packages to install, which using statements are required, etc., to implement Roslyn scripting?

更新#1:

我已经取得了一些进展,但仍然有问题。我得到了一堆编译器警告,然后一个TypeInitilizationException这显然是由于组件版本不匹配。

I have made some progress, but still having issues. I get a bunch of compiler warnings and then a TypeInitilizationException which is apparently due to a component version mismatch.

我现在用下面的代码示例(从测试取),而且也没有丢失类型:

I'm now using the following example code (taken from a test), and there's 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());  
      }  
   }  
}  



我已经加载的所有的每晚包可用在 https://www.myget.org/F/roslyn-nightly /

我得到了一系列的参考Microsoft.CodeAnalysis,v1.1.0.0版本警告。

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

运行,尽管警告EXE产生上述TypeInitilizationException。基于堆栈跟踪,该TypeInitializationError是由一个版本不匹配System.Reflection.Metadata.dll引起的。

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

我不知道在哪里可以从这里走。我不明白是怎么脚本相关的软件包/组件结合在一起的。我看到了从今年早些时候描述全面建设罗斯林一些职位。我没有这样做。有必要吗?

I am not sure where to go from here. I don't understand how the scripting-related packages/components fit together. I saw some posts from earlier this year that describe building Roslyn completely. I have not done that. Is that necessary?

这是提醒我从昔日的DLL地狱。

This is reminding me of DLL hell from the old days.

推荐答案

该脚本的API仍在进行中,并从发布包被拆除。

The scripting APIs are still in progress, and were removed from the release packages.

尝试Nightlies版来代替。

Try the nightlies instead.

这篇关于我如何能够在2015年VS C#脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆