c# - 构建环境 CodeAnalysis 任务无法实例化

标签 c# .net visual-studio visual-studio-2013 msbuild

我正在尝试使用 Microsoft.Build.Evaluation.Project 在我的项目中运行 MSBuild。

我收到此错误,但我不知道为什么,或者从哪里开始诊断它:

C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\CodeAnalysis\Microsoft.CodeAnalysis.targets: error MSB4127: The "CodeAnalysis" task could not be isntantiated from the assembly "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v12.0\CodeAnalysis\.\FxCopTask.dll". Please verify the task assembly has been built using the same version of the Microsoft.Build.Framework assembly as the one installed on your computer and that your host application is not missing a binding redirect for Microsoft.Build.Framework. Unable to cast object of type 'Microsoft.Build.Tasks.CodeAnalysis' to type 'Microsoft.Build.Framework.ITask'.

  • 我尝试在构建文件中使用 ToolsVersion="12.0"
  • 我已检查 Microsoft.CodeAnalysis.targets 并确保 FxCopTask.dll 正常工作
  • 我已删除无关的引用,现在仅引用 Microsoft.BuildMicrosoft.Build.Framework
  • 我已在同一解决方案的 shell 进程中成功使用了 MSBuild.exe
  • This question似乎解决了问题,但它使用的是命令行。

我不确定如何“验证任务程序集”或添加“Microsoft.Build.Framework 的绑定(bind)重定向”。有人能指出我正确的方向吗?

最佳答案

这里的答案在于模糊的引用文献。默认的 Microsoft.Build 引用是 v4.0

结果引用了最新版本(至少在 VS 2013 Community 中),我必须浏览到 C:\Program Files (x86)\MSBuild\12.0\bin 中的程序集并手动添加引用文献。成功!

感谢BuildManager to use another version of MSBuild指出这个解决方案。

关于c# - 构建环境 CodeAnalysis 任务无法实例化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28161239/

相关文章:

visual-studio - WinForm 部分类

windows - 尝试提交 Git 文件但得到::fatal: LF 将被 <some file in repo> 中的 CRLF 替换

c# - 将 IL 包装到 C#/.NET Core 中写在磁盘上的程序集中?

c# - 如何在 C# 中读取用户的十进制数?

c# - 来自 .net core 的 Azure ServiceBus 消息无法在 .net 4.6.1 中解析

.net - 以编程方式在 .NET 中的 windows7 中显示屏幕键盘

c++ - Visual C++ 中的全局变量

c# - 尝试在 C# 中将枚举 system.array 转换为枚举 List<T>

c# - 大型原始数组的 protobuf-net 序列化性能

c# - 为什么不能在嵌套的局部作用域中声明重复的变量名?