-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Stripping annotations also strips the signature away from strong-named assemblies #2
Comments
@tankbob sorry for not replying sooner. You're right, this needs to be solved. Any idea about it is welcome. I confess I'm learning about strong-named assemblies in these last weeks - I had been avoiding the topic entirely for years, shame on me. These days I'm trying to speed up the release of Buildvana SDK, which, among other things, will automate assembly signing with separate keys for local and CI builds. This issue is clearly a show-stopper for it too. The good news is I'm soon going to be on it. Again, any help or suggestion is greatly appreciated! |
I'm using the following Extra Targets <PropertyGroup>
<SNPath Condition="'$(SNPath)'==''"></SNPath>
<SignAssembly Condition="'$(SignAssembly)'==''"></SignAssembly>
<AssemblyOriginatorKeyFile Condition="'$(AssemblyOriginatorKeyFile)'==''"></AssemblyOriginatorKeyFile>
</PropertyGroup>
<Target Name="GetSNPath" BeforeTargets="FixStrongName">
<GetFrameworkSdkPath>
<Output TaskParameter="Path" PropertyName="WindowsSdkPath" />
</GetFrameworkSdkPath>
<Exec Command="WHERE /r "$(WindowsSdkPath.TrimEnd('\\'))" sn > sn-path.txt" />
<ReadLinesFromFile File="sn-path.txt">
<Output TaskParameter="Lines" PropertyName="SNPath"/>
</ReadLinesFromFile>
<Delete Files="sn-path.txt" />
<PropertyGroup>
<SNPath>$([System.Text.RegularExpressions.Regex]::Replace('$(SNPath)', ';.*', ''))</SNPath>
</PropertyGroup>
</Target>
<Target Name="FixStrongName" AfterTargets="_TenacomExportAnnotations_CopyFilesToOutputDirectory" Condition="$(SignAssembly) == 'True'">
<Message Text="Resigning after Export Annotations for $(ProjectName)" Importance="High" />
<Exec Command=""$(SNPath)" -R "$(TargetPath)" "$(MSBuildProjectDirectory)\$(AssemblyOriginatorKeyFile)"" />
</Target> |
@tankbob thanks a lot for sharing! That's not going to cut it for non-Windows builds, however. In the meantime I've found StrongNameSigner, a .NET library that seems to be able to sign assemblies in C# using Cecil. I cannot reference it from (*) Of course I plan to include a third-party copyright notice. StrongNameSigner's Apache 2.0 license shouldn't be a problem: MSBuild is another MIT-licensed project containing Apache-licensed material. |
On an unrelated note, you don't need an <PropertyGroup>
<SNPath Condition="'$(SNPath)'==''"></SNPath>
<SignAssembly Condition="'$(SignAssembly)'==''"></SignAssembly>
<AssemblyOriginatorKeyFile Condition="'$(AssemblyOriginatorKeyFile)'==''"></AssemblyOriginatorKeyFile>
</PropertyGroup>
<Target Name="GetSNPath" BeforeTargets="FixStrongName">
<GetFrameworkSdkPath>
<Output TaskParameter="Path" PropertyName="WindowsSdkPath" />
</GetFrameworkSdkPath>
<!-- Make sure there's a trailing path separator. -->
<PropertyGroup>
<WindowsSdkPath>$([MSBuild]::EnsureTrailingSlash('$(WindowsSdkPath)'))</WindowsSdkPath>
</PropertyGroup>
<!-- Find all files called sn.exe under the SDK path. -->
<ItemGroup>
<SNExe Include="$(WindowsSdkPath)**\sn.exe" />
</ItemGroup>
<PropertyGroup>
<!-- Turn items into a semicolon-separated list. -->
<SNPath>@(SNExe)</SNPath>
<!-- If there's more than one sn.exe, keep the first and discard the others. -->
<SNPath Condition="@(SNExe->Count()) > 1">$(SNPath.Remove($(SNPath.IndexOf(';'))))</SNPath>
</PropertyGroup>
</Target>
<Target Name="FixStrongName" AfterTargets="_TenacomExportAnnotations_CopyFilesToOutputDirectory" Condition="$(SignAssembly) == 'True'">
<Message Text="Resigning after Export Annotations for $(ProjectName)" Importance="High" />
<Exec Command=""$(SNPath)" -R "$(TargetPath)" "$(MSBuildProjectDirectory)\$(AssemblyOriginatorKeyFile)"" />
</Target> |
@tankbob since I don't modify assemblies using Cecil any more, I closed this issue. Please use the latest version of If you're still having the same problem, please comment below and I'll reopen the issue. |
This task does not work if the assembly is strong named as it breaks the signature.
Need some way of either stripping the assembly before strong naming occurs or reapplying the strong name afterwards.
The text was updated successfully, but these errors were encountered: