How to use roslyn c# compiler with visual studio 2015?

泄露秘密 提交于 2019-11-27 17:43:33

So it looks like you've got a few questions:

What is Roslyn?

Roslyn is the new default compiler inside of Visual Studio 2015. If you're building and running applications within Visual Studio 2015, they're being compiled with the Roslyn compiler. You'll get to take advantage of all the new C# 6 features that are available only within the new compiler.

If you're using VS2015, Roslyn has replaced the old compiler entirely and as far as I know you can't use the old compiler within VS 2015.

Roslyn is also a platform that allows you to build programs that can modify, interpret and understand other programs. It's not really meant to let you write code that modifies itself (although that's probably possible to a degree).

The common use cases for Roslyn are:

  1. Building Code Analyzers that provide errors and warnings within Visual Studio.
  2. Building extensions for Visual Studio that understand source code.
  3. Building other tools that understand or run source code. Example: ScriptCS - Scripting with C# code.

In order to use Roslyn for these purposes, you pull down the Microsoft.CodeAnalysis packages from NuGet. You can use these packages to parse code, analyze syntax trees, analyze symbols or compile code and emit IL.

If you're interested in learning more about Roslyn, I've started a series called Learn Roslyn Now that you might be interested in.

Can I replace the compiler?

Yes you can, but I'm not convinced this is a great idea outside of testing changes you want to contribute back to Roslyn. You can pull down Roslyn from GitHub and follow these instructions to build and run Roslyn from within Visual Studio.

If you follow those instructions, you'll be able to run the Roslyn project with F5. It will start a new instance of Visual Studio that's using your customized compiler. This is how people outside of Microsoft will contribute features to the compiler from now on. (Previously you couldn't deploy your custom compiler to Visual Studio but they fixed that in Visual Studio Update 1).

Roslyn is two things:

  1. An API that lets you see "compiler things" like syntax trees and symbols.
  2. A new csc.exe that is implemented atop #1.

If you want to make changes to the compiler and use that to build, take a look at these instructions if you haven't already. There's a few different ways you can make your own version of csc.exe and then use that to build something. But there's no "choice" dialog like you're looking for.

Roslyn is the default compiler of Visual Studio 2015. So, if you install VS2015 you´re already using Roslyn.

Roslyn is a codename for .NET Compiler Platform, and it provides open-source C# and Visual Basic compilers. The project is available on github.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!