Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is Roslyn related to MsBuild?

Tags:

I'm wondering: How exactly is Roslyn related to MsBuild?

My understanding was that

  1. Roslyn is a compilation engine
  2. MsBuild is is mostly a set of specifications of how a project is set up - i.e. basically a definition schema for .csproj, .sln files and so on.

Then again, MsBuild also ships with an msbuild.exe - which, correct me if I'm wrong, is able to actually compile projects. But how would this tie in with Roslyn, assuming msbuild.exe can compile projects, but so can Roslyn?

Does msbuild.exe use Roslyn to compile, in case of MSBuild 15? Are they completely seperate? Am I misunderstanding anything?

And furthermore & more specifally: Assuming I want programatically create simple .csproj files, and use Roslyn's MSBuildWorkspace to handle/populate and finally compile these. Would the end user of my application need to have Microsoft's build tools installed on their machine? Or is this not necessary, as Roslyn would be able to read & compile these independently of any local MSBuild installation?

like image 944
Bogey Avatar asked Jul 18 '17 13:07

Bogey


People also ask

What is Roslyn compiler used for?

NET Compiler Platform, better known as Roslyn. Roslyn is a collection of open-source compilers, code analysis and refactoring tools which work with C# and Visual Basic source codes. This set of compilers and tools can be used to create full-fledged compilers, including, first and foremost, source code analysis tools.

What compiler does MSBuild use?

MSBuild uses csc.exe as its actual compiler but knows where to find assemblies, references etc based on your solution and project files (these files are actually xml files).

Is Visual Studio using MSBuild?

Visual Studio uses MSBuild, but MSBuild doesn't depend on Visual Studio. By invoking msbuild.exe on your project or solution file, you can orchestrate and build products in environments where Visual Studio isn't installed. Visual Studio uses MSBuild to load and build managed projects.

What is Roslyn Visual Studio?

. NET Compiler Platform (Roslyn) Analyzers inspect your C# or Visual Basic code for style, quality, maintainability, design, and other issues. This inspection or analysis happens during design time in all open files. Analyzers are divided into the following groups: Code style analyzers are built into Visual Studio.


1 Answers

MSbuild is the build system for Visual Studio. It calls the C# compiler to compile C# projects. Roslyn is the C# compiler (and the VB compiler). So msbuild uses Roslyn.

However, Roslyn also includes more things than just the compiler. It also includes a VS plug in that gives you IDE features (completion lists, colorization, code fixes, etc).

In addition, Roslyn is also an API for analyzing source code, that you can use from your own app. For this last scenario is has an API known as MSBuildWorkspace that you can use to open a project or solution for analysis. This workspace uses MSBuild to figure out all the pieces of the projects and solution. So this part of Roslyn uses MSBuild.

like image 198
Matt Warren Avatar answered Sep 18 '22 19:09

Matt Warren