How To Disable External Console In Visual Studio For Mac

Yesterday, at Build, Microsoft released the first public preview of Visual Studio “15” – the next iteration of Visual Studio.

The Visual Studio Emulator for Android and the Windows Phone emulator run on Hyper-V and make a bunch of changes to your networking configuration that you may not want, especially if you’re using Hyper-V for running other virtual machines. The Visual Studio Emulator for Android and the Windows Phone emulator run on Hyper-V and make a bunch of changes to your networking configuration that you may not want, especially if you’re using Hyper-V for running other virtual machines.

One of the main reasons why you’d want to try it out already is to be able to use some of the heralded C# 7 features – such as binary literals, local functions or pattern matching (to name just a few).

It’s been possible to test out these features in a slightly hacky way before (see Josh’s post) – by building Roslyn from source and deploying it into VS using the CompilerExtension VSIX, but of course it’s much easier and convenient to just use C# 7 features directly in VS “15” now.

In this post I’m gonna show you how to enable the experimental C# 7 features – because they are by default not available.

TL;DR

Add the following conditional compilation symbols to your project: __DEMO__ and __DEMO_EXPERIMENTAL__.

Enabling C# 7 features

So let’s say you want to use local functions in your C# code. You looked at the feature discussion and you wrote this bit of code:

2
4
Error CS8058
Feature'local functions'isexperimental andunsupported;use'/features:localFunctions'toenable.

This is a compiler options and you can pass it into csc.exe command line compiler. Of course you’d likely never want to invoke it manually, but would want to use msbuild to build the entire project/solution for you, so you can pass it to the compiler through msbuild too:

2
4
6
8
vars=foo isstringx?x:'not a string';
// prints 'foo'
// 'not a string'

Package Manager Console In Visual Studio

There is also a version of pattern matching that uses a match keyword. That is actually covered by a separate conditional compilation symbol – __DEMO_EXPERIMENTAL__ (symbols are comma separated).

Once you add that to your project you could try out some of the experimental pattern matching code with match, for example the snippet below:

2
ConsoleApplication1.Cat-meow

You can read more about pattern matching in C# 7 here.