views:

668

answers:

3

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..

+1  A: 

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.

OregonGhost
I'm using VS 2005, so the ResXFileGeneratorEx would have been the way to go. Thanks for your answer!
Peter Bernier
A: 

From the dataset designer and with the properties window visible, there is a "Modifier" property. For your datasets, it is likely saying internal.

I don't know if there is a setting to default all new datasets to public.

Austin Salonen
+4  A: 

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.

Dale Ragan
Perfect, Thank you! I hadn't seen the InternalsVisibleTo attribute before, but that's exactly what I needed. It lets me keep things simple, clean, and I don't have to install the ResXFileCodeGeneratorEx.
Peter Bernier