gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 18:58:23 24 4
gpt4 key购买 nike

我最近刚刚研究了 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com