Is an assembly signed with a strong name before or after the post-build event?

偶尔善良 提交于 2019-12-08 12:42:16

问题


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?

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)..\..\VC\bin\editbin.exe" /STACK:16777216 "$(TargetPath)"

And my project .csproj file contains the following lines:

<PropertyGroup>

  <SignAssembly>true</SignAssembly>
  <AssemblyOriginatorKeyFile>..\STRONGNAME.snk</AssemblyOriginatorKeyFile>

</PropertyGroup>

<PropertyGroup>
  <PostBuildEvent>"$(DevEnvDir)..\..\VC\bin\editbin.exe" /STACK:16777216 "$(TargetPath)"</PostBuildEvent>
</PropertyGroup>

回答1:


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 will return Failed to verify assembly -- Strong name validation failed ...

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.

The Project file should look like that:

  <Target Name="AfterCompile">
    <Exec Command="
&quot;$(DevEnvDir)..\..\VC\bin\editbin.exe&quot; /STACK:16777216 &quot;$(ProjectDir)obj\$(ConfigurationName)\$(TargetFileName)&quot;
echo $(FrameworkSDKDir)bin\NETFX 4.5.1 Tools\
&quot;$(FrameworkSDKDir)bin\NETFX 4.5.1 Tools\sn.exe&quot; -Ra &quot;$(ProjectDir)obj\$(ConfigurationName)\$(TargetFileName)&quot; &quot;$(SolutionDir)\STRONGNAME.snk&quot;
" />
  </Target>
  <PropertyGroup>
    <PostBuildEvent>REM "See AfterCompile for stack size and resigning"</PostBuildEvent>
  </PropertyGroup>


来源:https://stackoverflow.com/questions/56557646/is-an-assembly-signed-with-a-strong-name-before-or-after-the-post-build-event

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