vb.net 强签名程序集

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

Strong Signed Assemblies

vb.netcompiler-constructionpublishing

提问by Jason Shoulders

I have a project I made in Visual Basic 2008 Express. I converted it from someone else's C# project, but it works. It has several DLL dependencies. I went to publish my project so I can install it on another machine and for each DLL, I get an error: "Assembly must be strong signed in order to be marked as a prerequisite." I've done some research, but am not finding a lot and what I have found I don't really understand. What does this error mean? What is the best way to resolve it? One other thing: it took me a LONG time to be able to get all my dll's to reference correctly, so I prefer that the solution has NOTHING to do with moving DLL's around because that will likely break the functionality in my main project.

我有一个在 Visual Basic 2008 Express 中制作的项目。我从别人的 C# 项目中转换了它,但它有效。它有几个 DLL 依赖项。我去发布我的项目,以便我可以将它安装在另一台机器上,对于每个 DLL,我收到一个错误:“程序集必须经过强签名才能被标记为先决条件。” 我做了一些研究,但没有找到很多,我发现的东西我真的不明白。这个错误是什么意思?解决它的最佳方法是什么?另一件事:我花了很长时间才能正确引用我的所有 dll,所以我更喜欢该解决方案与移动 DLL 无关,因为这可能会破坏我的主项目中的功能。

回答by Adam Robinson

If you're publishing via ClickOnce, go to the publish page and click on "Application Files". From there you should see a list of your DLL's. Ensure that the ones that are giving you trouble have their Publish Status marked as "Include" rather than "Prerequisite".

如果您通过 ClickOnce 发布,请转到发布页面并单击“应用程序文件”。从那里你应该看到你的 DLL 的列表。确保给您带来麻烦的那些将其发布状态标记为“包含”而不是“先决条件”。

What this error message means is that the current publishing settings are going to expect all of the assemblies in question to be present in the Global Assembly Cache on the target machine before installation can take place. Since all assemblies in the GAC must be strong signed, any assembly marked as a prerequisite that isn't strong signed will give you this error.

此错误消息的意思是,当前发布设置将期望所有有问题的程序集都存在于目标计算机上的全局程序集缓存中,然后才能进行安装。由于 GAC 中的所有程序集都必须经过强签名,因此任何标记为非强签名的先决条件的程序集都会出现此错误。

回答by Agustin

The workaround is more simple than that:

解决方法比这更简单:

  1. Go to your project.
  2. Right click and Select Properties.
  3. Go to the Security Tab.
  4. Uncheck Enable ClickOnce security Settings.
  1. 转到您的项目。
  2. 右键单击并选择属性。
  3. 转到安全选项卡。
  4. 取消选中启用 ClickOnce 安全设置。

Unless you are deploying this application through ClickOnce, you don't need to StrongName your assemblies.

除非您通过 ClickOnce 部署此应用程序,否则您不需要对程序集进行 StrongName。

回答by JaredPar

Strongly named assemblies are mainly assemblies which have are signed by a cryptographic key. This is fairly easy to do with Visual Studio and does not require re-ordering of your dependencies.

强命名程序集主要是由加密密钥签名的程序集。这对于 Visual Studio 来说相当容易,并且不需要重新排序您的依赖项。

I'm using non-express Visual Studio so the steps may be slightly different for you.

我使用的是 non-express Visual Studio,所以步骤对你来说可能略有不同。

  • Right click on the project and select properties
  • Click on the Signing tab
  • Check "Sign the assembly"
  • In the combo box select "<New...>"
  • Complete the wizard
  • Rebuild
  • 右键单击项目并选择属性
  • 单击签名选项卡
  • 选中“签署程序集”
  • 在组合框中选择“<新建...>”
  • 完成向导
  • 重建

回答by Justin Niessner

Check this link out...it has instructions for signing your assembly with a strong name:

检查此链接...它具有使用强名称签署程序集的说明:

MSDN: Signing an Assembly with a Strong Name

MSDN:使用强名称签署程序集

回答by Binoj Antony

To create a strong name just go to the SDK Command Prompt or Visual Studio 200X Command Prompt then type in the following

要创建强名称,只需转到 SDK 命令提示符或 Visual Studio 200X 命令提示符,然后键入以下内容

sn -k sgKey.snk

Refer this link for details

详情请参阅此链接

Then associate the strong name to your assembly by running the below command

然后通过运行以下命令将强名称关联到您的程序集

al /out:MyAssembly.dll MyOldAssembly.dll /keyfile:sgKey.snk

Refer this link for details

详情请参阅此链接

回答by ptg

This just worked for me after the above mentioned solutions failed:

在上述解决方案失败后,这对我有用:

Remove the reference to the assembly in error, then add it again.

删除对错误程序集的引用,然后重新添加。

回答by Tony

I found my problem to be in the .csproj file

我发现我的问题出在 .csproj 文件中

<Reference Include="OtherProjectNothingToDo">
  <HintPath>..\..\..\..\Pedidos\XBAP\Pedidos\Pedidos\bin\Release\Pedidos.exe</HintPath>
</Reference>

Then I removed it using notepad and it is okay now.

然后我用记事本删除了它,现在可以了。

回答by mono código

Using Adam Robinson'ssolution allowed me to publish, but I found that users could not install the project once it was published, as the end user system would complain of an inability to install, noting hard drive space. As this seemed highly unlikely to be the root cause, I looked further into it.

使用Adam Robinson 的解决方案允许我发布,但我发现项目发布后用户无法安装,因为最终用户系统会抱怨无法安装,并注意到硬盘空间。由于这似乎不太可能是根本原因,因此我进一步研究了它。

Apparently the basis for my problem was that one of my references was also referencing a .dll that my project used, but a different version. ClickOnce was not having this, and refused to copy the second version of the .dll to the user's system, citing the version already present. Fixing it so the .dll and the project referenced the same version of the other .dll removed the error and corrected the install problem.

显然,我的问题的基础是我的一个引用也引用了我的项目使用的 .dll,但版本不同。ClickOnce 没有这个,并拒绝将 .dll 的第二个版本复制到用户的系统,引用版本已经存在。修复它以便 .dll 和项​​目引用其他 .dll 的相同版本删除了错误并更正了安装问题。

回答by user2854828

I just had this problem too. In my case the blabla.dll was referenced in my solution but blabla.dll was also used in another.dll which i had referenced in my project.

我也刚遇到这个问题。在我的情况下,blabla.dll 在我的解决方案中被引用,但 blabla.dll 也被用于我在我的项目中引用的 another.dll。

On checking the versions of both blabla.dll they were not the same. So i updated another.dll with the correct blabla.dll and then referenced the new another.dll in my solution. The error was gone.

在检查两个 blabla.dll 的版本时,它们并不相同。所以我用正确的 blabla.dll 更新了 another.dll,然后在我的解决方案中引用了新的 another.dll。错误消失了。

In short: i was using 2 versions of blabla.dll

简而言之:我使用了 blabla.dll 的 2 个版本

I hope this makes sense, if not let me know. :)

我希望这是有道理的,如果不是让我知道。:)

Check my blog for more detailed explanation: Blog article

查看我的博客以获得更详细的解释: 博客文章

Regards, Jacob Iedema

问候, 雅各布·伊德玛

回答by helper

Check that the Target Framework is actually set to 3.5 or whatever framework you want to target. Sometimes it will error out when it's not set properly.

检查 Target Framework 是否实际设置为 3.5 或您想要定位的任何框架。有时设置不正确会出错。