Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# REPL outside Visual Studio

F# has a REPL (read–eval–print loop) F# Interactive, C:\Program Files (x86)\Microsoft F#\v4.0\Fsi.exe.

I understand C# now has its own interactive REPL, as released with Roslyn. How do I open outside Visual Studio? Where is csi.exe?

like image 412
Colonel Panic Avatar asked Jun 11 '12 13:06

Colonel Panic


People also ask

What C is used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

What is the full name of C?

In the real sense it has no meaning or full form. It was developed by Dennis Ritchie and Ken Thompson at AT&T bell Lab. First, they used to call it as B language then later they made some improvement into it and renamed it as C and its superscript as C++ which was invented by Dr. Stroustroupe.

Is C language easy?

C is a general-purpose language that most programmers learn before moving on to more complex languages. From Unix and Windows to Tic Tac Toe and Photoshop, several of the most commonly used applications today have been built on C. It is easy to learn because: A simple syntax with only 32 keywords.

Is C programming hard?

C is more difficult to learn than JavaScript, but it's a valuable skill to have because most programming languages are actually implemented in C. This is because C is a “machine-level” language. So learning it will teach you how a computer works and will actually make learning new languages in the future easier.


2 Answers

I created exactly what you are asking for, a Roslyn based REPL running outside VisualStudio.

You can download it from PoC - Roslyn C# ScriptEngine Execute v1.0.exe which is a stand-alone exe containing all Roslyn assemblies as embedded resources. See also Video: Using O2's Roslyn-based C# REPL Script environment

Note that I have developed a more powerful C# REPL for the O2 Platform, which you can see and download from C# REPL Script Environment

On the topic of Roslyn, here are a number of other stand-alone tools that I created:

  • Util - View Roslyn AST Graph v1.0.exe - good to see the AST tree created by Roslyn
  • Util - Exe Creator (using Roslyn Compiler v1.0.exe - Nice tool to create stand alone exes
  • Util - Roslyn - Compile Solution and view errors v1.0.exe - compile entire solutions
  • Util - Roslyn - OnSave Compile Solution (with REPL) v1.0.exe - adds a REPL for Roslyn objects
  • PoC - Roslyn refactor on InitializerExpressions v1.0.exe - shows an refactoring example
  • Util - Roslyn AST Refactoring via REPL Script v1.0.exe - gui to develop refactoring scripts
  • Util - Roslyn Cat.Net- Compile and Scan Solution v1.0.exe - shows integration of code compile and security scanning (Cat.NET will be download the first time this tool is executed)

Note that all these tools and the O2 Platform are released under an Open Source license, so please fell free to expand and make them better :)

like image 44
Dinis Cruz Avatar answered Sep 18 '22 17:09

Dinis Cruz


C# Interactive window and csi.exe REPL were added to Visual Studio 2015 Update 1 (emphasis mine):

Introducing Interactive

The Interactive Window is back! The C# Interactive Window returns in Visual Studio 2015 Update 1 along with a couple other interactive treats:

  • C# Interactive. The C# Interactive window is essentially a read-eval-print-loop (REPL) that allows you to play and explore with .NET technologies while taking advantage of editor features like IntelliSense, syntax-coloring, etc. Learn more about how to use C# Interactive on Channel 9 or by reading our beginner’s walkthrough.

  • csi. If you don’t want to open Visual Studio to play around with C# or run a script file, you can access the interactive engine from the Developer Command Prompt. Type csi /path/myScript.csx to execute a script file or type simply csi to drop inside the command-line REPL.

  • Scripting APIs. The Scripting APIs give you the ability to execute snippets of C# code in a host-created execution environment. You can learn more about how to create your own C# script engine by checking out our code samples.

See What’s New in Visual Studio 2015 Update 1 for .NET Managed Languages.


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, e.g. #r "myLib.dll".   #load         Load specified script file and execute it, e.g. #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 } 
like image 197
Athari Avatar answered Sep 21 '22 17:09

Athari