你怎么指示NUnit的,从一个特定的目录加载程序集的dll.config文件? [英] How do you instruct NUnit to load an assembly's dll.config file from a specific directory?
问题描述
如果一个程序集包含一个app.config文件, ConfigurationManager中
只要会加载它,因为它是在同一个目录中,它通过NUnit的桂执行NUnit的项目。为了说明考虑下面的文件夹结构。
+ TestFolder
testProject.nunit
+ AssemblyAFolder
assemblyA.dll
assemblyA.dll.config
+ AssemblyBFolder
assemblyB.dll
assemblyB.dll.config
两个 AssemblyA
和 AssemblyB
运动code调用到 ConfigurationManager中
。如果我在NUnit的桂独立运行这些测试程序集, ConfigurationManager中
将正确解析本地配置文件。
不过,如果我加载 testProject.nunit
到NUnit的桂(其中包含引用了 AssemblyA
和 AssemblyB
), ConfigurationManager中
会在 TestFolder
不管其中装配当前正在执行。
有没有办法直接NUnit的重新加载在当前汇编目录应用程序配置为一present?
下面是内容 testProject.nunit
:
< NUnitProject>
<设置activeconfig =调试/>
<配置NAME =调试binpathtype =自动>
<装配路径=AssemblyAFolder \ assemblyA.dll/>
<装配路径=AssemblyBFolder \ assemblyB.dll/>
< /配置>
< / NUnitProject>
NUnit的博客为何配置文件加载它们的方式做解释。基本上,他们说的是,NUnit的允许的框架内处理配置文件,并没有做任何的管理。
您也可以使用,将在你的情况下加载的 testProject.config
文件,以引用配置文件为每个组件。使用AppSettings文件属性添加键。
最后一个替代方案是使用<一href="http://msdn.microsoft.com/en-us/library/system.configuration.sectioninformation.configsource(VS.85).aspx"相对=nofollow> configSource
元素属性使用该部分中的组件配置文件中的一个。
希望这有助于。
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
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.
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.
Is there a way to direct NUnit to reload the application configuration to the one present in the current assembly's directory?
Here are the contents of testProject.nunit
:
<NUnitProject>
<Settings activeconfig="Debug" />
<Config name="Debug" binpathtype="Auto">
<assembly path="AssemblyAFolder\assemblyA.dll" />
<assembly path="AssemblyBFolder\assemblyB.dll" />
</Config>
</NUnitProject>
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.
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.
One final alternative is to use the configSource
element attribute to use the section in one of the assemblies config files.
Hope this helps.
这篇关于你怎么指示NUnit的,从一个特定的目录加载程序集的dll.config文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!