问题
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="
"$(DevEnvDir)..\..\VC\bin\editbin.exe" /STACK:16777216 "$(ProjectDir)obj\$(ConfigurationName)\$(TargetFileName)"
echo $(FrameworkSDKDir)bin\NETFX 4.5.1 Tools\
"$(FrameworkSDKDir)bin\NETFX 4.5.1 Tools\sn.exe" -Ra "$(ProjectDir)obj\$(ConfigurationName)\$(TargetFileName)" "$(SolutionDir)\STRONGNAME.snk"
" />
</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