我有一个网络服务,它为我提供生成的 .resx(仅限 XML),然后我将其转换为二进制 .resources 文件。我目前正在使用 al.exe 生成一个程序集文件。这是我的论点:
/t:lib /c:{culture} /embed:"{.resource input}" /out:"{.dll output}"
通过 Assembly.LoadFrom(file) 加载这个程序集工作正常,但我相信我的程序集没有正确生成。它没有类型、命名空间或可调用的方法,因此显然没有 ResourceManager。
本质上,我只是想知道是否有可能生成、加载和利用没有我的项目在编译时知道的类或命名空间的资源。谢谢。
请您参考如下方法:
您的程序集是一个卫星程序集。来自 MSDN :
By definition, satellite assemblies can only contain resources. They cannot contain any executable code.
如果你想访问这个程序集的资源——类似的代码应该可以工作:
ResourceManager rm = new ResourceManager(
"ResourceTest.Properties.Resources",
Assembly.LoadAssembly(file));
MessageBox.Show(rm.GetString("helloWorldString"));
此外,来自 MSDN 的文章:Walkthrough: Loading Resources from a Satellite Assembly显示了如何从附属程序集加载资源字符串的另一种方法。
