Visual Studio - Resx File Default 'Internal' to 'Public'

Visual Studio - Resx File default 'internal' to 'public'

Instead of the ResXFileCodeGenerator, use the PublicResXFileCodeGenerator.

You can do this by setting this as the Custom Tool property in the Property Window for the Resx file you want public access to.

Edit: Alternatetively you can set the Access Modifier to public when you open the resx file in Visual Studio. The Access Modifier dropdown box can be found at the top of the form.

What does the Access Modifier option actually do in a RESX file?

Your assumptions about 1 and 2 are correct.

Try setting the access modifier of a resource item which is used outside of the project in which it was defined from 'Public' to 'Internal' and then build your project again. You will get compiler errors similar to :

error CS0122: 'Resource' is inaccessible due to its protection level


  1. 'No code generation' means a designer file like 'Resource.Designer.cs' doesn't get created:

Sample Image

For a resx resource file, why should I use an internal or public access modifier?

That depends on the encapsulation level for your projects/solutions if you feel that resource is more likely to be used internally then set it up as a protected/private/internal resource, if some of those properties may be configured and accessed by an external solution / project then leave it as public.

Encapsulation is good, just think about the way you consume external libraries and how they expose properties, classes,configurations, that's a good exercise to do. Think like an external developer who doesn't know anything about your project implementation, you can ask yourself the following questions:

  • is this piece of code worth to external developers to know about it?
  • do I need a pre-configuration on this code?
  • is my implementation clear enough so anybody understand it just by looking at the code implementation?
  • does the code enforce certain policies/requirements?
  • does my code have obscure implementations?

for me for example talking about IOC, setter injection could be a little bit obscure

Setter injection is just creating a setter property to replace a
dependency on a previously instantiated object. I don’t like Setter
Injection because it requires extra, hidden steps to prepare an object
to execute

look at this post to get the full context as an example, but again this is just an example.

Inaccessible, Internal, Resource Files?

Yep... didn't see this. Open up the resource file in design mode and change the access modifier (at least, on VS 2013):

Sample Image

Setting File From Internal To Public

Either select "public" in the combobox "Access modifier" in settings designer:

Sample Image

Or you can manually set that settings class to be public in generated code:

Sample Image

Changing Resource files (resx) namespace and access modifier

The quick answer is: Just open the Properties of the resource file and change the Custom Tool Namespace to the namespace you need.

Simple as that.

Visual Studio : can't find resource file in list of items to add to project

At the top right corner you have a searchbox, try typing it there and see if it finds anything.

If it doesn't, create a text file from the new item dialog and change the extension to

resx

It should now open the new file with the resources designer. Now open the properties pane for that file (right click it in the solution explorer) and make sure it has the following set:

  • Build Action: Embedded resource
  • Custom tool: ResXFileCodeGenerator (or PublicResXFileCodeGenerator to generate a designer class with public visibility)

NOTE:
According to the link Chris posted, my suggestion may not help if you have the express edition of visual studio.

How to statically access a .resx file

Open the .resx file using VS2008. From the .resx editor toolbar change the 'Access Modifier' to 'Public'. This will allow access to the resources from any asssembly that references the App_GlobalResources assembly (ex: Messages.EmailBodyMagazine).

You can also find a quick tutorial here.



Related Topics



Leave a reply



Submit