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
- 'No code generation' means a designer file like 'Resource.Designer.cs' doesn't get created:
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):
Setting File From Internal To Public
Either select "public" in the combobox "Access modifier" in settings designer:
Or you can manually set that settings class to be public in generated code:
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
Upgrading Old Unity Code to Unity 5
What's the Fastest Way to Bulk Insert a Lot of Data in SQL Server (C# Client)
Step by Step Tutorial to Use Sap. Net Connector with VS 2008
Convert an Object to an Xml String
How to Do Logging in C# Without Using 3Rd Party Libraries
How to Add Data Table with Legend Keys to a Ms Chart in C#
MVC 4 Edit Modal Form Using Bootstrap
Lock-Free Multi-Threading Is for Real Threading Experts
Login Using Google Oauth 2.0 with C#
If My Interface Must Return Task How to Have a No-Operation Implementation
Accelerating Bitmap Grayscale Conversion, Is Openmp an Option in C#
Looking for a Command Line Argument Parser for .Net
Find the Next Tcp Port in .Net
Multi Threading C# Application with SQL Server Database Calls