gpt4 book ai didi

asp.net - VS2017 无法加载文件或程序集 Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll 或其依赖项之一

转载 作者:行者123 更新时间:2023-12-03 11:46:59 25 4
gpt4 key购买 nike

尝试在 VS2017 中打开较旧的解决方案时有一个旧的单元测试项目在构建时给我带来了问题。

在构建此测试项目时,我不断收到以下错误:

Could not load file or assembly 'file:///C:\Projects\MyProj\Test\DAL\UnitTestProj\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll' or one of its dependencies. The system cannot find the file specified.



我检查了项目的引用,它似乎引用了 Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll .此外,没有代码错误。我怎么知道它是否是它找不到的依赖项之一?

最佳答案

在最初使用 VS2010 开发的项目中,我遇到了类似的问题(带有附加消息 The "BuildShadowTask" task failed unexpectedly),并且不得不花费最后几个小时来了解构建过程的另一个遗留方面。
您很有可能正在处理 private accessor files ( .accessor ),它们是 deprecated in VS2012 (original source)。这在 announcement from the VS2010 team 中有所预示他们不再致力于这些功能。
您也有可能只是在处理对错误版本的 UnitTestFramework 的错误引用,但 NuGet 还原应该可以解决此问题。如果没有,请参阅 this GitHub thread寻求可能的修复(手动更改公共(public)文件夹的引用),或移动到新的 MSTest.TestAdapter 和 MSTest.TestFramework 包(见 MSDN support thread)。
解决方案
A. 编辑单元测试.csproj并更改项目 Include来自 Shadow 的引用资料=> None :<Shadow Include="Test References\namespace.accessor" /><None Include="Test References\namespace.accessor" />B. 更好的是,只需删除所有 .accessor来自单元测试项目的 Test References 的文件文件夹。
理想情况下,您还可以重写单元测试以删除对私有(private)方法的引用,方法是重新架构以分离关注点或将属性更改为 internal。并在 InternalsVisibleToAttribute 中使用“ friend ” .

对于那些由于某种原因需要继续支持私有(private)方法测试的人,同一篇文章对逻辑问题"What is available for me then?"提供以下建议。 :

For those who wish to continue testing internal APIs, you have three options:


  1. Use the Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject class to assist in accessing internal and private APIs in your code. This is found in the Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll assembly.
  2. Create a reflection framework that would be able to reflect off your code to access internal or private APIs.
  3. If the code you are trying to access is internal, you may be able to access your APIs using the InternalsVisibleToAttribute so your test code can have access to the internal APIs.

However, there is not any good replacement for Code Generation for the new features added by the lanugage teams. You may create the TestMethod stubs and then remove the internal code. You only need to keep the stub itself.



进一步阅读/帮助我将其拼凑在一起的资源:
  • VS 2005 ASP.NET explanation访问者
  • 2008 blog article解释如何为构建服务器解决此问题
  • MSDN forum thread讨论访问器的目的、实现和解决方法。从大约 1/3 开始。
  • MSDN BaseShadow docs
  • MSDN PrivateObject class
  • 关于asp.net - VS2017 无法加载文件或程序集 Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll 或其依赖项之一,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44525487/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com