Automatically calling signature verification disabling as part of build for delay signed assemblies

I authored this neat but overkilled build target for Visual Studio 2012 to automatically disable signature verification on the output of projects as part of a build step:


<?xml version=”1.0″ encoding=”utf-8″?>
<Project xmlns=”“>
  <!– Turn off assembly signature verification when needed, so delay sign assemblies do not fail to load in dev unit test environment –>
  <Target Name=”PostBuildDisableSignatureVerification” AfterTargets=”AfterBuild”>
    <Message Text=”TRACE: Beginning PostBuildDisableSignatureVerification…” Condition=”‘$(EnableTracing)’ == ‘true'” Importance=”high” />

    <!– The tool we need to turn off signature verification is under the Microsoft SDK folder –>
          PropertyName=”SdkPath” />

    <!– We need to exclude the file types that cannot be signed –>
      <ExtensionsExcluded Include=”xml;xap;config;lastcodeanalysissucceeded;pdb;manifest;UnitTest.dll” />

    <!– Because the property is scalar (i.e. represents multiple values) we need to do batching and transformation to exclude given values –>
    <CreateItem  Include=”$(TargetDir)**\$(TargetName).*”
      <Output TaskParameter=”Include” ItemName=”CandidatesToSign”/>
    <Message Text=”CandidatesToSign: @(CandidatesToSign)” Condition=”‘$(EnableTracing)’ == ‘true'” Importance=”high” />

    <!– We need to run the tool twice, once for x86 and once for x64 –>
    <Exec Command=”&quot;$(SdkPath)bin\NETFX 4.0 Tools\x64\sn.exe&quot; -Vr %(CandidatesToSign.Identity)” />
    <Exec Command=”&quot;$(SdkPath)bin\NETFX 4.0 Tools\sn.exe&quot; -Vr %(CandidatesToSign.Identity)” />
    <Message Text=”INFO: Signature verification disabled for assemblies of project ‘$(MSBuildProjectFile)’.” Importance=”high” />



This can actually be simplified by passing the public part of the signature key as *,<public key> to designate all assemblies signed with this public key. It is then no longer necessary to build the candidates to sign or the extensions to exclude. Also the target needs then only to be executed once per solution instead of once for each project of the solution.

Comments (0)

Skip to main content