Make MSBuild use new Roslyn compiler in VS15 Preview

梦想与她 提交于 2019-12-24 08:25:00

问题


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?


回答1:


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.




回答2:


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:


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.



来源:https://stackoverflow.com/questions/40221813/make-msbuild-use-new-roslyn-compiler-in-vs15-preview

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