[英]Combining C++/CLI, x86, x64 and strong naming
Let me get right to the point: 让我说清楚一点:
Main application: 主要应用:
C# (4.0), AnyCPU. C#(4.0),任何CPU。
Library: 图书馆:
Wrapper for native .dll written in C++/CLI. 用C ++ / CLI编写的本机.dll的包装。 Compiled in two versions; 编译有两个版本; x86 and x64, both signed with the same .snk key (using this workaround) x86和x64,都使用相同的.snk密钥签名(使用此替代方法)
Limitations: 局限性:
In the end a single distribution package is required for x86 and x64 platforms. 最后,x86和x64平台需要一个分发包。 Main application needs strong name due to references to other strongly named libs. 主应用程序需要强名称,因为要引用其他强命名的库。 Rewriting the library using managed C# and P/Invoke is an absolute last way out. 使用托管C#和P / Invoke重写库绝对是最后的出路。
The problem: 问题:
As long as the main application, at compile time, references the version (x86 or x64) of the library that is needed when run, this is all working fine. 只要主应用程序在编译时引用运行时所需的库版本(x86或x64),就可以正常工作。
Moving the same compiled output - and exchanging the library with the right platform version during installation - does not work since the signature of the library changes from that of the referenced one. 移动相同的编译输出-并在安装期间将库与正确的平台版本交换-不起作用,因为库的签名与引用的库的签名有所不同。
In a test application without any strong naming I can switch between them as needed. 在没有任何强大命名的测试应用程序中,我可以根据需要在它们之间切换。
The question: 问题:
Is there a way to enable switching between the x86 and x64 libraries within the set limitations, or is strong naming preventing any possible solution other than rewriting the lib? 有没有一种方法可以在设置的限制范围内在x86库和x64库之间进行切换,还是强命名功能会阻止除了重写lib之外的任何可能的解决方案?
Let me clarify that it is not a question about finding the correct .dll (as discussed here ) but about being able to load the .dll once found. 让我澄清一下,这不是一个找到正确的.dll文件(如讨论的问题在这里 ),但对能够装载一旦发现该.dll。
@Damien_The_Unbeliever's comment got me thinking and he is right in that the strong names are the same, and it was not the actual issue. @Damien_The_Unbeliever的评论让我思考,他是对的,因为强者名字相同,但这不是实际的问题。
I found another difference between the two versions of the library; 我发现库的两个版本之间还有另一个区别。 the output name was set to nnn.dll
and nnnx64.dll
. 输出名称设置为nnn.dll
和nnnx64.dll
。 Changing it so that both have the same output name magically made it all work. 对其进行更改,以使它们都具有相同的输出名称,即可神奇地完成所有工作。
Perhaps someone knows why such a setting matters, I certainly don't. 也许有人知道为什么这样的设置很重要,我当然不知道。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.