您如何指示 NUnit 从特定目录加载程序集的 dll.config 文件? [英] How do you instruct NUnit to load an assembly's dll.config file from a specific directory?

查看:14
本文介绍了您如何指示 NUnit 从特定目录加载程序集的 dll.config 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果程序集包含 app.config 文件,只要它与通过 NUnit-Gui 执行的 NUnit 项目在同一目录中,ConfigurationManager 就会加载它.为了说明,请考虑以下文件夹结构.

If an assembly contains an app.config file, ConfigurationManager will load it as long as it is in the same directory as the NUnit project that is executing through NUnit-Gui. To illustrate consider the following folder structure.

+ TestFolder
    testProject.nunit
  + AssemblyAFolder
      assemblyA.dll
      assemblyA.dll.config
  + AssemblyBFolder
      assemblyB.dll
      assemblyB.dll.config

AssemblyAAssemblyB 都练习调用 ConfigurationManager 的代码.如果我在 NUnit-Gui 中独立运行这些测试程序集,ConfigurationManager 将正确解析本地配置文件.

Both AssemblyA and AssemblyB exercise code that calls into ConfigurationManager. If I run these test assemblies independently in NUnit-Gui, ConfigurationManager will correctly resolve the local configuration files.

但是,如果我将 testProject.nunit 加载到 NUnit-Gui(其中包含对 AssemblyAAssemblyB 的引用),无论当前正在执行哪个程序集,ConfigurationManager 都会在 TestFolder 中查找配置文件.

However, if I load testProject.nunit into NUnit-Gui (which contains references to both AssemblyA and AssemblyB), ConfigurationManager looks for the configuration file in TestFolder regardless of which assembly is currently executing.

有没有办法让 NUnit 将应用程序配置重新加载到当前程序集目录中的配置?

Is there a way to direct NUnit to reload the application configuration to the one present in the current assembly's directory?

这里是testProject.nunit的内容:

<NUnitProject>
  <Settings activeconfig="Debug" />
  <Config name="Debug" binpathtype="Auto">
    <assembly path="AssemblyAFolder\assemblyA.dll" />
    <assembly path="AssemblyBFolder\assemblyB.dll" />
  </Config>
</NUnitProject>

推荐答案

NUnit 博客解释了为什么配置文件以它们的方式加载.基本上他们说的是 NUnit 让框架处理配置文件而不做任何管理.

The NUnit blog explained of why the config files load the way they do. Basically what they said was that NUnit lets the framework handle the config files and doesn't do any of the management.

您还可以使用将在您的案例中加载的 testProject.config 文件来引用每个程序集的配置文件.使用 appSettings 文件属性添加密钥.

You can also use the testProject.config file that would be loaded in your case, to reference the config files for each of the assemblies. Using the appSettings file attribute to add keys.

最后一种选择是使用 configSource 元素属性 以使用其中一个程序集配置文件中的部分.

One final alternative is to use the configSource element attribute to use the section in one of the assemblies config files.

希望这会有所帮助.

这篇关于您如何指示 NUnit 从特定目录加载程序集的 dll.config 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆