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

61,097

Solution 1

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

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

  2. Custom Tool => Change to PublicResXFileCodeGenerator

Share:
61,097
Robin Maben
Author by

Robin Maben

LinkedIn Profile Github Profile Other Thoughts

Updated on July 28, 2022

Comments

  • Robin Maben
    Robin Maben almost 2 years

    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
      Robin Maben over 13 years
      @jvanrhyn: Because I need to access its resource manager from another project in the solution.
  • Marc Gravell
    Marc Gravell over 13 years
    (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)
  • Robin Maben
    Robin Maben over 13 years
    @Anton: Thanks, works in my case. Also, I noticed that changing access modifier from the drop down changes the corresponding tool.
  • Anton
    Anton over 13 years
    @conqenator: that's why I proposed using the Access Modifier dropdown as an alternative way of reaching the same outcome :)
  • Raheel Khan
    Raheel Khan about 12 years
    @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.
  • Céryl Wiltink
    Céryl Wiltink over 10 years
    Jup, I'm another one who missed the modifier dropdown until I found this answer! Thanks @Anton!
  • Manuel Navarro
    Manuel Navarro over 10 years
    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.
  • zaitsman
    zaitsman over 9 years
    So that's still a click for each resx. Any way to make VS create them public by default?
  • Thad
    Thad almost 9 years
    This is not possible. You will get an error CS0060 Inconsistent accessibility: base class 'Strings' is less accessible than class 'PublicStrings'
  • Laurent Michel
    Laurent Michel almost 5 years
    For me with Visual Studio 2017 choosing the PublicResXFileCodeGenerator only makes the Resources class public, not its constructor.
  • Luis de Haro
    Luis de Haro over 4 years
    It works fine for Visual Studio for Mac 2019 as well.
  • Milton
    Milton over 2 years
    Thank you! Driven crazy by this for an entire morning