Semuserable Semuserable - 1 year ago 150
C# Question

Build Roslyn compiler and replace it in VS15 Preview

I just recently delved into Roslyn compiler stuff and I'm wondering about some possibilities. I'm trying to build Roslyn compiler from Roslyn repository using

branch and replace the needed dlls in
folder. But when I replace dlls and build console app project I receive the following error message

Severity Code Description Project File Line Suppression State
Error The specified task executable "csc.exe" could not be run. Could not load file or assembly 'Microsoft.CodeAnalysis.CSharp, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Files which I try to replace:
Microsoft.CodeAnalysis.dll, Microsoft.CodeAnalysis.Csharp.dll and csc.exe

Is it possible to build your custom Roslyn compiler for C# and replace it within VS15 Preview?

Answer Source

One way of going about it is to set the CscToolPath msbuild variable to your new roslyn build's bin directory.

I find the msbuild commandline (e.g. Start > Developer Command Prompt) the most convenient for this. You can just cd into any solution directory on run:

msbuild /p:CscToolPath=<PathToYourRoslynBinDir>`

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