将本地化资源.DLL嵌入C#中的可执行文件? [英] Embedding Localization Resources .DLL's to the Executable in C#?
问题描述
问题是,例如还会生成一个名为en的文件夹,在该文件夹中,另一个生成的文件称为ProjectName.resources.dll。
有没有将此资源文件嵌入到的.exe?将其添加到资源并将Build Action设置为嵌入式资源也不起作用。
感谢。
在.NET Framework 4中,您可以将资源库嵌入到可执行文件中。
http://msdn.microsoft.com/en-us/library/system.appdomain.assemblyresolve.aspx
只需创建相同的结构(使用本地化文件夹'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#中的可执行文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!