Remove signing from an assembly

自闭症网瘾萝莉.ら 提交于 2019-11-30 13:53:37
theMayer

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>

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