Strong name signing of merged assemblies.

The initial implementation was generating unsigned assemblies. ServiceWrapper/winsw.csproj has been reworked to sign merged all assemblies automatically.
The current implementation requires winsw_key.snk instead of the encrypted key with a password.

Signed-off-by: Oleg Nenashev <o.v.nenashev@gmail.com>
pull/74/head
Oleg Nenashev 2015-02-07 19:41:38 +03:00
parent fb8dd8a15f
commit 53ba5810a6
4 changed files with 45 additions and 9 deletions

1
.gitignore vendored
View File

@ -7,3 +7,4 @@ obj
*.user
/src/packages/NUnit.2.6.4
/src/packages/ILMerge.MSBuild.Tasks.1.0.0.3
/winsw_key.snk

View File

@ -1,4 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ILMerge" version="2.14.1208" targetFramework="net20" />
<package id="log4net" version="2.0.3" targetFramework="net20" />
<package id="MSBuildTasks" version="1.4.0.88" targetFramework="net20" />
</packages>

View File

@ -16,7 +16,7 @@
</StartupObject>
<SignManifests>false</SignManifests>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>..\..\..\winsw_cert.pfx</AssemblyOriginatorKeyFile>
<AssemblyOriginatorKeyFile>$(SolutionDir)..\winsw_key.snk</AssemblyOriginatorKeyFile>
<FileUpgradeFlags>
</FileUpgradeFlags>
<UpgradeBackupLocation>
@ -91,7 +91,10 @@
</ItemGroup>
<ItemGroup>
<None Include="..\..\..\winsw_cert.pfx" />
<None Include="packages.config" />
<None Include="packages.config">
<SubType>Designer</SubType>
</None>
<None Include="$(AssemblyOriginatorKeyFile)" />
</ItemGroup>
<ItemGroup>
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
@ -124,10 +127,6 @@
<Target Name="AfterBuild">
</Target>
-->
<PropertyGroup>
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
@ -135,8 +134,8 @@
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>
<!-- Merge plugins into winsw.exe -->
<UsingTask TaskName="ILMerge.MSBuild.Tasks.ILMerge" AssemblyFile="$(SolutionDir)\packages\ILMerge.MSBuild.Tasks.1.0.0.3\tools\ILMerge.MSBuild.Tasks.dll" />
<!-- Merge plugins and other DLLs into winsw.exe -->
<UsingTask TaskName="MSBuild.Community.Tasks.ILMerge" AssemblyFile="$(SolutionDir)\packages\MSBuildTasks.1.4.0.88\tools\MSBuild.Community.Tasks.dll" />
<Target Name="AfterBuild">
<ItemGroup>
<MergeAsm Include="$(OutputPath)$(TargetFileName)" />
@ -146,8 +145,35 @@
</ItemGroup>
<PropertyGroup>
<MergedAssembly>$(ProjectDir)$(OutDir)winsw.exe</MergedAssembly>
<CertificatePfxFile>$(AssemblyOriginatorKeyFile)</CertificatePfxFile>
</PropertyGroup>
<!-- Locate SN.EXE in Windows SDK, use the first found one-->
<PropertyGroup>
<SnPathTmpFile>$(OutputPath)sn-path.txt</SnPathTmpFile>
</PropertyGroup>
<GetFrameworkSdkPath>
<Output TaskParameter="Path" PropertyName="WindowsSdkPath" />
</GetFrameworkSdkPath>
<Message Text="Using SDK from $(WindowsSdkPath)" Importance="high" />
<Exec Command="WHERE /r &quot;$(WindowsSdkPath.TrimEnd('\\'))&quot; sn &gt; $(SnPathTmpFile)" />
<ReadLinesFromFile File="$(SnPathTmpFile)">
<Output TaskParameter="Lines" PropertyName="SNPath" />
</ReadLinesFromFile>
<Delete Files="$(SnPathTmpFile)" />
<PropertyGroup>
<SNPath>$([System.Text.RegularExpressions.Regex]::Replace('$(SNPath)', ';.*', ''))</SNPath>
</PropertyGroup>
<Error Condition="!Exists('$(SNPath)')" Text="Cannot find SN.EXE utility in $(WindowsSdkPath)" />
<Message Text="Using SN.EXE utility from $(SNPath)" Importance="high" />
<!-- Merge and re-sign assemblies -->
<PropertyGroup>
<ILMergePath>$(SolutionDir)packages\ilmerge.2.14.1208\tools</ILMergePath>
<CertificateTmpPubFile>$(OutputPath)winsw_cert.pub</CertificateTmpPubFile>
</PropertyGroup>
<Message Text="Extracting public key from $(AssemblyOriginatorKeyFile)" />
<Exec Command="&quot;$(SNPath)&quot; -p &quot;$(AssemblyOriginatorKeyFile)&quot; &quot;$(CertificateTmpPubFile)&quot;" />
<Message Text="ILMerge @(MergeAsm) -&gt; $(MergedAssembly)" Importance="high" />
<ILMerge InputAssemblies="@(MergeAsm)" OutputFile="$(MergedAssembly)" TargetKind="SameAsPrimaryAssembly" />
<ILMerge ToolPath="$(ILMergePath)" InputAssemblies="@(MergeAsm)" OutputFile="$(MergedAssembly)" TargetKind="SameAsPrimaryAssembly" KeyFile="$(CertificateTmpPubFile)" DelaySign="true" />
<Exec Command="&quot;$(SNPath)&quot; -R &quot;$(MergedAssembly)&quot; &quot;$(AssemblyOriginatorKeyFile)&quot;" />
</Target>
</Project>

View File

@ -22,6 +22,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{5297623A-1
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WinSWCore", "Core\WinSWCore\WinSWCore.csproj", "{9D0C63E2-B6FF-4A85-BD36-B3E5D7F27D06}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".build", ".build", "{D8806424-4640-440C-952D-37790B603C27}"
ProjectSection(SolutionItems) = preProject
Build.proj = Build.proj
.build\MSBuild.Community.Tasks.dll = .build\MSBuild.Community.Tasks.dll
.build\MSBuild.Community.Tasks.targets = .build\MSBuild.Community.Tasks.targets
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU