正在构建仅使用资源的DLL(使用al.exe)“程序集是由比当前加载的运行时新的运行时构建的". [英] Building Resource-Only DLL (With al.exe) Is Raising "assembly is built by a runtime newer than the currently loaded runtime"

查看:127
本文介绍了正在构建仅使用资源的DLL(使用al.exe)“程序集是由比当前加载的运行时新的运行时构建的".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在包装资源;并且我已成功使用ResourceManager.CreateFileBasedResourceManager从.resource文件加载它们.我想改为使用资源创建dll文件,并使用Assembly.LoadFrom加载这些文件;然后使用新的ResourceManager(string,Assembly)加载资源.当我这样做时,我会得到:

I am packaging resources; and I am successfully loading them from .resource files using ResourceManager.CreateFileBasedResourceManager. I want to instead create dll files with the resources, and load those with Assembly.LoadFrom; and then load the resources with new ResourceManager(string, Assembly). When I do this, I am getting:

程序集是由比当前加载的运行时新的运行时构建的."

该项目是一个类库;并在主机"(如插件")内部分发和运行.主机正在运行.Net 3.5.我的VS项目配置为以3.5为目标...实际上,我实际上是在手动运行al.exe来构建DLL.

The project is a class library; and it is distributed and run inside of a "host" like a "plugin". The host is running .Net 3.5. My VS project is configured to target 3.5 ... and I am actually running al.exe manually to build the DLL.

我可以在项目中运行一个测试程序(也设置为目标3.5),并且我的代码将加载程序集(并查找资源).但是当相同的代码在主机"中运行时,我得到了错误.

I can run a test Program in my project (also set to target 3.5) and my code will load the Assembly (and find resources). But when the same code runs in the "host", I get the error.

我已经尝试了在机器上可以找到的每个版本的al.exe;我专门下载了.NET 3.5 SDK;该文件似乎已安装到C:\ Program Files \ Microsoft SDKs \ Windows \ v7.0,但无论我运行的是哪个版本的al.exe,我总是会收到错误消息.

I have tried every version of al.exe that I can find on my machine; and I specifically downloaded the .NET 3.5 SDK; which seemed to install into C:\Program Files\Microsoft SDKs\Windows\v7.0 but I always get the error no matter which version of al.exe I run.

有人可以帮助我构建dll,以便将其加载到此.NET 3.5环境中吗? ---再次,它是仅资源的DLL.这些是构建后命令:

Can someone help me build the dll so that it will load inside of this .NET 3.5 environment? --- Again it's a resource-only DLL. These are the post-build commands:

ResGen.exe AdResources.resx AdResources.resources
al.exe /target:lib /embed:AdResources.resources /culture:en /out:AdResources.resources.dll

我用于加载程序集和资源的.cs代码如下:

The .cs code I use to load the Assembly and resources is like this:

string path = Path.Combine(InstallDir, "AdResources.resources.dll");
Assembly resAssembly = Assembly.LoadFrom(path);
ResourceManager temp = new ResourceManager("AdResources", resAssembly);

...在IDE(目标3.5)中运行时有效,但在最终主机平台中失败.

... Works when run in the IDE (targeting 3.5) but fails in the end host platform.

推荐答案

我已经解决了这个问题.

I have solved this.

尽管有Hans的评论,但我还是通过使用IDE(Community 2015 RC)解决了这个问题.

Despite Hans' comments, I solved it by USING the IDE (Community 2015 RC).

我创建了一个新的类库项目.将目标设置为.NET 3.5 ---并确保App.config表示相同的内容.然后,将我的.resx文件(仅)从我的主项目复制到该项目中.我删除了自定义工具(生成强名称). IDE构建的输出将在我的主机环境中正常加载!

I created a new class library project. Set the target to .NET 3.5 --- and made sure the App.config said the same thing. Then I copy my .resx files (only) from my main project into this project. I removed the custom tool (that generates the strong names). And the output that the IDE builds will load just fine in my host environment!

因此,即使我直接使用3.5或2.0工具,我也可以使用IDE但不能使用工具,这很奇怪.并确认输出清单确实显示"//元数据版本:v2.0.50727"!

So, very odd that I can use the IDE but not the tools, even when I use the 3.5 or 2.0 tools directly; and verify that the output manifest does say "// Metadata version: v2.0.50727"!

我创建了一个Pre-Build脚本来从主项目中复制我的resx文件;以及将该库复制到我的目标输出文件夹中的构建后脚本.工作正常...

I created a Pre-Build script to copy my resx files from the main project; and a Post-Build script to copy this library into my target output folder. Working fine ...

这篇关于正在构建仅使用资源的DLL(使用al.exe)“程序集是由比当前加载的运行时新的运行时构建的".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆