在构建后事件之前还是之后,程序集是否使用强名称签名? [英] Is an assembly signed with a strong name before or after the post-build event?
问题描述
我正在使用 editbin
修改程序集的堆栈大小,请参阅 增加主程序的堆栈大小或者为递归代码块创建一个具有更大堆栈大小的新线程?
I'm modifying the stack size of an assembly using editbin
, see Increase stack size of main program or create a new thread with larger stack size for recursive code blocks?
现在我问自己:在构建后事件之前还是之后,程序集是否使用强名称签名?因为 editbin
正在构建后事件中更改程序集.
Now I'm asking myself: Is an assembly signed with a strong name before or after the post-build event? Because editbin
is changing the assembly in the post-build event.
我的帖子构建事件看起来像这样:
My post build-event looks like that:
"$(DevEnvDir)....VCineditbin.exe" /STACK:16777216 "$(TargetPath)"
我的项目 .csproj
文件包含以下几行:
And my project .csproj
file contains the following lines:
<PropertyGroup>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..STRONGNAME.snk</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup>
<PostBuildEvent>"$(DevEnvDir)....VCineditbin.exe" /STACK:16777216 "$(TargetPath)"</PostBuildEvent>
</PropertyGroup>
推荐答案
在构建后事件之前使用强名称对程序集进行签名.这意味着 editbin
将更改该程序集并且签名不再有效.
An assembly is signed with a strong name before the post-build event. That means editbin
will change that assembly and the signature is not valid anymore.
sn.exe -v assembly.exe
将返回 Failed to verify assembly -- Strong name validation failed ...
获得使用 editbin
修改的有效签名程序集的解决方法是使用 AfterCompile
事件并使用 sn
重新签名程序集.
A workaround to get a valid signed assembly which was modified using editbin
is to use the AfterCompile
event and to resign the assembly using sn
.
项目文件应如下所示:
<Target Name="AfterCompile">
<Exec Command="
"$(DevEnvDir)....VCineditbin.exe" /STACK:16777216 "$(ProjectDir)obj$(ConfigurationName)$(TargetFileName)"
echo $(FrameworkSDKDir)binNETFX 4.5.1 Tools
"$(FrameworkSDKDir)binNETFX 4.5.1 Toolssn.exe" -Ra "$(ProjectDir)obj$(ConfigurationName)$(TargetFileName)" "$(SolutionDir)STRONGNAME.snk"
" />
</Target>
<PropertyGroup>
<PostBuildEvent>REM "See AfterCompile for stack size and resigning"</PostBuildEvent>
</PropertyGroup>
这篇关于在构建后事件之前还是之后,程序集是否使用强名称签名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!