问题描述
我想让我的程序多语言。我已经通过Form的本地化和语言属性成功地使程序成为多语言。它制作了一些.resx文件。然后我从.resx文件中删除了非需要的文件,例如图像(它们在所有langauges中都是一样的)等。问题是,例如还会生成一个名为en的文件夹,在该文件夹中,另一个生成的文件称为ProjectName.resources.dll。
有没有将此资源文件嵌入到的.exe?将其添加到资源并将Build Action设置为嵌入式资源也不起作用。
感谢。
在.NET Framework 4中,您可以将资源库嵌入到可执行文件中。
只需创建相同的结构(使用本地化文件夹'lib / en','lib / de')并嵌入它们。
private static Assembly MyResolveEventHandler(object sender,ResolveEventArgs args){
AssemblyName MissingAssembly = new AssemblyName(args.Name);
CultureInfo ci = MissingAssembly.CultureInfo;
...
resourceName =MyApp.lib。 + ci.Name.Replace( - ,_)+。 + MissingAssembly.Name +.dll;
var stream = Assembly.GetExecutingAssembly()。GetManifestResourceStream(resourceName)
...
}
I want to make my program multilingual. I have successfully made the program multilingual via Form's Localizable and Language properties. It made some .resx files. Then I deleted non-needed files such as images (which they are the same in all langauges) etc from the .resx files.
The problem is, for example, it also generates a folder called "en" and in that folder, another generated file is called "ProjectName.resources.dll".
Is there anyway to embed this resource file to the .exe? Adding it to the resources and setting Build Action to "Embedded Resource" doesn't work also.
Thanks.
In .NET Framework 4 you can embed resource library into executable.
http://msdn.microsoft.com/en-us/library/system.appdomain.assemblyresolve.aspx
Just create same structure ( with localized folders 'lib/en', 'lib/de' ) and embed them.
private static Assembly MyResolveEventHandler(object sender, ResolveEventArgs args) {
AssemblyName MissingAssembly = new AssemblyName(args.Name);
CultureInfo ci = MissingAssembly.CultureInfo;
...
resourceName = "MyApp.lib." + ci.Name.Replace("-","_") + "." + MissingAssembly.Name + ".dll";
var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName)
...
}
这篇关于将本地化资源.DLL嵌入C#中的可执行文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!