简体   繁体   English

如何阻止我的主项目中使用我的 dll(参考)中的 resx 文件?

[英]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.

相关问题 如何确保dll函数不被我的应用程序外使用? - how to secure dll functions from being used outside of my application? 如何从我的resx文件中检索图像? - How do I retrieve an image from my resx file? 如何在ASP的网站项目中读取.resx文件的属性。 DLL程序集的网络 - How to read the properties of an .resx file in a Web site project of asp. Net from a dll assembly C# - 从我添加的 NET.dll 文件定义事件作为对我的项目的引用 - C# - Defining an event from a NET .dll file I added as a reference to my project 我创建了一个.resx文件,如何在我的视图页面中引用它? - I created a .resx file, how do I reference it in my view page? 如何将dll项目设置整合到Visual Studio 2010中用于C#应用程序的主exe.config文件中? - How can I consolidate my dll project settings into my main exe.config file in Visual Studio 2010 for a C# application? 如何将新项目添加到现有项目并从新项目创建 dll 文件? - How can i add a new project to my existing already project and create a dll file from the new project? 为什么我的LocalCopy dll不是从参考项目中的参考项目进行本地复制的? - Why are my LocalCopy dll's not localcopied from a reference project in a reference project? 如何确定是否使用.resx文件? - How to determine if a .resx file is used? 从dll读取Main Project中的文件 - Read a file in Main Project from dll
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM