how to resolve “error MSB3188: Assembly … must be strong signed in order to be marked as a prerequisite.”

廉价感情. 提交于 2020-01-16 08:35:33

问题


I've seen several questions on this board which are similar, but I think several problems can cause this message, and my particular problem may not have been among them, and certainly my solution appears much simpler and more effective than any of the others.

I have a project which was using packages.config.

I used the Visual Studio UI to migrate by projects references from package.config to PackageReference (https://devblogs.microsoft.com/nuget/migrate-packages-config-to-package-reference/). I did this because it allows building with msbuild /t:restore mysln.sln - which doesn't work with packages.config.

I think this GENERALLY works (I tried 5 or 6 times on other projects). But on one project when I rebuilt, I got the error message:

c:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VisualStudio\v16.0\OfficeTools\Microsoft.VisualStudio.Tools.Office.targets(236,9): error MSB3188: Assembly 'C:\Users\lew
is\.nuget\packages\mousekeyhook\5.6.0\lib\net40\Gma.System.MouseKeyHook.dll' must be strong signed in order to be marked as a prerequisite.

回答1:


My solution to this problem:

  • Squirrel away the Gma.System.MouseKeyHook.dll from the packages folder
  • Delete the reference to Gma.System.MouseKeyHook.dll from nuget
  • Add a folder called 'ThirdPartyComponents' and put Gma.System.MouseKeyHook.dll in there.
  • Create a REFERENCE (not PackageReference) using the 'Add Reference' command in Visual studio

DONE - error gone.

.CSPROJ DIFF FOR FIX:
index f0abf00..f87ab3e 100644
--- a/X.csproj
+++ b/X.csproj
@@ -123,6 +123,9 @@
   -->
   <ItemGroup>
     <Reference Include="Accessibility" />
+    <Reference Include="Gma.System.MouseKeyHook">
+      <HintPath>..\ThirdPartyComponents\Gma.System.MouseKeyHook.dll</HintPath>
+    </Reference>
     <Reference Include="Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
       <EmbedInteropTypes>True</EmbedInteropTypes>
     </Reference>
@@ -632,9 +635,6 @@
     <PackageReference Include="log4net">
       <Version>2.0.8</Version>
     </PackageReference>
-    <PackageReference Include="MouseKeyHook">
-      <Version>5.6.0</Version>
-    </PackageReference>
     <PackageReference Include="Newtonsoft.Json">
       <Version>12.0.3</Version>
     </PackageReference>

Apparently having a requires the signing stuff, but having a regular does not.




回答2:


The error message about demanded signed assemblies is usually shown in the following combinations:

  • The project can be published (such as a VSTO project).
  • The project uses PackageReferences for NuGet.
  • A referenced NuGet package is a netstandard2.0 package.

You could easily reproduce this by creating a new VSTO Word Add-In and reference NGenerics Version 1.5.3 via NuGet.

(Another reason could be version conflicts of the referenced assembly, say you reference assemblies A and B via NuGet, and A itself references a different version of B; then you would have to reference the same version of B as A does.)

With the help of a Microsoft Service call we found out that in such a scenario, the referenced assembly (in our case NGenerics v. 1.5.3) is marked as CopyLocal=false internally by the build process. If you use packages.config instead of PackageReferences for NuGet and mark the referenced assembly as CopyLocal=false in the Properties window, then you get the same compile error.

Solution: When using packages.config, set the assembly reference property of the affected assembly to CopyLocal=true. When using PackageReferences, edit the project file manually and add an assets option as in the following example:

    <PackageReference Include="NGenerics">
      <Version>1.5.3</Version>
      <ExcludeAssets>compile</ExcludeAssets>
    </PackageReference>

The name of the ExcludeAssets and IncludeAssets setting is misleading. ExcludeAssets is copying the mentioned items to the output, while IncludeAssets keeps them from going to the output directory. You could as well say <IncludeAssets>none</IncludeAssets>. See documentation at https://docs.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files



来源:https://stackoverflow.com/questions/58980683/how-to-resolve-error-msb3188-assembly-must-be-strong-signed-in-order-to-be

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!