212

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.

Robin Maben
  • 22,194
  • 16
  • 64
  • 99

4 Answers4

440

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.

SliverNinja - MSFT
  • 31,051
  • 11
  • 110
  • 173
Anton
  • 5,323
  • 1
  • 22
  • 25
  • 15
    (Good answer; but just some notes; it could also be `GlobalResourceProxyGenerator`, not just `ResXFileCodeGenerator`; and note also that the "Access Modofier" dropdown is often disabled) – Marc Gravell Nov 25 '10 at 06:45
  • @Anton: Thanks, works in my case. Also, I noticed that changing access modifier from the drop down changes the corresponding tool. – Robin Maben Nov 25 '10 at 06:56
  • 3
    @conqenator: that's why I proposed using the Access Modifier dropdown as an alternative way of reaching the same outcome :) – Anton Nov 25 '10 at 07:10
  • @Anton: Thanks. Most people new to resource files miss the modifier drop down. In a rush project, I went so far as to manually strong type each resource name. – Raheel Khan Apr 19 '12 at 07:24
  • Jup, I'm another one who missed the modifier dropdown until I found this answer! Thanks @Anton! – Céryl Wiltink Nov 27 '13 at 13:42
  • 2
    BTW if the Access Modifier dropdown is disabled, you can try changing the Custom Tool property to ResXFileCodeGenerator, if that's not the value alredy. At least that work for me in an MVC project on VS 2010. – Manuel Navarro Jan 13 '14 at 21:24
  • So that's still a click for each resx. Any way to make VS create them public by default? – zaitsman Oct 15 '14 at 04:27
  • 3
    For me with Visual Studio 2017 choosing the `PublicResXFileCodeGenerator` only makes the Resources class public, not its constructor. – Laurent Michel Jul 05 '19 at 11:18
  • 1
    It works fine for Visual Studio for Mac 2019 as well. – Luis de Haro Oct 22 '19 at 17:10
26
  1. Right click on Resource file ( resource.resx ) => Properties.

  2. Custom Tool => Change to PublicResXFileCodeGenerator

SliverNinja - MSFT
  • 31,051
  • 11
  • 110
  • 173
Rohan K
  • 872
  • 11
  • 18
1

In your .csproj change for each .Designer.cs

<Generator>ResXFileCodeGenerator</Generator>

To

<Generator>PublicResXFileCodeGenerator</Generator>

Or from the interface

enter image description here

Hope it's help

G Clovs
  • 2,442
  • 3
  • 19
  • 24
-11

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()
    {

    }
}