Make MSBuild use new Roslyn compiler in VS15 Previ

2019-07-30 00:37发布

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 features/tuples branch and replace the needed DLLs in VS15Preview\MSBuild\15.0\Bin 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=2.0.0.0, 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?

3条回答
对你真心纯属浪费
2楼-- · 2019-07-30 00:47

M0sa's answer might work, however, that will only give you MSBuild enabled builds. If you also want to test it in VS, then you can follow Roslyn's own documentation. That page tell you how to replace the "intellisense" in Visual Studio (the VisualStudioSetup bullet), and the Ctrl-Shift-B "Build Solution" to actually run your solution (the CompilerExtension).

查看更多
冷血范
3楼-- · 2019-07-30 00:57

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:

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

Obviously, this only affects the build, not Visual Studio or it's intellisense. To hook that up, you need to follow the Trying Your Changes in Visual Studio guide in the Roslyn repo. You have to build one of the VSIX projects in the Roslyn solution. Running one of those projects launches an experimental instance of Visual Studio where you can play around with your changes.

查看更多
【Aperson】
4楼-- · 2019-07-30 01:10

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

查看更多
登录 后发表回答