During the last 10 minutes of Ander's talk The Future of C# he demonstrates a really cool C# Read-Eval-Print loop which would be a tremendous help in learning the language.
Several .NET4 related downloads are already available: Visual Studio 2010 and .NET Framework 4.0 CTP, Visual Studio 2010 and .NET Framework 4 Training Kit. Do you know what happened to this REPL? Is it somewhere hidden among examples?
I know about mono repl. Please, no alternative solutions.
The REPL demo was part of "what might happen next", i.e. after 4.0; in .NET 5.0 or something similar.
This is not 4.0 functionality, and never has been.
It's probably worth mentioning that the Mono project already does have a C# REPL which i tend to use for those small checks you do now and then. Take a look. Also, if I'm testing an idea which I'm uncomfortable Mono is going to handle to well and it's not worth starting a new test project then Snippet Compiler always comes in handy.
The Immediate window (Debug>Windows>Immediate Ctrl+D, I ) is fairly good replacement that's built in. It does require you start the IDE and put a breakpoint on something.
It does give you the context of where you would like to do experimentation.
Marc's answer is entirely correct, the possibility of a repl or script like c# has been discussed by Eric Lippert in two blog posts:
Why doesn't c# implement top level methods
It already is a scripting language
I would add that, the 2010 CTP does contain an f# repl (not much use for c# but if you were interested in some aspect of the BCL or CLR then it might be sufficient for your needs)
I find that LINQPad makes up for the lack of a REPL in many cases. It would be nice to get it integrated into Visual studio so you could interact with your existing code base more easily though.
Take a look at this C# REPL Script Environment which is a great way to quickly run C# script (and learn how to code)
I just published a VisualStudio Extension that provides a REPL environment inside VisualStudio (namely a C# REPL Environment with a Fluent API for .NET and VisualStudio)
In addition to being able to write and execute quick C# snippets (in a REPL environment), you can program VisualStudio IDE in real time!
You can install it using VisualStudio's Extension Manager (search for C# REPL) or via the download link at the VisualStudio Gallery page: VisualStudio C# REPL
The VisualStudio C# REPL page also contains more details and code samples.
There is also an Reddit thread on this extension (which contains more code samples).
Let me know what you think of it
Command-line REPL
To play with the C# REPL outside of Visual Studio, open the Developer Command Prompt for VS2015 and type the command csi to begin your interactive session. Here is a list of arguments that can be passed to csi.
Note: csi stands for "CSharp Interactive"
You can also open an interactive window directly from Visual Studio by navigating to View > Other Windows > C# Interactive.
Check out the Roslyn Wiki on the C# Interactive Window.
I found http://kamimucode.com/Home.aspx/C-sharp-REPL/1 . Which seems to be pretty good and I believe also exposes an API to evaluate expressions dynamically
To update on this old question c# REPL is now available as part of Visual studio IDE (starting VS 2015 update 1).
Introducing the Visual Studio 'C# REPL'
From time to time I want to try out some .NET API instead of wondering about C# language syntax. (There are far more subtleties in API than in the language itself.) If you are only looking for REPL for .NET, good old PowerShell is always with you.
C#:
using System;
using System.Text;
Convert.ToBase64String(Encoding.UTF8.GetBytes("Overflow"));
PowerShell:
[Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes("Overflow"))
Related
You can open the C# Interactive window in Visual Studio to use C# as a scripting an shell language. Unfortunately, this requires you to have Visual Studio open all the time.
I know I can run csi.exe itself, but this does not give me any syntax highlighting or auto completion features.
How can I run the C# Interactive Windows standalone?
I would suggest LINQPad (I don't use it myself but I know this can do that kind of things). I think it's pretty powerful
https://www.linqpad.net/
VSCode has built in support for .NET Interactive Notebooks - if you don't see it, you can install the '.NET Interactive Notebooks' extension
Is there a good working plugin for C# in Eclipse? I'm using a Linux machine so I do not have access to Visual Studio Express. I already have an Eclipse Environment working perfectly for my needs so I don't want to deal with multiple IDEs if at all possible. It doesn't need code complete but highlighting and compiling would be nice.
Emonic is an actual eclipse plugin for C#: http://emonic.sourceforge.net/.
Here's a handy guide for how to get it set up: http://www.ibm.com/developerworks/library/os-eclipse-migratenetvs/
Monodevelop is great, but won't meet your requirement not to have to work in multiple IDEs.
I'm not sure about eclipse, but MonoDevelop is cross platform.
http://monodevelop.com/
From:
http://www.mono-project.com/Mono_For_Linux_Developers#Eclipse_in_C.23_Mode
Black-Sun
Emonic
eSharp
I don't personally have any experience with the mentioned plugins. Any C# development I've done on Linux has been through MonoDevelop
From Eclipse marketplace:
aCute: C# edition in Eclipse IDE
aCute enables C# application development in the Eclipse IDE.
aCute provides a rich C# editor with error reporting, hover, content assist, jump to references... (using OmniSharp) and syntax highlighting (using TextMate grammar).
aCute also integrates various operations of the dotnet command-line (New, Run, Test, Publish) as typical Eclipse IDE wizards and workflows.
aCute provide supports debugging for .NET applications.
the core part of the bachelor thesis which I am writing right now is a plugin for a C# IDE that offers a few refactorings (it comes to more than simple refactorings but I want to keep it simple for the moment).
I've always been working with Visual Studio so far. However, I've heard that their AST access is rather uncomfortable.
Alternatives are MonoDevelop and SharpDevelop. Another way to work with Visual Studios AST would be to access it via a custom ReSharper Plugin.
Does anyone of you have experience in writing Plugins for any of those target applications? What do you think? I appreciate every advice and disadvice.
Thanks,
TH
An advantage of using MonoDevelop or SharpDevelop is that they're open-source, so you can be sure to have full access to the AST - you can go into the core and modify things, if necessary. Another advantage is that they're 100% managed code, so much easier to develop and debug. Plus, you're more likely to be able to get hold of core developers and ask them detailed questions.
If you're interested if working with MonoDevelop, I'd recommend you implement your refactoring directly in the existing Refactoring addin. We'd love to have more refactoring features :)
The codebase has been undergoing a bit of churn in master because we switched to a new AST and a parser based on the Mono C# parser, and the refactorings have not yet been ported over. I'd recommend you head over to our mailing list or IRC and ask some more specific questions there, so we can give you some more specific pointers.
I believe VS 2010 has very good native support for plugins using MEF. Here's a guide:
http://msdn.microsoft.com/en-us/library/dd885242.aspx
You can also use Devexpress DXCore, it's free with CodeRush Express.
The best AST access for refactorings is offered by NRefactory 5, a complete rewrite of the previous NRefactory version (which is used in both SharpDevelop and MonoDevelop).
For SharpDevelop we plan to use the new NRefactory in SharpDevelop 5.0; and MonoDevelop will also migrate to it eventually (MonoDevelop is already using the new AST, but not yet the new type system/semantic analysis).
The main goal for this rewrite was to:
Provide a rich AST with position information for every token, making refactorings easier to write
Improve the semantic analysis performance
Eliminate some bad design decisions from the previous version (IExpressionFinder, and how referenced assemblies are handled)
In the future, you might also want to look at Microsoft's Compiler-As-A-Service.
Also be sure to checkout ReSharper from http://www.jetbrains.com/resharper which is a plug-in for VS that adds many refactorings
I want to write a new templating language, and I want Visual Studio to "support" it. What I need to know is:
How do I parse my new language?
Given some code in my new template language, how do I translate it into HTML? Right now I'm using regular expressions to parse it token by token, but I don't think this is going to scale very well as the language gets more complicated, and there's no error checking. I've heard of ANTLR but never used it. Would that be the right tool for this job, or is there perhaps something simpler? Ideally I'd like to send any syntax errors to the error window with as much information as possible (line #, type of error) like other languages do.
How do I create a new file type for Visual Studio?
How do I get syntax highlighting?
Can I use the same parser I created in step 1, or is this something entirely different?
How do I get Intellisense?
I'd prefer to write my parser in C#.
I would take a look at another language that has already done the legwork of integrating with Visual Studio. A great example is Boo. The language and Visual Studio integration are open source. So you can take a look at exactly what they had to do.
Boo Language: https://github.com/boo/boo-lang
Boo Syntax Highlighting for VS2010 (VSX add-in): http://vs2010boo.codeplex.com/
Boo Language Studio (syntax highlighting for VS2008): http://boolangstudio.codeplex.com/
The Boo Syntax Highlighting for VS2010 includes some recommended links on its homepage, which I'll copy for easy reference:
Nice article about "classification" (syntax highligting) in VS 2010: http://dotneteers.net/blogs/divedeeper/archive/2008/11/04/LearnVSXNowPart38.aspx
Examples for VSX add-ins: http://blogs.msdn.com/vsxteam/archive/2009/06/17/new-editor-samples-for-visual-studio-2010-beta-1.aspx
Regarding the Visual Studio aspects, what you need is a "language service", which is the entity that handles colorizing, intellisense, etc. for a given file extension/type.
For an intro, see this article
And for a code sample see here
Regarding parsing, there are lots of technologies, and I won't offer an opinion/advice.
Beware, there is a fair amount of work involved, although in my opinion it is much more straightforward in VS2010 than in previous versions of Visual Studio to provide this kind of extension.
See also
Visual Studio 2010 Extensibility, MPF and language services
I wrote a VS Language Service using this article as my basis:
http://www.codeproject.com/KB/recipes/VSLanguageService.aspx
It wasn't too bad if you have a basic handle on Grammars.
There is a sample in the VS SDK that shows most of the features you are looking for.
I was using VS with own language and desperately needed a syntax highlight. I built mine based on this tutorial: https://mattduffield.wordpress.com/2012/07/31/writing-a-brightscript-syntax-highlight-extension-for-visual-studio-2010/
I know the tutorial is in VS2010. I made mine in VS2012 with no or very small hiccups. (also worked in VS2013) Recently I changed to VS2015 and the solution can be edited, built with no problem.
I found this very useful collection of recent samples for Visual Studio 2013 SDK:
http://blogs.msdn.com/b/vsx/archive/2014/05/30/vs-2013-sdk-samples-released.aspx
It also contains the recent version of the OokLanguage which sounds promising.
We used ANTLR 4 to parse our language which works like a charm and allows direct interaction with C# code. Can totally recommend it.
As mentioned in other answers, the most interesting code sample is the Ook language extension for the latest version of Visual Studio (2017 at the time of writing).
For VS 2015 see the sample in the VS2015 branch.
In order to install the SDK for 2015 or later, you need to rerun the VS setup. In 2015 it's called "Visual Studio Extensibility Tools Update 3".
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
Sometimes it's handy to have access to your language to do quick things without starting Visual Studio and creating a new console app.
Is there something like Python's interactive mode or groovy shell, except for C#?
Update for 2022
After installing Visual Studio 2022, add the following to your PATH environment variable.
C:\Program Files (x86)\Microsoft Visual Studio\Shared\Packages\Microsoft.Net.Compilers.2.6.1\tools
Then open your terminal (CMD, PowerShell, Windows Terminal) and type csi to run C Sharp Interactive.
You'll get something like this:
PS C:\> csi
Microsoft (R) Visual C# Interactive Compiler version 2.6.1.62414
Copyright (C) Microsoft Corporation. All rights reserved.
Type "#help" for more information.
> var list = new List<int>{ 1, 2, 3, 4 };
> list // You don't need to call Console.WriteLine() to see values
List<int>(4) { 1, 2, 3, 4 }
> // You can keep adding lines as needed
Previous Answer
With the Visual Studio 2015 Update 1 there now is a C# Interactive tool window built into Visual Studio.
The new tool window is invoked by going to View → Other Windows → C# Interactive.
For Visual Studio 2010 to 2013 you can use the Roslyn CTP to get a similar tool window in Visual Studio.
Have a look at CsharpRepl (part of the Mono project). Never used it myself, I hasten to add.
For LINQ stuff, you should also look at LINQPad.
There are several.
CsharpRepl
CSI: A Simple C# Interpreter
SnippetCompiler
LINQPad
Like others noted, Mono's CSharpRepl is probably the right answer. However, if you're not fixed to C#, then PowerShell is a pretty nice environment of playing around with .NET. I frequently use it to test regular expressions, format strings, etc. All the kinds of stuff you have ConsoleProject163 lying around for :)
In addition to the other good answers here (+1), there is also CSI and the immediate window in Visual Studio.
Here is a Mono CsharpRepl which is what you are looking for.
This documents the features available
in the C# interactive shell that is
part of Mono's C# compiler. An
interactive shell is usually referred
to as a read eval print loop or repl.
The C# interactive shell is built on
top of the Mono.CSharp
(http:/monodoc/N:Mono.CSharp) library,
a library that provides a C# compiler
service that can be used to evaluate
expressions and statements on-the-fly.
There is ScriptCS which uses the Roslyn CTP nuget package.
I think CShell would be a nice contribution to answers given here.
It provides code completion enabled REPL command window as well as a lightweight workspace management tools to include some scratch files and library references.
With Roslyn CTP there now is a full C# interactive window from Microsoft direct in Visual Studio!!
Works great! So far runs all my libraries.
After install: Invoking View -> Other Windows -> C# Interactive from the menu.
I use ideone.com sometimes, but LINQPad is a good choice if an install is acceptable.
You can use this developed by Miguel De Icaza, is shipped with mono and have code completion
If you are looking for a simple web based environment to crank out some C# code try coderpad.io Not sure if you can add libraries n' all but its a quick and simple solution if you are just interested in testing out several commands