Skip to content

Commit 1a2c848

Browse files
committed
chore: add msbuild target to update strong name signature
1 parent c2f0a6e commit 1a2c848

File tree

1 file changed

+42
-1
lines changed

1 file changed

+42
-1
lines changed

Directory.Build.targets

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
NuGet don't support <img> (in particular, align, width and height).
3030
This task generates a new README file with those unsupported constructs removed.
3131
-->
32-
<Target Name="GenerateNugetReadmeFiles"
32+
<Target Name="Allure_GenerateNugetReadmeFiles"
3333
BeforeTargets="GenerateNuspec"
3434
Condition="'$(IsPackable)' == 'true'"
3535
Inputs="@(NuGetPackInput)" Outputs="@(NuGetPackOutput)">
@@ -48,4 +48,45 @@
4848
</_PackageFiles>
4949
</ItemGroup>
5050
</Target>
51+
52+
<!-- Some assemblies have strong names. We should resign them after AspectInjector before publishing on NuGet.
53+
Otherwise, they won't pass the `sn.exe -vf <assembly>` check -->
54+
55+
<Target Name="Allure_SetAssemblyTimestampBeforeAspectInjection"
56+
AfterTargets="CoreCompile"
57+
BeforeTargets="$(_InjectAspectsDependsOn)">
58+
<PropertyGroup>
59+
<Allure_AssemblyTimestampBeforeAspectInjection>%(IntermediateAssembly.ModifiedTime)</Allure_AssemblyTimestampBeforeAspectInjection>
60+
</PropertyGroup>
61+
</Target>
62+
63+
<Target Name="Allure_SetAssemblyTimestampAfterAspectInjection"
64+
AfterTargets="AspectInjector_InjectAspects"
65+
BeforeTargets="Allure_UpdateStrongNameSignatures">
66+
<PropertyGroup>
67+
<Allure_AssemblyTimestampAfterAspectInjection>%(IntermediateAssembly.ModifiedTime)</Allure_AssemblyTimestampAfterAspectInjection>
68+
</PropertyGroup>
69+
</Target>
70+
71+
<!--
72+
Only resign the assembly if all four conditions are met:
73+
1. We're running on Windows (sn.exe is a Windows-only utility).
74+
2. The assembly's been signed during the compilation.
75+
3. A path to sn.exe is given.
76+
4. AspectInjector has modified the assembly.
77+
-->
78+
<Target Name="Allure_UpdateStrongNameSignatures"
79+
Condition=" '$(OS)' == 'Windows_NT'
80+
And '$(SignAssembly)' == 'true'
81+
And Exists('$(AssemblyOriginatorKeyFile)')
82+
And Exists('$(Allure_SnExePath)')
83+
And '$(Allure_AssemblyTimestampBeforeAspectInjection)' != '$(Allure_AssemblyTimestampAfterAspectInjection)'"
84+
AfterTargets="AspectInjector_InjectAspects"
85+
BeforeTargets="_TimeStampAfterCompile;AfterCompile">
86+
<Exec UseUtf8Encoding="Always"
87+
StdOutEncoding="UTF-8"
88+
StdErrEncoding="UTF-8"
89+
Command="&quot;$(Allure_SnExePath)&quot; -Ra &quot;%(IntermediateAssembly.FullPath)&quot; &quot;$(AssemblyOriginatorKeyFile)&quot;"
90+
/>
91+
</Target>
5192
</Project>

0 commit comments

Comments
 (0)