c# - 让 MSBuild 在 VS15 预览版中使用新的 Roslyn 编译器

标签 c# .net visual-studio roslyn roslyn-code-analysis

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

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)

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

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

最佳答案

一种解决方法是设置 CscToolPath msbuild 变量添加到新的 roslyn 构建的 bin 目录中。

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

msbuild /p:CscToolPath=<PathToYourRoslynBinDir>`

如果您经常这样做,您也可以在 .csproj 中执行此操作:

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

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

关于c# - 让 MSBuild 在 VS15 预览版中使用新的 Roslyn 编译器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40221813/

相关文章:

c# - 即使我将变量设为静态方法或创建相关类的新实例,我也无法访问另一个类中的变量?

c# - 每次我添加新的 cs 文件时,Visual Studio 都会在重复的解决方案中继承旧的命名空间

django - 无法发布到 azure

asp.net - 使用 .NET Core ASP.NET Web 应用程序将 Excel 文件导入到 SQL Server 数据库

visual-studio - 如何为 Entity Framework 复杂类型添加导航属性

c# - 使用 WCF Rest 服务下载文件?

c# - 配置文件 'appsettings.json'未找到且不可选

c# - 简单使用 RSACryptoServiceProvider KeyPassword 失败

c# - 无法在 .NET 中打开串口

.net - Powershell:管道输入到通过调用运算符执行的命令