Skip to content

Commit f83efb6

Browse files
authored
Merge pull request #632 from chwarr/msbuild-removedups-inorder
Document that RemoveDuplicates preserves order
2 parents b83c72b + a050dde commit f83efb6

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

docs/msbuild/removeduplicates-task.md

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "RemoveDuplicates Task | Microsoft Docs"
33
ms.custom: ""
4-
ms.date: "11/04/2016"
4+
ms.date: "03/01/2018"
55
ms.reviewer: ""
66
ms.suite: ""
77
ms.technology: msbuild
@@ -33,7 +33,7 @@ Removes duplicate items from the specified item collection.
3333

3434
|Parameter|Description|
3535
|---------------|-----------------|
36-
|`Filtered`|Optional <xref:Microsoft.Build.Framework.ITaskItem>`[]` output parameter.<br /><br /> Contains an item collection with all duplicate items removed.|
36+
|`Filtered`|Optional <xref:Microsoft.Build.Framework.ITaskItem>`[]` output parameter.<br /><br /> Contains an item collection with all duplicate items removed. The order of the input items is preserved, keeping the first instance of each duplicate item.|
3737
|`Inputs`|Optional <xref:Microsoft.Build.Framework.ITaskItem>`[]` parameter.<br /><br /> The item collection to remove duplicate items from.|
3838

3939
## Remarks
@@ -65,8 +65,31 @@ Removes duplicate items from the specified item collection.
6565
</Target>
6666
</Project>
6767
```
68+
69+
The following example shows that the `RemoveDuplicates` task preserves its input order. When the task is complete, the `FilteredItems` item collection contains the items "MyFile2.cs", "MyFile1.cs", and "MyFile3.cs" in that order.
6870

71+
```xml
72+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
73+
74+
<ItemGroup>
75+
<MyItems Include="MyFile2.cs"/>
76+
<MyItems Include="MyFile1.cs" />
77+
<MyItems Include="MyFile3.cs" />
78+
<MyItems Include="myfile1.cs"/>
79+
</ItemGroup>
80+
81+
<Target Name="RemoveDuplicateItems">
82+
<RemoveDuplicates
83+
Inputs="@(MyItems)">
84+
<Output
85+
TaskParameter="Filtered"
86+
ItemName="FilteredItems"/>
87+
</RemoveDuplicates>
88+
</Target>
89+
</Project>
90+
```
91+
6992
## See Also
7093
[Task Reference](../msbuild/msbuild-task-reference.md)
7194
[MSBuild Concepts](../msbuild/msbuild-concepts.md)
72-
[Tasks](../msbuild/msbuild-tasks.md)
95+
[Tasks](../msbuild/msbuild-tasks.md)

0 commit comments

Comments
 (0)