Skip to content
This repository was archived by the owner on Aug 3, 2024. It is now read-only.

Commit d298565

Browse files
committed
De-dupe files to sign in non-batch signing case (#313)
1 parent ae6a42c commit d298565

2 files changed

Lines changed: 38 additions & 16 deletions

File tree

build/FindDuplicateFiles.targets

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<DuplicateFiles ParameterType="Microsoft.Build.Framework.ITaskItem[]" Output="true" />
1010
</ParameterGroup>
1111
<Task>
12-
<Code Type="Class" Language="cs" Source="FindDuplicateFiles.cs" />
12+
<Code Type="Class" Language="cs" Source="$(MSBuildThisFileDirectory)FindDuplicateFiles.cs" />
1313
</Task>
1414
</UsingTask>
1515
</Project>

build/sign.microbuild.targets

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
-->
3636
<PropertyGroup Condition="'$(WebPublishMethod)' == 'Package'">
3737
<EnumerateFilesToSignAfterTargets>PipelineCopyAllFilesToOneFolderForMsdeploy</EnumerateFilesToSignAfterTargets>
38-
<PackageUsingManifestDependsOn>SignFiles</PackageUsingManifestDependsOn>
38+
<PackageUsingManifestDependsOn>CopySignedFiles</PackageUsingManifestDependsOn>
3939
</PropertyGroup>
4040

4141
<!--
@@ -46,13 +46,13 @@
4646
things.
4747
-->
4848
<ItemGroup Condition="'$(BatchSign)' == 'false'">
49-
<SignFilesDependsOn Include="EnumerateFilesToSign" />
49+
<SignFilesDependsOn Include="DedupeFilesToSign" />
5050
</ItemGroup>
5151
<Target
5252
Name="EnumerateFilesToSign"
5353
AfterTargets="$(EnumerateFilesToSignAfterTargets)"
5454
Condition="'$(SignAssembly)' == 'true' AND '$(SignType)' != 'none' AND '$(SkipEnumerateFilesToSign)' != 'true'"
55-
Returns="@(FilesToSign)">
55+
Returns="@(UnfilteredFilesToSign)">
5656

5757
<ItemGroup>
5858
<!--
@@ -66,68 +66,90 @@
6666
bin directory of another project. That assembly also needs to be signed.
6767
-->
6868
<_OutputToSign Include="$(RepositoryRootDirectory)**\$(TargetFileName)" Condition="'$(BatchSign)' == 'true'" />
69-
<FilesToSign
69+
<UnfilteredFilesToSign
7070
Include="$([System.IO.Path]::GetFullPath('%(_OutputToSign.Identity)'))"
7171
Condition="Exists('%(_OutputToSign.Identity)')"
7272
KeepDuplicates="false">
7373
<Authenticode>Microsoft400</Authenticode>
7474
<StrongName>MsSharedLib72</StrongName>
75-
</FilesToSign>
75+
</UnfilteredFilesToSign>
7676

7777
<!--
7878
Add fully qualified paths for PowerShell scripts. By convention, add common scripts that we use for jobs.
7979
-->
8080
<PowerShellScriptsToSign Include="Scripts\Functions.ps1"/>
8181
<PowerShellScriptsToSign Include="Scripts\PostDeploy.ps1"/>
8282
<PowerShellScriptsToSign Include="Scripts\PreDeploy.ps1"/>
83-
<FilesToSign
83+
<UnfilteredFilesToSign
8484
Include="$([System.IO.Path]::GetFullPath('$(ProjectDir)%(PowerShellScriptsToSign.Identity)'))"
8585
Condition="Exists('$(ProjectDir)%(PowerShellScriptsToSign.Identity)')"
8686
KeepDuplicates="false">
8787
<Authenticode>Microsoft400</Authenticode>
88-
</FilesToSign>
88+
</UnfilteredFilesToSign>
8989

9090
<!--
9191
Add fully qualified paths for checked in binaries. By convention, add common binaries that we use for jobs.
9292
-->
9393
<ExecutablesToSign Include="Scripts\nssm.exe"/>
94-
<FilesToSign
94+
<UnfilteredFilesToSign
9595
Include="$([System.IO.Path]::GetFullPath('$(ProjectDir)%(ExecutablesToSign.Identity)'))"
9696
Condition="Exists('$(ProjectDir)%(ExecutablesToSign.Identity)')"
9797
KeepDuplicates="false">
9898
<Authenticode>3PartySHA2</Authenticode>
99-
</FilesToSign>
99+
</UnfilteredFilesToSign>
100100

101101
<!--
102102
Add fully qualified paths for third-party binaries.
103103
-->
104-
<FilesToSign
104+
<UnfilteredFilesToSign
105105
Include="$([System.IO.Path]::GetFullPath('$(TargetDir)%(ThirdPartyBinaries.Identity)'))"
106106
Condition="@(ThirdPartyBinaries->Count()) &gt; 0 AND Exists('$(TargetDir)%(ThirdPartyBinaries.Identity)')"
107107
KeepDuplicates="false">
108108
<Authenticode>3PartySHA2</Authenticode>
109-
</FilesToSign>
109+
</UnfilteredFilesToSign>
110110
</ItemGroup>
111111

112112
<!--
113113
When we are building a web app package, sign the third party assemblies and output assembly from the single folder
114114
used for packaging.
115115
-->
116116
<ItemGroup Condition="'$(WebPublishMethod)' == 'Package'">
117-
<FilesToSign
117+
<UnfilteredFilesToSign
118118
Include="$(WPPAllFilesInSingleFolder)\bin\%(ThirdPartyBinaries.Identity)"
119119
Condition="Exists('$(WPPAllFilesInSingleFolder)\bin\%(ThirdPartyBinaries.Identity)')">
120120
<Authenticode>3PartySHA2</Authenticode>
121-
</FilesToSign>
122-
<FilesToSign
121+
</UnfilteredFilesToSign>
122+
<UnfilteredFilesToSign
123123
Include="$(WPPAllFilesInSingleFolder)\bin\$(TargetFileName)"
124124
Condition="Exists('$(WPPAllFilesInSingleFolder)\bin\$(TargetFileName)')">
125125
<Authenticode>Microsoft400</Authenticode>
126126
<StrongName>MsSharedLib72</StrongName>
127-
</FilesToSign>
127+
</UnfilteredFilesToSign>
128128
</ItemGroup>
129+
</Target>
129130

131+
<Target
132+
Name="DedupeFilesToSign"
133+
DependsOnTargets="EnumerateFilesToSign">
134+
<FindDuplicateFiles Files="@(UnfilteredFilesToSign)">
135+
<Output
136+
TaskParameter="UniqueFiles"
137+
ItemName="FilesToSign" />
138+
<Output
139+
TaskParameter="DuplicateFiles"
140+
ItemName="DuplicateFilesToSign" />
141+
</FindDuplicateFiles>
130142
<Message Text="Count of files to sign: @(FilesToSign->Count())" Importance="High" />
131143
<Message Text="Files to sign:%0A@(FilesToSign, '%0A')" Importance="High" />
144+
</Target>
145+
146+
<Target Name="CopySignedFiles"
147+
AfterTargets="SignFiles"
148+
DependsOnTargets="SignFiles">
149+
<Copy
150+
SourceFiles="@(DuplicateFilesToSign->'%(DuplicateOf)')"
151+
DestinationFiles="@(DuplicateFilesToSign)" />
132152
</Target>
153+
154+
<Import Project="FindDuplicateFiles.targets" />
133155
</Project>

0 commit comments

Comments
 (0)