我在Visual Studio 2005项目中添加了一个弱命名的程序集(它是强命名的)。我现在得到的错误:

"引用程序集'xxxxxxxx'没有强名称"

我需要签署这个第三方程序集吗?


当前回答

我添加了NuGet包“StrongNamer”,我的问题解决了。

其他回答

展开使用“没有强名称键”的项目的项目文件,寻找.snk文件(. strongnamekey)。

在Windows资源管理器中浏览这个文件(这样你就知道它在哪里了)。

回到Visual Studio中那个没有“强名称键”的项目,做

右键单击项目文件 选择属性 选择“签名选项卡”(在左侧) 单击“签署程序集”复选框 然后<Browse>到前面找到的.snk文件

这样应该可以了。这为我解决了一个问题,在同一个解决方案中,在另一个项目中使用一个表单。

我希望这能有所帮助。

如何对未签名的第三方程序集进行签名

Open up Developer Command Prompt for Visual Studio. This tool is available in your Window programs and can be found using the default Windows search. Ensure your prompt has access to the following tools by executing them once: sn ildasm and ilasm Navigate to the folder where your Cool.Library.dll is located sn –k Cool.Library.snk to create a new key pair ildasm Cool.Library.dll /out:Cool.Library.il to disassemble the library move Cool.Library.dll Cool.Library.unsigned.dll to keep the original library as a back-up ilasm Cool.Library.il /dll /resource=Cool.Library.res /key=Cool.Library.snk to reassemble the library with a strong name powershell -command "& {[System.Reflection.AssemblyName]::GetAssemblyName($args).FullName} Cool.Library.dll" to get the assembly fully qualified name. You will need this bit if you have to reference the DLL in external configuration files like web.config or app.config.

对我来说,问题在于没有强名称的NuGet包。解决方案是从NuGet安装StrongNamer,它会自动向所有引用的程序集添加强名称。只是简单地在项目中引用它修正了我的问题。

ilmerge使用。ilmerge来自微软,但它没有随Visual Studio或sdk一起发布。不过你可以从这里下载。还有一个GitHub存储库。你也可以从NuGet安装:

PM> Install-Package ilmerge

使用方法:

ilmerge assembly.dll /keyfile:key.snk /out:assembly.dll /targetplatform:v4,C:\Windows\Microsoft.NET\Framework\v4.0.30319 /ndebug

如果需要,你可以使用sn(从Visual Studio)生成你自己的密钥文件:

sn -k key.snk

为第三方程序集签名对我来说很有效:

引用程序集没有强名称

我了解到,如果链接的文章不再有效,发布步骤是很有帮助的。所有功劳归于Hiren Khirsaria:

运行Visual Studio命令提示符并转到DLL所在的目录。 例如,我的DLL位于D:/hiren/Test.dll 现在使用下面的命令创建CIL文件。 D:/hiren> ildasm /all /out=Test。il Test.dll(此命令生成代码库) 生成一个新密钥来对项目进行签名。 D:/hiren> sn -k mykey.snk 现在使用ilasm命令对库进行签名。 D:/hiren> ilasm /dll /key=mykey。snk Test.il