In Microsoft Visual Studio Enterprise 2022 (64-bit) version 17.11.1, I am developing a C# WPF application. I use Resources.resx file for storing string translations in English, and up until recently I was able to successfully generate the Resources.Designer.cs file automatically from Resources.resx whenever I added a new translation using Resource Explorer in Visual Studio 2022. But then I wanted to add lots of translations at a time, so I used Visual Studio Code to edit the Resources.resx file directly and added tens of new translations. However, from that time, I am no longer able to generate the Resources.Designer.cs file at all.
I tried generating the Resources.Designer.cs file manually by right clicking the Resources.resx file in Solution explorer and choosing "Run custom tool" as adviced in ansers to similar question here: Adding new strings to resource.resx not reflecting into Designer.cs, but it has no effect. I am posting this new question here as I use Visual Studio 2022 whereas similar questions here at Stack Overflow relate to older versions of Visual Studio.
My Resources.resx file is well formatted XML document, it displays all strings correctly in Resource Explorer, and I have used Visual Studio code already before to add few translations at a time and the generation worked, but as I wrote, now the Resources.Designer.cs generation for some reason stopped working.
I also tried the following with no success:
- Restarting Visual Studio and reopening the solution.
- Restarting computer.
- Creating a new solution with just the Resources.resx file with all my translations and trying Resources.Designer.cs generation there.
Please, any ideas what might be going wrong?
2
Answers
Update: I've found out the problem was in my
Resources.resx
file. It was well-formed XML, but was invalid even though Visual Studio was able to parse and display it in Resource Explorer. Concretely, in the file I had the following invalid markup, which I don't know how it originated:Once I modified it to the following markup, Visual Studio started to be able to generate
Resources.Designer.cs
from it:Old solution
For completeness, I leave the old solution here, as it may help somebody who wants to generate
Resources.Designer.cs
file manually without needing Visual Studio.The old solution was not relying on Visual Studio to generate the
Resources.Designer.cs
file, but instead use the Resgen.exe command line tool located atC:Program Files (x86)Microsoft SDKsWindowsv10.0AbinNETFX 4.8 ToolsResGen.exe
. The command has the following syntax when in the tool's directory:In my case the exact command when in the
Resources.resx
file directory is:The command generates two files:
Resources.cs
andResources.resources
. I don't need the latter so I delete it, and the former does not need to be renamed toResources.Designer.cs
as Visual Studio recognizes it even with the nameResources.cs
.It seems there is a bug in the new versions (17.11.1 & 17.11.2), take a look at Revamped Resource Explorer they made some things new and today I reported this as this link below. Please vote on it until the support team fixes it.
1-When you add a new resource its properties must be set to Build Action = Embedded Resource and Custom Tool = ResXFileCodeGenerator, to generate “.Designer.cs” file.
2-There is no option to make your resource public and you should change it manually in “.Designer.cs” file and every time that you rename your file you should change the internal to the public if you want to use it as public.