Visual Studio外部的C#REPL

F#有一个REPL(读取 – 评估 – 打印循环)F#Interactive, C:\Program Files (x86)\Microsoft F#\v4.0\Fsi.exe

我知道C#现在有自己的交互式REPL,与Roslyn一起发布。 如何在Visual Studio外部打开? csi.exe在哪里?

C#Interactive窗口和csi.exe REPL被添加到Visual Studio 2015 Update 1 (强调我的):

介绍互动

交互式窗口又回来了! C#Interactive窗口返回Visual Studio 2015 Update 1以及其他一些交互式处理:

  • C#互动 。 C#Interactive窗口本质上是一个read-eval-print-loop(REPL),允许您使用.NET技术进行游戏和探索,同时利用IntelliSense,语法着色等编辑器function。了解有关如何使用C#的更多信息在第9频道互动或阅读我们的初学者演练。

  • csi 。 如果您不想打开Visual Studio来使用C#或运行脚本文件,则可以从Developer Command Prompt访问交互式引擎。 键入csi /path/myScript.csx 以执行脚本文件或仅键入 csi 以放入命令行REPL。

  • 脚本API 。 Scripting API使您能够在主机创建的执行环境中执行C#代码片段。 您可以通过查看我们的代码示例来了解有关如何创建自己的C#脚本引擎的更多信息。

请参阅.NET Managed Languages的Visual Studio 2015 Update 1中的新增function 。


https://www.visualstudio.com/en-us/news/vs2015-update1-vs.aspx

 >csi Microsoft (R) Visual C# Interactive Compiler version 1.1.0.51109 Copyright (C) Microsoft Corporation. All rights reserved. Type "#help" for more information. > #help Keyboard shortcuts: Enter If the current submission appears to be complete, evaluate it. Otherwise, insert a new line. Escape Clear the current submission. UpArrow Replace the current submission with a previous submission. DownArrow Replace the current submission with a subsequent submission (after having previously navigated backwards). REPL commands: #help Display help on available commands and key bindings. Script directives: #r Add a metadata reference to specified assembly and all its dependencies, eg #r "myLib.dll". #load Load specified script file and execute it, eg #load "myScript.csx". > > Enumerable.Range(10) (1,12): error CS7036: There is no argument given that corresponds to the required formal parameter 'count' of 'Enumerable.Range(int, int)' > Enumerable.Range(1, 10) RangeIterator { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 } 

我创建了你要求的东西,一个在VisualStudio之外运行的基于Roslyn的REPL。

您可以从PoC-Roslyn C#ScriptEngine执行v1.0.exe下载它,它是一个独立的exe,包含所有Roslyn程序集作为嵌入式资源。 另请参见video:使用O2基于Roslyn的C#REPL脚本环境

请注意,我为O2平台开发了一个更强大的C#REPL,您可以从C#REPL脚本环境中查看和下载

关于Roslyn的主题,我创建了许多其他独立工具 :

  • Util – 查看Roslyn AST Graph v1.0.exe – 很高兴看到Roslyn创建的AST树
  • Util – Exe Creator(使用Roslyn Compiler v1.0.exe – 很好的工具来创建独立的exes
  • Util – Roslyn – 编译解决方案并查看错误v1.0.exe – 编译整个解决方案
  • Util – Roslyn – OnSave编译解决方案(使用REPL)v1.0.exe – 为Roslyn对象添加REPL
  • PoC – InitializerExpressions v1.0.exe上的Roslyn重构 – 显示了一个重构示例
  • Util – Roslyn AST通过REPL Script v1.0.exe重构 – gui开发重构脚本
  • Util – Roslyn Cat.Net-编译和扫描解决方案v1.0.exe – 显示代码编译和安全扫描的集成(Cat.NET将在第一次执行此工具时下载)

请注意,所有这些工具和O2平台都是在开源许可下发布的,所以请随意扩展并使它们更好:)

我找到的唯一可执行文件是C:\Program Files (x86)\Microsoft Codename Roslyn CTP\Binaries\rcsi.exe ,它可以执行.csx文件。 但它似乎并没有真正支持REPL。

脚本如何: http ://scriptcs.net/?

有一个REPL,你甚至可以获得NuGet的力量。

它可能不是替代品,但我主要使用RoslynPad进行快速研究和测试。 我也用过Linqpad。 根据他们的网站https://roslynpad.net/,RoslynPad是“基于Roslyn的简单C#编辑器”。 你可以编写小脚本,你可以看到变量值’,你也可以保存它们。

Anders Hejlsberg在此video中构建了一个C#REPL循环,时间为65分钟:

http://channel9.msdn.com/Events/PDC/PDC08/TL16#time=65m00s

这是Roslyn的一个旧版本,但同样的想法适用(和eval !;)。