在尝试使用 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/