Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Roslyn and .NET Runtime version [duplicate]

Tags:

Is it possible to use Roslyn compiler and new features of C# 6.0 with old versions of .NET Runtime (for example, .NET 4.0)?

For example, I want use the expression-bodied members (int S => x + y; instead of int S { get { return x + y; } }) in .NET 4.0 application.

like image 360
AndreyAkinshin Avatar asked Jun 26 '14 16:06

AndreyAkinshin


People also ask

Is Roslyn a part of .NET core?

Roslyn, the . NET Compiler Platform, empowers the C# compiler on . NET Core and allows developers to leverage the rich code analysis APIs to perform code generation, analysis and compilation.

What is dotnet Roslyn?

The . NET Compiler Platform ("Roslyn") provides open-source C# and Visual Basic compilers with rich code analysis APIs. You can build code analysis tools with the same APIs that Microsoft is using to implement Visual Studio!

What is Roslyn used for?

Roslyn is an open source platform, developed by Microsoft, containing compilers and tools for parsing and analysis of code written in C# and Visual Basic. Roslyn is used in the Microsoft Visual Studio 2015 environment.

Why is Roslyn a compiler?

Roslyn was designed with that intent from the beginning. This reduces the barrier in developing tools specifically designed for source code analysis. APIs of Roslyn are of three types: feature APIs, work-space APIs and compiler APIs. Feature APIs allow source code tool developers to do code refactoring and fixes.


2 Answers

The new C# 6.0 features don't depend upon framework support so yes, you an app compiled with the C# 6.0 compiler will run on .NET 4.0, assuming of course you specify you are targeting .NET 4.0 in your project file in the first place.

like image 150
Jason Malinowski Avatar answered Oct 23 '22 03:10

Jason Malinowski


As of now Roslyn C# compiler and tooling cannot run on .NET 4.0

You can certainly cross-compile for .NET 4.0, but to run the compiler itself you need at least .NET 4.5

like image 26
Oleg Mihailik Avatar answered Oct 23 '22 04:10

Oleg Mihailik