Remove signing from an assembly

∥☆過路亽.° 提交于 2019-12-18 16:12:10

问题


I have a project open in Visual Studio (it happens to be Enyim.Caching). This assembly wants to be delay-signed. In fact, it desires so strongly to be delay-signed, that I am unable to force Visual studio to compile it without delay signing.

  1. I have unchecked "Delay sign only" and "Sign the assembly" on the Visual Studio project properties box, and rebuilt. The assembly is still marked for delay sign (as shown by sn.exe -v).

  2. I have unloaded the project and verified that the signing is set to false. When reloading the project, the check boxes for "Sign" and "Delay Sign" are checked.

  3. I have verified that no attributes are present in the AssemblyInfo (or elsewhere) that would cause this.

  4. I have searched the Internet for a solution, but have found none.

How can I do this?


回答1:


In this case, the problem is a project "common properties" reference.

Inside of the project .csproj file is this innocuous little line:

<Import Project="..\build\CommonProperties.targets" />

Unfortunately, the file (CommonProperties.targets) instructs VS to re-write the properties, but it does not provide any clear indication in the user interface that this is taking place.

The solution is to go into the CommonProperties.targets file and delete the following lines:

<!-- delay sign the assembly if the PrivateKeyPath property is not specified -->
<PropertyGroup Condition=" '$(PrivateKeyPath)' == '' And '$(PrivateKeyName)' == ''">
    <AssemblyOriginatorKeyFile>..\public_key.snk</AssemblyOriginatorKeyFile>
    <DelaySign>true</DelaySign>
</PropertyGroup>

<!-- sign the assembly using the specified key file containing both the private and public keys -->
<PropertyGroup Condition=" '$(PrivateKeyPath)' != '' ">
    <AssemblyOriginatorKeyFile>$(PrivateKeyPath)</AssemblyOriginatorKeyFile>
    <DelaySign>false</DelaySign>
</PropertyGroup>

<!-- sign the assembly using the specified key container containing both the private and public keys -->
<PropertyGroup Condition=" '$(PrivateKeyName)' != '' ">
    <AssemblyOriginatorKeyFile></AssemblyOriginatorKeyFile>
    <DelaySign>false</DelaySign>
</PropertyGroup>

Replace those lines with the following:

  <PropertyGroup>
    <DelaySign>false</DelaySign>
    <SignAssembly>false</SignAssembly>
  </PropertyGroup>



回答2:


Met the same problem. Even after I disabled "Delay Sign only" and "Sign the assembly", I still got the error

error MSB3325: Cannot import the following key file: . The key file may be password protected".

And the .csproj is correct:

<PropertyGroup>
    <SignAssembly>false</SignAssembly>
    <DelaySign>false</DelaySign>
</PropertyGroup>

However, there's one more tricky line below:

<SignAssembly Condition="Exists('..\xxx.pfx')">true</SignAssembly>

Only after I removed the line in .csproj, or removed the file on the disk, then the VS is OK to go.

Seems like a bug of VS. The version I am using:

Microsoft Visual Studio 2010
Version 10.0.40219.1 SP1Rel
Microsoft .NET Framework
Version 4.5.50709 SP1Rel


来源:https://stackoverflow.com/questions/15469534/remove-signing-from-an-assembly

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