本文介绍了将 NSubstitute 导入 Unity 项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的 Unity 项目(Unity 版本 2019.2.2f1)中使用 NSubstitute.无论如何导入,当我尝试 using NSubstitute 时,我的 IDE(Visual Studio 和 JetBrains Rider)都会报错,说 NSubstitute 未定义.

我尝试了 NSubstitute 软件包的许多选项和版本(4.2.1 和 2.0.3).我还将 dll 文件从包的 net35 文件夹导入到我的 Unity 项目中的 Plugins 文件夹中.我还尝试在 IDE 中使用 Nuget 安装相同版本的 NSubstitute.

解决方案

2020 年更新

如果您在 2020 年或之后阅读本文,请查看

当您现在在 Rider 中重新打开项目时,应该会找到它.有时 Unity 会出现一些问题,似乎没有找到 DLL.在这种情况下,重新导入项目会有所帮助.

I'm trying to use NSubstitute in my Unity project (Unity version 2019.2.2f1). No matter how to import it, my IDE, both Visual Studio and JetBrains Rider, would give an error when I try using NSubstitute saying NSubstitute is undefined.

I have tried many options and versions of NSubstitute packages (4.2.1 and 2.0.3). I also import the dll file from net35 folder of the package into a Plugins folder in my Unity project. I also tried to install the same version of NSubstitute using Nuget in the IDE.

解决方案

Update 2020

If you read this in 2020 or later, check the answer from Rodrigo Eleuterio how to make this work with the latest version of NSubstitute.

/end update

I was able to make the 2.0.3 version work with Unity. The newer versions have additional dependencies which I could not make work in Unity, so it seems for now we're stuck with 2.0.3. So here is how I did it:

  • Download 2.0.3 from the NuGet Website.
  • Unzip the file and move the lib/net35/NSubstitute.dll into the Plugins folder of your project.
  • In your test assembly definition, don't forget to reference it, otherwise it will not be found.

When you now reopen the project in Rider it should be found. Sometimes Unity acts up a little and doesn't seem to find the DLL. In this case re-importing the project can help.

这篇关于将 NSubstitute 导入 Unity 项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 02:42