Are async/await keywords only usable with VS 2012+? - c#

Are async/await keywords only usable with VS 2012+ and not usable with the C# compiler, which I could use from command line?
I've read some questions at SO, like:
Will VS 2010 allow me to use the new async and await keywords in C#?
But, I don't really understand how such keywords which must be connected only with such stuff as the compiler/interpreter are connected with the IDE. How it could be?
So if I want to use these features without VS 2012 the single solution is CTP for 2010?
It doesn't sound like a clear logic. Keywords which are linked with the language semantics must be independet from the such stuff as IDE. Interoperability is a main feature for such products, isn't it?

Are async/await keywords only usable with VS 2012+ and not usable with the C# compiler, which I could use from command line?
No, it's fine to build with csc.exe from the command line, so long as it's the C# 5 compiler (as shipped with .NET 4.5).
If you want to develop in Visual Studio though, you'll need to get VS2012 or later. (I really wouldn't use the CTP at this point - there were various bugs fixed in the real release, and there's no need to go through the pain of them now.)
Don't forget there's always the Express range of Visual Studio editions, which are free.

Related

Autocomplete blocks in C#

Iam used to Eclipse and Java development, but because of my job I need to start coding in C#. I find it a bit annoying that visual studio doesn't autocomplete my blocks. For instance when I write a new function, class or statement am used to that the IDE autocompletes my blocks. So when I type:
private function sendData(String msg, String email) {
and hit enter the closing bracket appears automatically, is there any settings that enables this function in Microsoft visual C# 2010 express ?
This isn't possible with Express versions, since you can't install extensions. You'll need to use Professional or higher and use third party extensions. Some simple free ones will do this (such as Productivity Power Tools), as does the commercial product ReSharper, which does much more more. The later likely would make Visual Studio have other features that you're probably used to comming form Eclipse, such as more refactoring support.
I'm almost certain that the Productivity Power Tools extension will give you this feature. You can find it here:
http://visualstudiogallery.msdn.microsoft.com/d0d33361-18e2-46c0-8ff2-4adea1e34fef
It's really a great add-on and it will give you a lot more control over options like this.
There is no functionality like this already built-in in Visual Studio, but you can install a plugin like Brace Completer to add the functionality .
No, you can't do it by default in Visual Studio. Visit Microsoft Connect to submit a feature request.

How to create a new language for use in Visual Studio

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".

Why are some Microsoft languages called "visual"? (Visual C#, Visual Basic .NET, Visual C++)

I understand visual programming languages to be those languages that allow the programmer to to manipulate graphical--rather than textual--objects onscreen to build functionality.
The closest thing I see in C#, VB, etc. is RAD controls, but that is just composing UI and the very simplest functionality -- it has nothing to do with the language itself, even.
Why, then is C# called "Visual C#", Basic .NET called "Visual Basic .NET," etc.?
What is "visual," or what is the rationale or history behind the nomenclature?
I don't think it has to do with the languages themselves being "visual."
From the Wikipedia article:
The term Visual denotes a brand-name relationship with other Microsoft programming languages such as Visual Basic, Visual FoxPro, Visual J# and Visual C++. All of these products are packaged with a graphical IDE and support rapid application development of Windows-based applications.
The languages are not called "Visual". The products are "Visual".
This is from way back before .NET. "Visual" Basic was "Visual" because of the forms development GUI. "Visual" C++ was "Visual" because of MFC and the wizards for creating an MFC application.
I suspect it all dates back to the original Visual Basic. The "visual" part of this was the UI designer...
The Ruby interface generator provided the "visual" part of Visual Basic
The use of the work "Visual" started to get popular with the introduction of Visual C++ version 1.0; it was the first version that ran natively inside Windows, whereas other versions ran in DOS mode even though they were able to produce Windows-runnable code. It has nothing to do with the languages, rather with the environment where the IDE runs.
I guess this is mainly a marketing choice.
It could, however be related to the fact that "Visual Studio" is a GUI, thus a way to "visualize" your code.
I guess it's all going from some event or some product name choice. And now, it just about the brand.
I mean, like, nowadays you can't even think about some IDE called Studio and the same can be said about, for example, Visual Eclipse.

How can I get Visual Studio to error check my code (show the squiggles) without explicitly compiling?

I use Visual Studio (C# Express 2008) occasionally to work with some vendor supplied C# code. I am looking to make my experience with VS more like my experience with Eclipse. I have become accustomed to the way Eclipse handles underlining errors (in java source). When I make an error in my code in Eclipse, it will be underlined right away, and if I fix it, the underline will disappear almost immediately, or at worst, when I save the file. In Visual Studio however, the underline remains until I next build the project.
Is there a setting somewhere I can change so that VS will build every time I save, or even as I am typing? Is this hard to do with C# because it is more complex in some way than Java? Do I need to find someone to buy me the full (non express) version? Also, what is the squiggly underline feature called? I fear this question may have been asked before but I don't know the magic word to search for.
Jason's answer is fine, but a couple additional points:
is this hard to do with C# because it is more complex in some way than Java?
Yes, but that's not relevant. Yes, it is a hard problem to do on-the-fly analysis of any language in the 100 milliseconds between keystrokes. Doing it for C# is probably harder than Java, being that it supports so many more language features than Java.
But our IDE team is a bunch of buff coders who are awesome, so they can handle doing it for C#.
The real issue was that the compiler architecture of C# was not originally designed to do this sort of analysis in realtime; the VB compiler was. And therefore it took rather longer to fix up the semantic analysis engine of the C# compiler to make this feature feasible.
We're continuing to do research into how to rearchitect the compiler to expose more and more of these on-the-fly analysis services in a rich, extensible and compelling way, but this will take some time. It's a big compiler.
what is the squiggly underline feature called?
On the compiler team we call it "the squiggly red underline feature", or "squiggles" for short.
I don't know if marketing has a name for it or not. If they do, it's probably something like "Microsoft SquiggleSense .NET For The Microsoft Visual Studio Suite System 2008"; they seem to like these long names that have "Microsoft" in them twice.
Do you have Visual C# 2008 Express Edition with SP1? SP1 added exactly this feature to Visual Studio 2008 Professional and Visual C# 2008 Express Edition.
From the release notes:
This service pack adds a new Visual C# IDE feature that provides a richer set of error information about your code. Specifically, this feature presents the expression-level errors that occur in open files to you according to your code. These expression-level errors were previously reported only after a build operation.
From Scott Guthrie's release notes:
The C# code editor now identifies and displays red squiggle errors for many semantic code issues that previously required an explicit compilation to identify. For example, if you try to declare and use an unknown type in the C# code-editor today you won't see a compile error until you do a build. Now with SP1 you'll see live red squiggle errors immediately (no explicit compile required):
To turn this option on in VS 2010 use Tools > Options > Text Editor > C# > Advanced > Show live semantic errors
and
VS 2010 use Tools > Options > Text Editor > C# > Advanced >Enter outlining mode when files open
To turn this option on in VS 2010 use Tools > Options > Text Editor > C# > Advanced > Show live semantic errors

Anders Hejlsberg's C# 4.0 REPL

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"))

Categories