【问题标题】:F# unit testing: nunit.framework assembly not referenced errorF# 单元测试:nunit.framework 程序集未引用错误
【发布时间】:2015-04-09 21:56:12
【问题描述】:

我正在使用 F# 进行单元测试。我正在运行 Visual Studio 2013 社区版。我创建了一个测试项目并安装了NUnit 2.6.4FsUnit 1.3.0.1。我使用了包管理器控制台。我在项目中添加了对库的引用,在我的脚本文件中我引用了 DLL 并添加了 open 子句:

#r @"C:\Users\pw\Documents\Visual Studio 2013\Projects\FSharpForQuantFirst\packages\FsUnit.1.3.0.1\Lib\Net40\FsUnit.NUnit.dll"
#r @"C:\Users\pw\Documents\Visual Studio 2013\Projects\FSharpForQuantFirst\packages\NUnit.2.6.4\lib\nunit.framework.dll" 

open NUnit.Framework
open NUnit.Framework.Constraints
open FsUnit

1 |> should equal 1

我的代码中没有错误或警告。但是,当我在 F# Interactive 中运行代码时,最后一行会触发以下错误:

Test.fsx(8,6):错误FS0074:通过'NUnit.Framework.Constraints.Constraint' 引用的类型是在未引用的程序集中定义的。您必须添加对程序集 'nunit.framework' 的引用。

但我已经添加了对nunit.framework 的引用。

我清理了项目,重新安装了包,删除并添加了引用,但结果是一样的。我仍然得到错误。知道问题出在哪里以及如何解决吗?

【问题讨论】:

    标签: f# assembly-binding-redirect fsunit


    【解决方案1】:

    如果您可能已经注意到,有一个 app.confignunit.framework 绑定重定向。

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-4.3.1.0" newVersion="4.3.1.0" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity name="nunit.framework" publicKeyToken="96d09a1eb7f44a77" culture="neutral" />
            <bindingRedirect oldVersion="0.0.0.0-2.6.4.14350" newVersion="2.6.4.14350" />
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
    </configuration>
    

    F# Interactive 没有考虑这一点,因此您必须使用 FsUnit.NUnit.dll 引用的 NUnit 2.6.3

    请将NUnit 降级为2.6.3,并确保重置 F# 交互会话。

    【讨论】:

    • 我已经卸载了NUnit 2.6.4 并安装了版本2.6.3。但我仍然得到同样的错误......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多