Search code examples
msbuildwixwix3.5strongnamemsbuild-4.0

How to add prebuild activity in MSbuild to verify signing process?


We are using Msbuild to build our Wix projects. Due to various issues , few times assemblies specified in wix were just delay signed. When it was installed in GAC it failed.

Is there any way to verify strong name signing verification as prebuild activity in wix?

I am using sn -vf "assembly" to do strong name verification.

I want to do strong name verification only for dlls which will be packed inside wix msi( in other words, assemblies specified in wxs file)

How to do it msbuild?


Solution

    • A quick solution is adding a BeforeBuild event that calls sn.exe:

    Open your .wixproj file and add:

    <Target Name="BeforeBuild">
    <ItemGroup>
        <AssemblyToSign Include="C:\SignedAssembly1.dll"/>
        <AssemblyToSign Include="C:\SignedAssembly2.dll"/>      
    </ItemGroup>
         <Exec Command="sn -q -vf %(AssemblyToSign.Identity)" />
    </Target>
    

    This will fail your build once an assembly fails verification.


    • Another solution is use MSBuild Extension Pack's Signing class:

    Once again, this will fail your build on failed verification:

    <Target Name="BeforeBuild">
    <ItemGroup>
            <AssemblyToSign Include="C:\SignedAssembly1.dll"/>
            <AssemblyToSign Include="C:\SignedAssembly2.dll"/>      
    </ItemGroup>
     <MSBuild.ExtensionPack.Framework.Signing 
             TaskAction="Sign" 
             ToolPath="C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin" 
             KeyFile="D:\key.snk" 
             Assemblies="@(AssemblyToSign)" />
    </Target>
    

    In order to use it you must add a reference to the Extension Pack assembly:

    <PropertyGroup>
        <ExtensionTasksPath Condition="Exists('$(MSBuildProjectDirectory)\..\..\Common')">$(MSBuildProjectDirectory)\..\..\Common</ExtensionTasksPath>
    </PropertyGroup>
    <UsingTask AssemblyFile="$(ExtensionTasksPath)\MSBuild.ExtensionPack.dll" TaskName="MSBuild.ExtensionPack.Framework.Signing"/>