我有以下三个项目的文件夹结构:
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
在 MyClassLibrary1 项目下:
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 的项目属性-> Pre-Build,我有以下内容:
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 ..
)
在 MyAppExe 项目下的 Program.cs 中:
static void Main() {
Strings.Culture = new CultureInfo("en-GB");
Trace.WriteLine(Strings.SchoolString);
}
问题是,由于某种原因,ResourceManager 不断回退到默认资源文件(嵌入在 MyAppExe 中)。请帮助我理解我在这里做错了什么。
无论我尝试什么,我都会得到的输出是“Preschool”而不是“Playgroup”。就好像卫星组件根本没有得到解决。