vb.net 第三方 DLL 没有“强名称”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15459816/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 12:50:16  来源:igfitidea点击:

Third party DLL does not have 'strong name'?

c#.netvb.netvisual-studio-2010assembly-signing

提问by CJ7

My Visual Studio 2010solution references a third party proprietary DLL.

我的Visual Studio 2010解决方案引用了第三方专有 DLL。

When I try to compile the solution the error message reads:

当我尝试编译解决方案时,错误消息如下:

Unable to emit assembly: Referenced assembly 'NameOfAssembly.DLL' does not have a strong name

无法发出程序集:引用的程序集“NameOfAssembly.DLL”没有强名称

Is the only solution to this issue to sign the third party DLL with my own key?

使用我自己的密钥签署第三方 DLL 是解决此问题的唯一方法吗?

回答by Hans Passant

That's criminal negligence by anybody that creates assemblies used by others, given how trivial it is to give an assembly a strong name while building it. Doing it afterwards is quite painful, you have to decompile the assembly with ildasm.exe and put it back together with ilasm.exe, now using the /key option.

考虑到在构建程序集时为其赋予强名称是多么微不足道,任何创建其他人使用的程序集的人都属于刑事疏忽。之后做这件事很痛苦,你必须用 ildasm.exe 反编译程序集,然后用 ilasm.exe 把它放回去,现在使用 /key 选项。

If you have a working relationship with the owner then send them a nastygram. If you don't then you probably should question the quality of the assembly, this is a major oversight and shows evidence that few people actually use the assembly.

如果您与所有者有工作关系,请向他们发送 nastygram。如果您不这样做,那么您可能应该质疑程序集的质量,这是一个重大疏忽,并表明很少有人真正使用该程序集。

回答by user2205317

Make sure you are licensed to reverse-engineer assemblies to as a strong name. I do not want you to have any legal troubles. You can strong name the assembly using the ILDASM and ILASM commands. In a Visual Studio command prompt.

确保您已获得将程序集反向工程为强名称的许可。我不希望你有任何法律问题。您可以使用 ILDASM 和 ILASM 命令强命名程序集。在 Visual Studio 命令提示符中。

Use the ILDASM to convert the assembly into MISL code. ILDASM MyThirdParty.dll /out:MyThirdParty.il

使用 ILDASM 将程序集转换为 MISL 代码。ILDASM MyThirdParty.dll /out:MyThirdParty.il

Use ILASM to compile with a strongname key. ILASM MyThirdParty.il /dll /resource=MyThirdParty.res /key=MyKey.snk

使用 ILASM 使用强名称键进行编译。ILASM MyThirdParty.il /dll /resource=MyThirdParty.res /key=MyKey.snk

If you need to make a strong name key use the SN command. I think its the -k option. If you get a BadImage exception then you check what CLR version the assembly was compiled in. If its a CLR 2.0/3.5 then use "C:\Windows\Microsoft.NET\Framework\v2.0.50727\ILASM" instead of the 4.0 version.

如果您需要制作强名称密钥,请使用 SN 命令。我认为它的 -k 选项。如果出现 BadImage 异常,则检查程序集编译的 CLR 版本。如果是 CLR 2.0/3.5,则使用“C:\Windows\Microsoft.NET\Framework\v2.0.50727\ILASM”而不是 4.0 版本.

回答by Laurent Etiemble

If you want strong-signed assemblies, all the references must be strong-signed. This entrydescribes the steps.

如果您需要强签名程序集,则所有引用都必须是强签名的。此条描述了这些步骤。