如何摆脱"API限制UnitTestFramework.dll已加载"错误?

Kev*_*ger 13 .net c# tfs tfsbuild visual-studio

偶尔会弹出以下错误:

C:\Program Files\MSBuild\Microsoft\VisualStudio\v9.0\TeamTest\Microsoft.TeamTest.targets(14,5): error : API restriction: The assembly 'file:///C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll' has already loaded from a different location. It cannot be loaded from a new location within the same appdomain.

我怎么摆脱它?

Kev*_*ger 8

  • 编辑.csproj文件
  • 删除UnitTestFramework引用末尾的processorArchitecture = MSIL.

更改:

<reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
Run Code Online (Sandbox Code Playgroud)

至:

<reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
Run Code Online (Sandbox Code Playgroud)
  • 重新启动Visual Studio

  • 凯文:你能解释一下这背后的想法吗?我遇到了同样的问题,但是看到了正在发生的事情的相互矛盾的解释. (2认同)

dea*_*dog 5

如果在尝试在TFS构建服务器上运行测试时遇到此错误,则可能只需更改TFS构建定义用于定位测试程序集的模式. 这篇文章描述了问题和解决方案.基本上TFS在两个不同的文件夹中找到相同的测试程序集,并尝试将其包含两次.解决这个问题:

  1. 打开团队浏览器
  2. 展开树,直到看到项目的构建
  3. 选择有问题的构建
  4. 右键单击>编辑构建定义
  5. 单击左侧边栏上的" 处理 "
  6. 展开'2.基本'>自动测试
  7. 单击编辑
  8. 更改测试程序集文件规范以删除匹配模式中的文件夹.例如,将****\test .dll**更改为*test*.dll

通过从匹配模式中删除文件夹(即\),它只包含一次测试程序集,即使它在两个不同的文件夹中找到它.