.net 程序集生成失败 - 引用的程序集没有强名称。为什么其他解决方案不起作用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9391452/
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-03 16:15:33  来源:igfitidea点击:

Assembly generation failed - Referenced assembly does not have a strong name. Why doesn't other solutions work?

.netvisual-studio-2010sharepointcode-signing

提问by Geir Smestad

This is a classic problem, which has numeroussolutions described. However, none of them seem to work for me.

这是一个经典问题,描述了许多解决方案。但是,它们似乎都不适合我。

I am using the Report.NET library in a SharePoint solution. Adding the Reports.dll as a reference and compiling results in the error message "Assembly generation failed - Referenced assembly 'Reports' does not have a strong name." My project, however, has a key.snk linked in the project properties. So I try to disassemble, sign and reassemble the dll with this key file, as described elsewhere:

我在 SharePoint 解决方案中使用 Report.NET 库。添加 Reports.dll 作为引用并编译会导致错误消息“程序集生成失败 - 引用的程序集‘报告’没有强名称。” 但是,我的项目在项目属性中链接了一个 key.snk。因此,我尝试使用此密钥文件反汇编、签名和重新组装 dll,如其他地方所述:

C:\Users\Administrator\Documents\Visual Studio 2010\Projects\MyProj
\dll>ildasm Reports.dll /out:Reports.il

C:\Users\Administrator\Documents\Visual Studio 2010\Projects\MyProj
\dll>ilasm Reports.il /dll /resource=Reports.res /key=..\key.snk

<output removed for brevity>

Class 95
Class 96
Method Implementations (total): 1
Resolving local member refs: 0 -> 0 defs, 0 refs, 0 unresolved
Writing PE file
Signing file with strong name
Operation completed successfully

I end up with a new Reports.dll timestamped to now. Adding this as a reference to my project and building, though, gives the same error message as before. The properties of the "Reports" reference displays "Strong Name: False".

我最终得到了一个新的 Reports.dll 时间戳到现在。但是,将此添加为对我的项目和构建的引用,会给出与以前相同的错误消息。“报告”引用的属性显示“强名称:假”。

Not to be discouraged by a bit of trouble, I attempt to re-sign the assembly using the strong naming utility:

不要因为一些麻烦而气馁,我尝试使用强命名实用程序重新签署程序集:

C:\Users\Administrator\Documents\Visual Studio 2010\Projects\MyProj
\dll>sn -R Reports.dll ..\key.snk

Microsoft (R) .NET Framework Strong Name Utility  Version 4.0.30319.1
Copyright (c) Microsoft Corporation.  All rights reserved.

Assembly 'Reports.dll' successfully re-signed

It might be worth noting that running the SN utility fails with the error message "Reports.dll does not represent a strongly named assembly" when running it beforethe disassemble/sign/reassemble process.

可能值得注意的是,在反汇编/签名/重新组装过程之前运行 SN 实用程序失败并显示错误消息“Reports.dll 不代表强命名程序集” 。

However, when running it after disassembly/signing/reassembly, I still get the original error message when re-adding it to Visual Studio.

但是,在反汇编/签名/重新组装后运行它时,将其重新添加到 Visual Studio 时,我仍然收到原始错误消息。

回答by Oleg Guchashvili

I just solved this problem in vs 2010 using this:

我刚刚在 vs 2010 中使用这个解决了这个问题:

Project Properties -> Signing -> uncheck Sign the assembly checkbox

回答by Andras Zoltan

I would suggest that if, after you have unambiguously signed the Reports.dll correctly from the command line, VS still says that that dll is unsigned; then it must be referencing the wrong file.

我建议,如果在您从命令行明确正确地签署了 Reports.dll 之后,VS 仍然说该 dll 是未签名的;那么它一定是引用了错误的文件。

If you want to be really paranoid and double-check the strong-naming after signing, load Reports.dll into ildasm (you have to double-click the manifest node in the tree and scroll down to find the .publickeysection). Or for ease just open it in ILSpy.

如果您真的想在签名后仔细检查强命名,请将 Reports.dll 加载到 ildasm(您必须双击树中的清单节点并向下滚动以找到该.publickey部分)。或者为方便起见,只需在ILSpy 中打开它。

After signing reports.dll; open your referencing project's proj file as an XML document (if you have the VS PowerCommands you can right-click and 'Edit Project File'; otherwise you can unload the project and then open it in VS using the 'Open With' command from the Open File dialog) and verify that the reference to the dll is indeed the correct path. If it's not, correct it and reload the project.

签署reports.dll后;将引用项目的项目文件作为 XML 文档打开(如果您有 VS PowerCommands,您可以右键单击并“编辑项目文件”;否则,您可以卸载项目,然后使用“打开方式”命令在 VS 中打开它)打开文件对话框)并验证对 dll 的引用确实是正确的路径。如果不是,请更正它并重新加载项目。