Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to make Strongly Typed Resource files public (as opposed to internal)?

Tags:

Here's what I'd like to do:

I want to create a library project that contains my Resource files (ie, UI Labels and whatnot). I'd like to then use the resource library both in my UI and in my Tests. (Ie, basically have a common place for my resources that I reference from multiple projects.)

Unfortunately, because the StronglyTypedResourceBuilder (the .Net class which generates the code for Resources) makes resource files internal by default, I can't reference my strongly typed resources in the library from another project (ie, my UI or tests), without jumping through hoops (ie, something similar to what is described here, or writing a public wrapper class/function).

Unfortunately, both those solutions remove my ability to keep the references strongly-typed.

Has anyone found a straight-forward way to create strongly typed .Net resources that can be referenced from multiple projects?

I'd prefer to avoid having to use a build event in order to accomplish this (ie, to do something like replace all instances of 'internal' with 'public', but that's basically my fall-back plan if I can't find an answer..

like image 590
Peter Bernier Avatar asked Sep 26 '08 17:09

Peter Bernier


People also ask

Which utility can be used to create a resource file from a text file?

You can use Resgen.exe in diverse ways: to compile a text-based or XML-based resource file into a binary file, to convert between resource file formats, and to generate a class that wraps ResourceManager functionality and provides access to resources.

How do I open a RESX file?

Navigate to resources from File StructureOpen a . resx file in the XML (Text) editor. Press Ctrl+Alt+F or choose ReSharper | Windows | File Structure from the main menu . Alternatively, you can press Ctrl+Shift+A , start typing the command name in the popup, and then choose it there.

What is the use of resx file in c#?

Resources in . resx files. Unlike text files, which can only store string resources, XML resource (. resx) files can store strings, binary data such as images, icons, and audio clips, and programmatic objects.

What is ResXFileCodeGenerator?

NET 2005 IDE is a custom tool called ResXFileCodeGenerator that is automatically associated with resources (. resx files) every time they are added into a project.


2 Answers

Not sure which version of Visual Studio you are using, so I will put steps for either one:

VS 2008 - When you open the resx file in design view, there is an option at the top beside Add Resource and Remove Resource, called Access Modifier, it is a drop down where you can change the generated code from internal to public.

VS 2005 - You don't have the option to generate the code like in VS 2008. It was a feature that was added, because of this headache. There are work around's though. You could use a third party generator like this tool or you could use the InternalsVisibleTo attribute in your AssemblyInfo.cs to add the projects that will have access to the internal classes of your resource library.

like image 131
Dale Ragan Avatar answered Oct 21 '22 16:10

Dale Ragan


Visual Studio 2008 allows you to select whether the generated resource class should be internal or public. There is also the ResXFileCodeGeneratorEx, which should do that for Visual Studio 2005.

like image 27
OregonGhost Avatar answered Oct 21 '22 16:10

OregonGhost