问题
Hi There: I have 2 projects in a solution. Project A and Project B. B has a reference to A. Thus A uses B's class and functions. B does not have any resource files as it contains all business functions only. A contains all the resource files. I need to use a resource file from An into B. I CAN NOT refer to A in B. I deploy my main project and it has referred to B. But how can I refer to a resource file(of A project) into B project without referencing the A library in B. Thanks in advance
回答1:
You could add a reference to the project that contains the resource file. However, to use the resource file which is generated as an internal class by default (inaccessible in your project if it's under a different namespace), you need to change the access modifier to public. See https://stackoverflow.com/a/4274341/3666333
回答2:
Wow, I finally found it from some search. From B, I Linked the resource file in A. Right Click B-Add-Existing Item-Browse the resource file in A(myresrc-en.resx
and my myresrc-fr.resx
)-Add a Link for both. Now in B,
ResourceManager rmg=new ResourceManager("B.myresrc", Assembly.GetExecutingAssembly());
string str1 = rmg.GetString("resxTxt"); // resxTxt is any string in your resx file.
It worked perfect. Keep original resources in A unchanged. These were already Embedded Resource.
Enjoy!
回答3:
You could create a separate project C containing the resources that both A and B can use.
来源:https://stackoverflow.com/questions/38332325/accessing-a-resource-file-from-another-project-c-sharp-net