1

我有一个复杂的解决方案(在 Windows 下开发,在 GNU\Linux 下部署),其中包含许多单元测试项目,使用 NUnit 2.9.3。

这是项目的参考:

<Reference Include="nunit.framework, Version=2.9.3.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..\..\..\..\..\Program Files\NUnit 2.9.3\bin\net-4.0\nunit.framework.dll</HintPath>
</Reference>

我从源代码下载并构建了 NUnit 2.9.3 :

$ xbuild solutions/MonoDevelop/NUnit.Framework.sln /p:Configuration=Release

并安装到 GAC 中:

$ gacutil /i solutions/MonoDevelop/bin/Release/nunit.framework.dll

$ gacutil /l nunit.framework
The following assemblies are installed into the GAC:
nunit.framework, Version=2.9.3.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77
Number of items = 1

并删除了本地单 nunit 安装:

$ rm /usr/lib/mono/2.0/nunit*
$ rm /usr/lib/mono/4.0/nunit*

但是当我尝试构建我的解决方案时:

$ xbuild MySolution.sln | grep error

: error CS0006: Metadata file `/usr/lib/mono/2.0/nunit.framework.dll' could not be found

我错了什么?

4

3 回答 3

4

Build tools do not normally resolve assemblies from the GAC (except possibly as a last resort). On .NET they they "assembly folders" registered in the registry. On Mono they use "pkgconfig". You may have removed the nunit assemblies but you did not remove or fix the pkgconfig ("pc") file that tells xbuild and MonoDevelop where to find the dll.

This kind of stuff is why it's a bad idea to alter things installed by packages. You should either uninstall the package properly, or use the appropriate environment variables to override packaged stuff.

In this case, I would suggest you create a pc file for your new nunit assemblies, and put it into the /usr/local/lib/pkgconfig directory (/usr/local is the prefix for installing stuff you build from source), or put it somewhere else and have that somewhere else included in the PKG_CONFIG_PATH environment variable.

See also:

And for some general background on configuring Mono environments, see:

于 2011-02-02T23:11:56.247 回答
2

我将尝试将 NUnit 2.9.3 复制到我的源文件文件夹,例如(解决方案文件夹)\lib。然后在本地添加此引用并确保标记与此本地路径匹配。

配置后,我认为 xbuild 应该直接使用这个本地副本,而不是读取 GAC 或其他预配置路径。如果没有,我会向 Mono 团队报告一个错误。

于 2011-02-03T01:59:35.183 回答
2

单声道编译器的 /pkg 选项对我来说效果很好......

dmcs test.cs /r:System.Configuration.dll /r:System.dll /pkg:nunit

FWIW,我使用 apt-get 包管理器(在 Ubuntu 上)安装了 nunit ...

sudo apt-get install nunit
于 2012-09-03T06:03:05.067 回答