让 MSBuild 在 VS15 Preview 中使用新的 Roslyn 编译器 [英] Make MSBuild use new Roslyn compiler in VS15 Preview

查看:53
本文介绍了让 MSBuild 在 VS15 Preview 中使用新的 Roslyn 编译器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近刚刚研究了 Roslyn 编译器的东西,我想知道一些可能性.我正在尝试使用 features/tuples 分支从 Roslyn 存储库构建 Roslyn 编译器,并替换 VS15Preview\MSBuild\15.0\Bin 文件夹中所需的 DLL.但是当我替换 DLL 并构建控制台应用程序项目时,我收到以下错误消息

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

错误指定的任务可执行文件csc.exe"无法运行.无法加载文件或程序集Microsoft.CodeAnalysis.CSharp,Version=2.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35"或其依赖项之一.定位的程序集的清单定义与程序集引用不匹配.(来自 HRESULT 的异常:0x80131040)

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)

我尝试替换的文件:Microsoft.CodeAnalysis.dllMicrosoft.CodeAnalysis.Csharp.dllcsc.exe.

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

是否可以为 C# 构建自定义 Roslyn 编译器并在 VS15 预览版中替换它?

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

推荐答案

解决方案的一种方法是设置 CscToolPath msbuild 变量到您的新 roslyn 构建的 bin 目录.

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

我发现 msbuild 命令行(例如开始 > 开发人员命令提示符)最方便.您可以在运行时 cd 进入任何解决方案目录:

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>`

如果你经常这样做,你也可以在 .csproj 中这样做:

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

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

显然,这只会影响构建,而不影响 Visual Studio 或它的智能感知.要连接它,您需要遵循 在 Visual Studio 中尝试更改 指南.您必须在 Roslyn 解决方案中构建 VSIX 项目之一.运行其中一个项目会启动一个 Visual Studio 实验实例,您可以在其中进行更改.

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.

这篇关于让 MSBuild 在 VS15 Preview 中使用新的 Roslyn 编译器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆