Reputation: 151
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
Upvotes: 9
Views: 12967
Reputation: 988
All you need to do is just change the Access Modifier from Internal
to Public
in the resource file, and voila, you can access the resources directly in other projects.
No nonsense additional steps. Note that you may get a warning.
Upvotes: 2
Reputation: 151
Wow, I finally found it from searching online.
I Linked the resource file in Project A to Project B.
Right Click Project B and "Add-Existing Item" then Browse the resource file in Project A
(
myresrc-en.resx
and mymyresrc-fr.resx
)
Add a Link for both. Now in Project B
ResourceManager rmg=new ResourceManager("B.myresrc", Assembly.GetExecutingAssembly());
string str1 = rmg.GetString("resxTxt"); // resxTxt is any string in your resx file.
It worked perfectly. Keep original resources in Project A unchanged. These were already Embedded Resource.
Enjoy!
Upvotes: 5
Reputation: 639
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
Upvotes: 3
Reputation: 101
You could create a separate project C containing the resources that both A and B can use.
Upvotes: 0