使用NUnit进行测试时,NDepend TypeInitializationExceptions

所以我试图使用NDepend API来设置一个项目,用于我的代码的某些指标(这很好地工作),但是,当我试图运行测试框架(NUnit)时,我得到了TypeInitializationExceptions。

这里是一些代码来重现我得到的错误:

  • 创建一个类库项目,并引用$NDependInstallPath$libNDependAPI的NDepend API dll,将copy local设置为false 。 创建一个类如下:

    public class NDependProjectLoader
    {
      public void LoadAnNDependProject()
      {
        var provider = new NDependServicesProvider();
      }
    }
    
  • 在将成为Test类的解决方案中创建第二个类库项目。 引用NUnit和您创建的引用NDependAPI的项目

    [TestFixture]
    public class NDependProjectLoader_Tests
    {
      [Test]
      public void I_can_load_an_depend_project()
      {
        new NDependProjectLoader().LoadAnNDependProject();
      }
    }
    
  • 使用您选择的测试运行器构建并运行测试(我已经尝试了Resharper的测试运行器和NUnit GUI)。

  • 您将在行上获得TypeInitializationException var provider = new NDependServicesProvider();

  • 向内看,TypeInitializationException表明根异常的消息是:

  • "{"Could not load file or assembly 'NDepend.Platform.DotNet' or one of its dependencies. The system cannot find the file specified.":"NDepend.Platform.DotNet"}".

  • 从NDepend.PowerTools示例项目中添加AssemblyResolverHelper并按照入门指南中的描述调用它并不会改变行为。

  • 我/假设/问题与NDepend API入门指南中的此声明有关,网址为http://www.ndepend.com/api/NDepend.API_gettingstarted.html

  • “程序可执行程序集必须生成到$ NDependInstallPath $ ”中

  • 在代码从测试运行器启动的情况下,可执行文件将不在ndepend安装路径中。

  • 从$ NDependInstallPath $ lib 中生成.exe的控制台应用程序调用NDependProjectLoader.LoadAnNDependProject()(请注意,.exe似乎需要在 lib 子文件夹中生成,而不是在$ NDependInstallPath $ 中生成,如入门指南)不会产生异常,这进一步指出这是原因。

  • 所以,问题是,除了控制台应用程序之外,如何使用NDepend API? 例如,在这里我想从一个测试跑步者那里做这件事。 另一个明显的候选人是IIS应用程序。 我错过了明显的东西吗?


    事实上,问题来自于组装决议。 您必须告诉CLR在哪里可以找到NDepend程序集(例如,在目录$ NDependInstallPath $ Lib中)。您有2个选择来执行此操作。 假设$ NDependInstallPath $是“C: NDepend”,例如:

  • 编辑AssemblyResolverHelper以解析“C: NDepend Lib”中的程序集

  • 为您的exe创建一个App.Config文件,添加一个引用“C: NDepend Lib”的<probing>元素。 当CLR不能解析程序集时,它会查看这个元素中的dir

  • 链接地址: http://www.djcxy.com/p/37711.html

    上一篇: NDepend TypeInitializationExceptions when Testing with NUnit

    下一篇: Detect Asp.Net Pages referencing other Pages (using NDepend? FXCop?)