[英]How to stop the resx file in my dll(reference) from being used in my main project?
So I have two projects, Tester and Coder.所以我有两个项目,Tester 和 Coder。 I've added the Coder.dll in my Tester project as reference, the issue is that both these projects have their own 'SetUp.resx' files for setup and for some reason the Tester project is using the 'SetUp.resx' file of Coder instead of its own SetUp.resx file.
我在我的 Tester 项目中添加了 Coder.dll 作为参考,问题是这两个项目都有自己的“SetUp.resx”文件进行设置,并且出于某种原因, Tester 项目正在使用“SetUp.resx”文件Coder 而不是它自己的 SetUp.resx 文件。
Coder has a string Name "browser" whose values are "Chrome, Firefox"
Tester has a string Name "browser" whose value is "Chrome"
As shown above, The "Browser" value is used for making the tests, so in Coder there will be two test cases ie, "Chrome and firefox" And in Tester there should be only one test, ie, Chrome but it still shows 2 tests (Chrome and Firefox) which shows that its taking the SetUp.resx from Coder.dll如上所示,“浏览器”值用于进行测试,因此在 Coder 中将有两个测试用例,即“Chrome 和 firefox” 而在 Tester 中应该只有一个测试,即 Chrome 但它仍然显示 2测试(Chrome 和 Firefox)表明它从 Coder.dll 获取 SetUp.resx
This is how the SetUp.resx file looks like in Tester这是 SetUp.resx 文件在Tester 中的样子
Name | Value |Comments
Browser | Chrome |Browser to be tested with separated by Comma
BuildNumber| v2.1 |aka version
This is what I've done for SetUp.Designer.cs in Tester这就是我在Tester 中为 SetUp.Designer.cs 所做的
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal SetUp() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TestProject3.Configurations.SetUp", typeof(SetUp).Assembly); //Path of Tester's SetUp.resx
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
internal static string BuildNumber {
get {
return ResourceManager.GetString("BuildNumber", resourceCulture);
}
}
internal static string Browser { //Gets string value for Browser in SetUp.resx
get {
return ResourceManager.GetString("Browser", resourceCulture);
}
}
}
This is the code for the function accessing the resx这是访问 resx 的函数的代码
internal static IEnumerable Browsers()
{
get
{
String[] browser = Configurations.SetUp.Browser.Split(",");
foreach (string b in browser)
{
yield return b;
}
}
}
Could someone please tell me where I went wrong and what should be changed in my code?有人可以告诉我我哪里出错了,我的代码应该改变什么?
I tried to find a way that uses the filepath of the resource file so tester doesn't get confused with the coder's resx.我试图找到一种使用资源文件的文件路径的方法,这样测试人员就不会与编码器的 resx 混淆。
internal static IEnumerable Browsers()
{
var enviroment = System.Environment.CurrentDirectory;
string resxFile = Directory.GetParent(enviroment).Parent.Parent.FullName + @"\Configurations\SetUp.resx";
String[] browser;
IDictionaryEnumerator dict;
string key;
using (ResXResourceSet resSet = new ResXResourceSet(resxFile))
{
dict = resSet.GetEnumerator();
while (dict.MoveNext())
{
key = (string)dict.Key;
// Retrieve resource by name.
if (dict.Key is "Browser")
{
browser = resSet.GetString(key).Split(",");
foreach (string b in browser)
{
yield return b;
}
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.