0

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>
David Wohlferd
  • 7,110
  • 2
  • 29
  • 56
Wollmich
  • 1,616
  • 1
  • 18
  • 46

1 Answers1

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>
Wollmich
  • 1,616
  • 1
  • 18
  • 46
  • If you enable MSBuild logging and take a look at the generated log entries, you should notice that the key file is used by the C# compiler. So of course, the strong name was generated before post build event. – Lex Li Jun 12 '19 at 12:49