How To Compile & Test C# 7 Features

Most of us are aware about the new changes being made in C# compiler. As we know now Roslyn is the default compiler for Visual Studio 2015 & Visual Studio ‘15’ preview (product name may be announced as Visual Studio 2016 or Visual Studio 2017).

Visual Studio 2015 supports all the language features of C# 6. But if you want to test the new features of C# 7 then you can go with “Visual Studio ‘15’ preview” or download and build Roslyn source code and run it with Visual Studio 2015.

So we have 2 options to compile & test C# 7 features:

  1. Visual Studio ‘15’ preview or
  2. Download latest source code of Roslyn form GitHub

If you want to go through the C# 7 features and how to use it with Visual Studio ‘15’ preview you can go through the article

Visual Studio 15 Preview First Look & C# 7

In the above article I have explained about some new features of C# 7 with Visual Studio 2016.

But I noticed that many developers are not able to use Visual Studio 2016 due to internet connectivity and hardware requirements. Its set up size is very big and it requires up to 36 GB of free hard disk space to install.

So we have another alternative to experiment C# 7 with Visual Studio 2015 and learn what is new in it for that you will require to download & build Roslyn Source Code.

Using Latest Roslyn Code with Visual Studio 2015

  1. To Use Roslyn for C# 7 features you must have Visual Studio 2015 with Update 1 or Update 2. If you do not have updated your visual Studio 2015 with update 1 or update 2 then please update your Visual studio 2015. I am using Visual Studio 2015 with update 2 for this article.

  2. After updating Visual Studio 2015 please make sure that “Visual Studio 2015 Extensibility Tools” has been installed.

  3. If “Visual Studio 2015 Extensibility Tools” is not installed on your computer then you can add it with Visual Studio 2015. To Add it with Visual Studio 2015 follow the steps below:

    a. Control Panel >> Programs and Features >> Select Visual Studio 2015 (Edition and update may vary depending on your installation).

    b. >> Click on Change >> Modify >> Select “Visual Studio 2015 Extensibility Tools Update 2” >>Click on update to install it if not installed already.

    visual studio

  4. Download any experimental branch of Roslyn from here.

  5. I have downloaded the branch “future”.

  6. Run “Developer Command Prompt for VS2015” >> go to the directory where you have downloaded the branch of Roslyn from GitHub. >> Run “Restore.cmd” to restore Nuget packages. >> execute the command “msbuild /v:m /m Roslyn.sln” >> open Roslyn.sln file in Visual Studio 2015 with administrative rights.

  7. Select the project “VisualStudioSetup” and set it as start-up project and press F5 to run it. It will open a new instance of Visual Studio 2015.

  8. You will require to make some changes inside Visual studio to use C# 7 features.
    Select your project name and right click >> Properties Window >> Build and then add the below two options in "Conditional Compilation symbols" text box __DEMO__,__DEMO_EXPERIMENTAL__

    build

Now build the program and you will be able to compile and build C# 7 new code syntax.

If you are thinking of what features & code syntaxes you can explore with C# 7 then you can go through the article Visual Studio 15 Preview First Look & C# 7 in this article I have explained about,

  • Local Functions or Nested Functions
  • Using Binary Literal
  • Digit Separators
  • Pattern matching

You can also explore other features of C# 7, but I would like mention here one of the very important points that the implemented features of C# 7 is experimental and it may be modified or removed in newer version until it is stabilized and officially announced by C# compiler (Roslyn) team.

Read more articles on C# 7:


Recommended Free Ebook
Similar Articles