我正在尝试使用 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.Build
和Microsoft.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
中的程序集并手动添加引用文献。成功!
关于c# - 构建环境 CodeAnalysis 任务无法实例化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28161239/