问题
I had a resource file named Localize.resx, which contains English strings. I copied and pasted it inside the same folder(App_GlobalResources), VS created a copy, I renamed the copy to Localize.sl.resx and the original to Localize.en.resx. Now everything in codebehind files (Localize.en.designer.cs) is gone. Deleting the designer file and selecting Run Custom Tool generates a new but completely blank designer file.
I still have all my strings in both resx's but the designer files are gone (empty) so the application does not build.
Any suggestions?
This is inside Vs 2010 with ASP.NET MVC solution.
回答1:
I had the same problem - Designer.cs file not being present for some resx files.
The fix was to set the properties for the resx files:
Build Action - Embedded Resource
Custom Tool - PublicResXFileCodeGenerator
回答2:
This is what ASP.NET documentation says about resources files.
It does not talk specifically about codebehind designer files generated on the fly but if you read the bolded text carefully, it is essentially saying that you need the base file without language specified and, given that, it makes sense that only this file will include autogenerated code.
"When you create resource files, you start by creating a base .resx file. For each language that you want to support, create a new file that has the same file name. But in the name, include the language or the language and culture (culture name). For a list of culture names, see the CultureInfo class. For example, you might create the following files:
•WebResources.resx
The base resource file. This is the default (fallback) resource file.
•WebResources.es.resx
A resource file for Spanish.
•WebResources.es-mx.resx
A resource file for Spanish (Mexico) specifically.
•WebResources.de.resx
A resource file for German."
I actually have never noticed this before but when I went to check my old projects, I saw they all have the base file and then language specific ones. So I just corrected it to follow that convention and it works now.
回答3:
If I were you, I would:
create a new resx file; open the old one; Press ctrl+a in the old one; Press ctrl+v in the new one; Save the new one; Delete the old one; Rename the new one :)
This should solve the problem quiet fast. You could also check if the cs files are not excluded from the file by clicking the show all button
回答4:
Sorry for using this to write a comment. My reputation actually is less than 50 =( but i think this might be important too.
This referes to Alvis' answer: Your solution did the trick. But i had also to modify the access modifier of properties in the base designer code file from internal to public. Otherwise i got XmlParseExceptions when trying to access the resx in xaml.
Edit: So this referes to C#/WPF. Could be different in ASP.NET
回答5:
I found the best way was to:
- Create the file as the default:
Resource1.resx
- Let it create the:
Resource1.Desinger.cs
- Rename it to what language you want, e.g.,
Localize.en.resx
Any other way for me just stopped creating the X.Designer.cs
files
来源:https://stackoverflow.com/questions/3343813/resource-resx-files-messed-up