Make MSBuild use the new Roslyn compiler in VS15 Preview

I just recently went deep into the Roslyn compiler, and I'm curious about some of the features. I am trying to create a Roslyn compiler from the Roslyn repository using the features/tuples and replace the required DLLs in the VS15Preview\MSBuild\15.0\Bin folder. But when I replace the DLL and create a console application project, I get the following error message

Severity code Description Project file line suppression status

Error The specified executable file for the task "csc.exe" could not be started. Could not load file or assembly "Microsoft.CodeAnalysis.CSharp, Version = 2.0.0.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35" or one of its dependencies. The located assembly manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

The files I'm trying to replace are: Microsoft.CodeAnalysis.dll , Microsoft.CodeAnalysis.Csharp.dll and csc.exe .

Is it possible to create my own Roslyn compiler for C # and replace it in VS15 Preview?

+1
source share
3 answers

One way to do this is to set the msbuild CscToolPath variable to the new bin bin directory for the assembly.

I found the msbuild command line (e.g. Start> Developer Command Prompt), the most convenient for this. You can simply cd to any solution directory at startup:

 msbuild /p:CscToolPath=<PathToYourRoslynBinDir>` 

You can also do this inside .csproj if you do this more often:

 <PropertyGroup> <CscToolPath>C:\your\roslyn\bin</CscToolPath> </PropertyGroup> 

Obviously, this only affects the assembly, not Visual Studio or Intellisense. To intercept this, you should follow the guide β€œTrying your changes in Visual Studio” in the Roslyn repo. You must build one of the VSIX projects in the Roslyn solution. Launching one of these projects launches an experimental instance of Visual Studio, where you can play with your changes.

+4
source

M0sa's answer may work, but it will only give you built-in MSBuild builds. If you also want to test it in VS, you can follow Roslyn's own documentation . This page explains how to replace the "intellisense" in Visual Studio (bullet) VisualStudioSetup ) and Ctrl-Shift-B "Build Solution" to actually launch your solution ( CompilerExtension ).

+2
source

If you just want to try your Roslyn build, you can do this by opening Roslyn.sln in VS15 and then running the Roslyn project (with or without debugging). It will launch a new instance of VS15 that uses your Roslyn build.

0
source

Source: https://habr.com/ru/post/1269956/


All Articles