I've the following folder structure for three projects:
MyClassLibrary1
Class1.cs
Resources\
en-GB\
Strings.en-GB.txt
Strings.resx
Strings.designer.cs (auto-generated)
MyClassLibrary2 (references MyClassLibrary1)
Class1.cs
MyAppExe (references MyClassLibrary1 and MyClassLibrary2)
Program.cs
Under MyClassLibrary1 project:
In Strings.resx, I've string resources defined, let's say:
<data name="SchoolString"><value>Preschool</value></data>
In Strings.en-GB.txt, I have:
SchoolString=Playgroup
MyClassLibrary1's Project properties -> Pre-Build, I've the following:
CD $(ProjectDir)Resources
FOR /D %%1 IN (*) DO (
CD "%%1"
resgen.exe "Strings.%%1.txt"
if %errorlevel% 0 al.exe /t:lib /culture:"%%1" /embed:"Strings.%%1.resources" /out:MyClassLibrary1.resources.dll
if not exist "$(TargetDir)%%1" md "$(TargetDir)%%1"
move /Y "MyClassLibrary1.resources.dll" "$(TargetDir)%%1"
CD ..
)
Under MyAppExe project, in Program.cs:
static void Main() {
Strings.Culture = new CultureInfo("en-GB");
Trace.WriteLine(Strings.SchoolString);
}
The problem is that the ResourceManager, for some reason, keeps on falling back to the default resource file (embedded in MyAppExe). Please help me understand what I am doing wrong here.
The output I keep getting no matter what I try is "Preschool" instead of "Playgroup". It's like the satellite assembly is not being resolved at all.
Following the correct procedure provided under http://support.microsoft.com/kb/839861, the application is working as expected now.
All I had to do was to change the "Pre-build event command line" as follows:
CD "$(ProjectDir)Resources"
FOR /D %%1 IN (*) DO (
CD "%%1"
resgen.exe "Strings.%%1.txt" "MyClassLibrary1.Resources.Strings.%%1.resources"
if %errorlevel% == 0 (
al.exe /t:lib /embed:"MyClassLibrary1.Resources.Strings.%%1.resources" /culture:"%%1" /out:MyClassLibrary1.resources.dll
if not exist "$(TargetDir)%%1" md "$(TargetDir)%%1"
move /Y "MyClassLibrary1.resources.dll" "$(TargetDir)%%1"
)
CD ..
)
Hope it helps someone.