c# - 使用 TFS 2017 BuildAgent 构建解决方案时出现错误 CS0234

标签 c# .net visual-studio tfs msbuild

在尝试使用 TFS 构建定义进行构建时,我遇到了以下问题。

执行构建时,代理会记录以下错误:

Error CS0234: The type or namespace name 'VisualStudio' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)

Error CS0246: The type or namespace name 'TestInitializeAttribute' could not be found (are you missing a using directive or an assembly reference?)

Error CS0246: The type or namespace name 'TestCleanupAttribute' could not be found (are you missing a using directive or an assembly reference?)

Error CS0246: The type or namespace name 'TestCleanup' could not be found (are you missing a using directive or an assembly reference?)

Error CS0246: The type or namespace name 'TestMethodAttribute' could not be found (are you missing a using directive or an assembly reference?)

所以我这样理解消息,即 buildAgent 无法找到以下 .dll

Microsoft.VisualStudio.TestTools.UnitTesting;

我在运行 TFS 和 Buildagents 的服务器上安装了 Visual Studio 2017 RC 和 Visual Studio 2017 Build Tools。

我还在那个机器上安装了 .net 4.6.1。

这个 accepted answer对我来说不是解决方案。

必须有某种解决方案,不包括将该 dll 复制到 git 主干并从那里引用它。

更新

我能够在该机器上使用 Visual Studio 2017 RC 在本地构建解决方案。 但是构建代理仍然会抛出相同的错误。

最佳答案

我终于想出了解决这个问题的方法。

我添加了以下 nuget 包作为我项目的引用:

https://www.nuget.org/packages/MSTest.TestFramework/

那就是mstestv2框架。

之后我不得不删除对 mstestv1 框架的旧引用。

构建错误现在消失了。

更新:

如果你想让你的测试被发现,请添加 MSTest TestAdapter到您的项目。

感谢Maciej获取该信息。

关于c# - 使用 TFS 2017 BuildAgent 构建解决方案时出现错误 CS0234,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42511594/

相关文章:

c# - 在大型 c# 项目中进行 TDD 时如何处理缓慢的单元测试

c# - 从具有最小值的键值对列表中获取键值对

c# - 无法上传大视频文件

c# - 透明形式上的半透明图像

.net - 像面板一样的 Visual Studio

c# - 有什么充分的理由不依赖业务逻辑中的数据库 key 完整性吗?

c++ - 是什么导致 Visual Studio 2017 中的空文件名

c# - 在 Visual Studio 2017 中运行和调试 Powershell 模块

c# - Xamarin iOS 11.2 中的 Environment.TickCount 替代方案

c# - 使用 Visual Studio 创建链接安装