7

I have a resource file in a different project and want to access eg. strings from it. How can i do this?

Sys
  • 443
  • 1
  • 8
  • 28
  • Have you checked http://stackoverflow.com/questions/1222519/access-resx-resource-files-from-another-project – Madhur Ahuja Feb 02 '11 at 11:04
  • 1
    @MadhurAhuja: This question is about ASP.NET. Would love to see a similar answer for a non-web project. – Doug Jul 10 '14 at 14:16

2 Answers2

5

Make your access modifier to public .

enter image description here

Sagar Dev Timilsina
  • 1,310
  • 15
  • 32
  • This. I just set this modifier and ide automatically suggested referencing it in other project – Justas Oct 11 '22 at 14:24
3

This is a super old question, but since it has not been answered and I just stumbled upon this problem, here are some possible solutions:

Make sure that the access modifier of the resx is set to public!

Link to the resx file

See here

Then you either acces the string directly with

var translatedString = Resources.NAME_OF_THE_STRING_IN_RESX_FILE;

or via ResourceManager

var resourceManager = new ResourceManager("FULLY.QUALIFIED.NAMESPACE.NO.EXTENSION", Assembly.GetExecutingAssembly());
var translatedString = resourceManager.GetString("NAME_OF_THE_STRING_IN_RESX_FILE");

Direct access when you have a reference to the project

var translatedString = [FULLY.QUALIFIED.NAMESPACE.NO.EXTENSION].NAME_OF_THE_STRING_IN_RESX_FILE;
Fabian
  • 435
  • 2
  • 5
  • 11
  • To use it like `Resources.NAME_OF_THE_STRING_IN_RESX_FILE` or `Resources.LocalizedText.NAME_OF_THE_STRING_IN_RESX_FILE`, you would need to link the designer file > edit the resx file access modifier from _`No code generation`_ to _`Internal`_ or _`Public`_ which would create a new designer file > edit the csproj file to connect the linked designer file to the linked resx file to avoid using the newly created designer file > then delete the newly created designer file > _et voilà_! – Dennis T --Reinstate Monica-- Nov 07 '19 at 22:55
  • The designer file must have `namespace Resources` at the top. Also, the `ResourceManager` property must have this line `global::System.Resources.ResourceManager("Resources.LocalizedText", global::System.Reflection.Assembly.Load("App_GlobalResources"));`. This is also near the top. This will get overwritten by Visual Studio every time you make a change to the resx file. That’s the only pain point with this solution. – Dennis T --Reinstate Monica-- Nov 20 '19 at 00:21
  • 2
    The link is dead, that means the first answer does not make sense any more. Please consider fixing the link and put summary of what is inside the link. – Mohammed Noureldin Jan 08 '20 at 05:31