我在 Visual Studio 中打开了一个项目(恰好是 Enyim.Caching)。该程序集需要延迟签名。事实上,它非常希望延迟签名,所以我无法强制 Visual Studio 编译它而不延迟签名。
我取消选中 Visual Studio 项目属性框中的“仅延迟签名”和“对程序集签名”,然后重新构建。该程序集仍标记为延迟标志(如
sn.exe -v
所示)。我已卸载项目并验证签名设置为 false。重新加载项目时,选中“签名”和“延迟签名”复选框。
我已验证 AssemblyInfo(或其他地方)中不存在会导致此问题的属性。
我已经在 Internet 上搜索了解决方案,但没有找到。
我该怎么做?
最佳答案
在这种情况下,问题是项目“公共(public)属性”引用。
项目 .csproj 文件的内部是这条无关紧要的小行:
<Import Project="..\build\CommonProperties.targets" />
不幸的是,文件 (CommonProperties.targets
) 指示 VS 重写属性,但它没有在用户界面中提供任何明确的指示表明这正在发生。
解决方案是进入 CommonProperties.targets
文件并删除以下行:
<!-- 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>
将这些行替换为以下内容:
<PropertyGroup>
<DelaySign>false</DelaySign>
<SignAssembly>false</SignAssembly>
</PropertyGroup>
关于c# - 从程序集中删除签名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15469534/