40

I am adding two new strings to our resource.resx but these newly added resources(strings) are not reflecting into the auto-generated Designer.cs file. I have rebuilt the project and also tried clean+build the project but no luck! I have other resource files to support various international languages where also i need to these two new string resources

Please suggest.

sandy
  • 616
  • 2
  • 9
  • 20

8 Answers8

70

Make sure the Custom tool property for your resx file is set to ResXFileCodeGenerator or PublicResXFileCodeGenerator. The .Designer.cs file should be regenerated every time you modify the resx file; if it's not, you can force it by selecting Run custom tool in the context menu for the resx file.

Thomas Levesque
  • 286,951
  • 70
  • 623
  • 758
  • 1
    Setting Custom tool property of .resx file to ResXFileCodeGenerator and running the same generated another designer.cs file which is already there and part of the project. How to proceed then? – sandy May 12 '14 at 09:47
  • 2
    @Sandeep, do you mean that it generated a extra Designer.cs file? Just delete both Designer.cs files and edit the csproj to remove the `` element. Afterwards the custom tool should generate the correct file. – Thomas Levesque May 12 '14 at 10:15
  • Yes it generated extra designer.cs right under the english resource file(resource.resx) and the generated designer.cs has the same code as the main one. – sandy May 12 '14 at 10:20
  • Can i manually edit designer.cs and the properties for the two string resources?What would be the consequences? – sandy May 12 '14 at 10:53
  • @Sandeep, don't edit designer files; anything you write will be overwritten the next time the file is generated. Just follow the steps in my previous comment and it should work fine. – Thomas Levesque May 12 '14 at 12:33
  • Thanks for this - I don't know how it became disconnected but it fixed the problem. – Michael Brown Sep 02 '18 at 21:51
  • If you have resx for different languages, do you set `PublicResXFileCodeGenerator` only on the main resx file? – testing May 20 '20 at 13:10
  • @testing yes, exactly – Thomas Levesque May 20 '20 at 13:24
10

Right click the resx file in solution explorer, select "Run custom tool".

This generated/added the code in the .designer.cs file for the new strings in the resource file for me.

tonyb
  • 379
  • 2
  • 6
9

When editing the resource file in Visual Studio, check the Access Modifier drop down is not set to No code generation.

If it is then select the appropriate option from the drop down - Public or Internal.

Enable Resource Code Generation

Dizzy
  • 448
  • 5
  • 15
2

You just need to :

enter image description here

& then do :

enter image description here

Tada! You got your new Designer.cs !

Hashka
  • 395
  • 3
  • 10
2

In JetBrains Rider, I had to right-click the resx file and select "Generate resources"

1

I had the same issue when I renamed my [YOUR_RESOURCE].resx file into [YOUR_RESOURCE].en-US.resx. It seems [YOUR_RESOURCE].Designer.cs no longer auto generates any code after you renamed the default [YOUR_RESOURCE].resx format to something like [YOUR_RESOURCE].en-US.resx

macio.Jun
  • 9,647
  • 1
  • 45
  • 41
0

I came across this solution and it worked fine for me.

  • Close the solution
  • Edit the project file LastGenOutput tag for the resource file
  • Open the solution again and try
Community
  • 1
  • 1
0

If you're looking to automate this process you can use resgen

resgen c:\development\test\properties\resources.resx /str:csharp
Mark Nadig
  • 4,901
  • 4
  • 37
  • 46