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

C#.Netasp.netasp.net MvcVisual Studio

C# Problem Overview


Every time I edit a resource file in VS, it regenerates the corresponding code and sets the class access modifier to internal.
It's a pain to Ctrl-F -> ReplaceAll every time I edit the resx. Is there a property/setting so that I can default this to public?

internal class MyResource {

     internal static global::System.Resources.ResourceManager ResourceManager {...}

}

I need all those internal to be public all the time.

C# Solutions


Solution 1 - C#

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.

Solution 2 - C#

  1. Right click on Resource file ( resource.resx ) => Properties.

  2. Custom Tool => Change to PublicResXFileCodeGenerator

Solution 3 - C#

Perhaps the easiest way is to create a derived class with a Public ctor?

The generated class:

 [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
    internal Strings() {
    }

The derived class:

public class PublicStrings : Strings
{
    /// <summary>
    /// Public localization Strings.
    /// </summary>
    public PublicStrings()
    {

    }
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRobin MabenView Question on Stackoverflow
Solution 1 - C#AntonView Answer on Stackoverflow
Solution 2 - C#Rohan KView Answer on Stackoverflow
Solution 3 - C#Trond Ivar LindbergView Answer on Stackoverflow