我对 C# 中的单元测试还很陌生。我使用 Visual Studio 添加了一个测试项目,但是当我尝试运行测试时,它们失败了,并提示程序集绑定(bind)失败。
所以我启用了日志记录并注意到测试正在尝试从特定于文化的目录(一个不存在的目录)加载我的 DLL。
例如如果测试项目的 DLL 存在于 C:\MyProject\ 中,它会在 C:\MyProject\en-GB\ 中查找被测程序集。
en-GB
的唯一引用是被测程序集的程序集文化属性。如果我将该属性的值更改为 en-US
,则单元测试绑定(bind)程序会在 /en-US/
我能以某种方式指定我不想要这种行为吗?
最佳答案
来自文档,
The attribute is used by compilers to distinguish between a main assembly and a satellite assembly. A main assembly contains code and the neutral culture's resources. A satellite assembly contains only resources for a particular culture, as in [assembly:AssemblyCultureAttribute("de")]. Putting this attribute on an assembly and using something other than the empty string ("") for the culture name will make this assembly look like a satellite assembly, rather than a main assembly that contains executable code. Labeling a traditional code library with this attribute will break it, because no other code will be able to find the library's entry points at runtime.
所以基本上,不要使用该属性。您实际上是在测试本地化的卫星组件吗?
关于c# - 单元测试 - 绑定(bind)程序集时忽略区域性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20959807/