我有三个项目的以下文件夹结构:
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的项目属性 - &gt;预建,我有以下内容:
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”。这就像卫星组件根本没有得到解决。
答案 0 :(得分:0)
按照http://support.microsoft.com/kb/839861下提供的正确程序,应用程序正在按预期工作。
我所要做的就是更改&#34;预构建事件命令行&#34;如下:
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 ..
)
希望它有所帮助。