Skip to content

Removing duplicate files from publish output #14020

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

Merged
merged 2 commits into from
Nov 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// Copyright (c) .NET Foundation and contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

using Microsoft.Build.Framework;
using System.Collections.Generic;
using System.Linq;

namespace Microsoft.NET.Build.Tasks.ConflictResolution
{
public class ResolveOverlappingItemGroupConflicts : TaskBase
{
[Required]
public ITaskItem[] ItemGroup1 { get; set; }

[Required]
public ITaskItem[] ItemGroup2 { get; set; }

public string[] PreferredPackages { get; set; }

public ITaskItem[] PackageOverrides { get; set; }

[Output]
public ITaskItem[] RemovedItemGroup1 { get; set; }

[Output]
public ITaskItem[] RemovedItemGroup2 { get; set; }

protected override void ExecuteCore()
{
var packageRanks = new PackageRank(PreferredPackages);
var packageOverrides = new PackageOverrideResolver<ConflictItem>(PackageOverrides);
var conflicts = new HashSet<ConflictItem>();

var conflictItemGroup1 = GetConflictTaskItems(ItemGroup1, ConflictItemType.CopyLocal);
var conflictItemGroup2 = GetConflictTaskItems(ItemGroup2, ConflictItemType.CopyLocal);

using (var conflictResolver = new ConflictResolver<ConflictItem>(packageRanks, packageOverrides, Log))
{
var allConflicts = conflictItemGroup1.Concat(conflictItemGroup2);
conflictResolver.ResolveConflicts(allConflicts,
ci => ItemUtilities.GetReferenceTargetPath(ci.OriginalItem),
(ConflictItem winner, ConflictItem loser) => { conflicts.Add(loser); });

var conflictItems = conflicts.Select(i => i.OriginalItem);
RemovedItemGroup1 = ItemGroup1.Intersect(conflictItems).ToArray();
RemovedItemGroup2 = ItemGroup2.Intersect(conflictItems).ToArray();
}
}

private IEnumerable<ConflictItem> GetConflictTaskItems(ITaskItem[] items, ConflictItemType itemType)
{
return (items != null) ? items.Select(i => new ConflictItem(i, itemType)) : Enumerable.Empty<ConflictItem>();
}
}
}
4 changes: 4 additions & 0 deletions src/Tasks/Common/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -694,4 +694,8 @@ The following are names of parameters or literal values and should not be transl
<value>NETSDK1147: The following workload packs were not installed: {0}</value>
<comment>{StrBegin="NETSDK1147: "}</comment>
</data>
<data name="DuplicatePublishOutputFiles" xml:space="preserve">
<value>NETSDK1148: Found multiple publish output files with the same relative path: {0}.</value>
<comment>{StrBegin="NETSDK1148: "}</comment>
</data>
</root>
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.cs.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@
<target state="translated">NETSDK1015: Token preprocesoru {0} získal více než jednu hodnotu. Volí se hodnota {1}.</target>
<note>{StrBegin="NETSDK1015: "}</note>
</trans-unit>
<trans-unit id="DuplicatePublishOutputFiles">
<source>NETSDK1148: Found multiple publish output files with the same relative path: {0}.</source>
<target state="new">NETSDK1148: Found multiple publish output files with the same relative path: {0}.</target>
<note>{StrBegin="NETSDK1148: "}</note>
</trans-unit>
<trans-unit id="DuplicateRuntimePackAsset">
<source>NETSDK1110: More than one asset in the runtime pack has the same destination sub-path of '{0}'. Report this error to the .NET team here: https://aka.ms/dotnet-sdk-issue.</source>
<target state="translated">NETSDK1110: Více než jeden prostředek v balíčku modulu runtime má stejnou cílovou dílčí cestu {0}. Tady můžete tuto chybu nahlásit týmu .NET: https://aka.ms/dotnet-sdk-issue.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.de.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@
<target state="translated">NETSDK1015: Das Präprozessortoken "{0}" wurde mit mehreren Werten versehen. "{1}" wird als Wert ausgewählt.</target>
<note>{StrBegin="NETSDK1015: "}</note>
</trans-unit>
<trans-unit id="DuplicatePublishOutputFiles">
<source>NETSDK1148: Found multiple publish output files with the same relative path: {0}.</source>
<target state="new">NETSDK1148: Found multiple publish output files with the same relative path: {0}.</target>
<note>{StrBegin="NETSDK1148: "}</note>
</trans-unit>
<trans-unit id="DuplicateRuntimePackAsset">
<source>NETSDK1110: More than one asset in the runtime pack has the same destination sub-path of '{0}'. Report this error to the .NET team here: https://aka.ms/dotnet-sdk-issue.</source>
<target state="translated">NETSDK1110: Mehr als eine Ressource im Runtimepaket weist den gleichen Zielunterpfad "{0}" auf. Melden Sie diesen Fehler hier dem .NET-Team: https://aka.ms/dotnet-sdk-issue.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.es.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@
<target state="translated">NETSDK1015: Se han dado varios valores para el token de preprocesador "{0}". Se va a elegir "{1}" como valor.</target>
<note>{StrBegin="NETSDK1015: "}</note>
</trans-unit>
<trans-unit id="DuplicatePublishOutputFiles">
<source>NETSDK1148: Found multiple publish output files with the same relative path: {0}.</source>
<target state="new">NETSDK1148: Found multiple publish output files with the same relative path: {0}.</target>
<note>{StrBegin="NETSDK1148: "}</note>
</trans-unit>
<trans-unit id="DuplicateRuntimePackAsset">
<source>NETSDK1110: More than one asset in the runtime pack has the same destination sub-path of '{0}'. Report this error to the .NET team here: https://aka.ms/dotnet-sdk-issue.</source>
<target state="translated">NETSDK1110: Más de un recurso del paquete del entorno de ejecución tiene la misma subruta de acceso de destino de "{0}". Notifique este error al equipo de .NET aquí: https://aka.ms/dotnet-sdk-issue.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.fr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@
<target state="translated">NETSDK1015: Le jeton de préprocesseur '{0}' a reçu plusieurs valeurs. La valeur choisie est '{1}'.</target>
<note>{StrBegin="NETSDK1015: "}</note>
</trans-unit>
<trans-unit id="DuplicatePublishOutputFiles">
<source>NETSDK1148: Found multiple publish output files with the same relative path: {0}.</source>
<target state="new">NETSDK1148: Found multiple publish output files with the same relative path: {0}.</target>
<note>{StrBegin="NETSDK1148: "}</note>
</trans-unit>
<trans-unit id="DuplicateRuntimePackAsset">
<source>NETSDK1110: More than one asset in the runtime pack has the same destination sub-path of '{0}'. Report this error to the .NET team here: https://aka.ms/dotnet-sdk-issue.</source>
<target state="translated">NETSDK1110: Plusieurs composants du pack de runtime ont le même sous-chemin de destination que '{0}'. Signalez cette erreur à l'équipe .NET ici : https://aka.ms/dotnet-sdk-issue.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.it.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@
<target state="translated">NETSDK1015: al token di preprocessore '{0}' è stato assegnato più di un valore. Come valore verrà scelto '{1}'.</target>
<note>{StrBegin="NETSDK1015: "}</note>
</trans-unit>
<trans-unit id="DuplicatePublishOutputFiles">
<source>NETSDK1148: Found multiple publish output files with the same relative path: {0}.</source>
<target state="new">NETSDK1148: Found multiple publish output files with the same relative path: {0}.</target>
<note>{StrBegin="NETSDK1148: "}</note>
</trans-unit>
<trans-unit id="DuplicateRuntimePackAsset">
<source>NETSDK1110: More than one asset in the runtime pack has the same destination sub-path of '{0}'. Report this error to the .NET team here: https://aka.ms/dotnet-sdk-issue.</source>
<target state="translated">NETSDK1110: più di un asset nel pacchetto di runtime ha lo stesso percorso secondario di destinazione di '{0}'. Segnalare questo errore al team di .NET all'indirizzo: https://aka.ms/dotnet-sdk-issue.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.ja.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@
<target state="translated">NETSDK1015: プリプロセッサ トークン '{0}' に複数の値が指定されています。値として '{1}' を選択します。</target>
<note>{StrBegin="NETSDK1015: "}</note>
</trans-unit>
<trans-unit id="DuplicatePublishOutputFiles">
<source>NETSDK1148: Found multiple publish output files with the same relative path: {0}.</source>
<target state="new">NETSDK1148: Found multiple publish output files with the same relative path: {0}.</target>
<note>{StrBegin="NETSDK1148: "}</note>
</trans-unit>
<trans-unit id="DuplicateRuntimePackAsset">
<source>NETSDK1110: More than one asset in the runtime pack has the same destination sub-path of '{0}'. Report this error to the .NET team here: https://aka.ms/dotnet-sdk-issue.</source>
<target state="translated">NETSDK1110: ランタイム パック内の複数のアセットに同じターゲット サブパス '{0}' が指定されています。https://aka.ms/dotnet-sdk-issue で、このエラーを .NET チームに報告してください。</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.ko.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@
<target state="translated">NETSDK1015: 전처리기 토큰 '{0}'의 값이 두 개 이상 지정되었습니다. '{1}'을(를) 값으로 선택합니다.</target>
<note>{StrBegin="NETSDK1015: "}</note>
</trans-unit>
<trans-unit id="DuplicatePublishOutputFiles">
<source>NETSDK1148: Found multiple publish output files with the same relative path: {0}.</source>
<target state="new">NETSDK1148: Found multiple publish output files with the same relative path: {0}.</target>
<note>{StrBegin="NETSDK1148: "}</note>
</trans-unit>
<trans-unit id="DuplicateRuntimePackAsset">
<source>NETSDK1110: More than one asset in the runtime pack has the same destination sub-path of '{0}'. Report this error to the .NET team here: https://aka.ms/dotnet-sdk-issue.</source>
<target state="translated">NETSDK1110: 런타임 팩에 있는 두 개 이상 자산에 동일한 대상 하위 경로인 '{0}'이(가) 있습니다. https://aka.ms/dotnet-sdk-issue에서 .NET 팀에 이 오류를 보고하세요.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.pl.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@
<target state="translated">NETSDK1015: Dla tokenu preprocesora „{0}” podano więcej niż jedną wartość. Wybieranie elementu „{1}” jako wartości.</target>
<note>{StrBegin="NETSDK1015: "}</note>
</trans-unit>
<trans-unit id="DuplicatePublishOutputFiles">
<source>NETSDK1148: Found multiple publish output files with the same relative path: {0}.</source>
<target state="new">NETSDK1148: Found multiple publish output files with the same relative path: {0}.</target>
<note>{StrBegin="NETSDK1148: "}</note>
</trans-unit>
<trans-unit id="DuplicateRuntimePackAsset">
<source>NETSDK1110: More than one asset in the runtime pack has the same destination sub-path of '{0}'. Report this error to the .NET team here: https://aka.ms/dotnet-sdk-issue.</source>
<target state="translated">NETSDK1110: Więcej niż jeden zasób w pakiecie środowiska uruchomieniowego ma taką samą docelową ścieżkę podrzędną („{0}”). Zgłoś ten błąd zespołowi platformy .NET tutaj: https://aka.ms/dotnet-sdk-issue.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@
<target state="translated">NETSDK1015: O token de pré-processador '{0}' recebeu mais de um valor. Escolhendo '{1}' como o valor.</target>
<note>{StrBegin="NETSDK1015: "}</note>
</trans-unit>
<trans-unit id="DuplicatePublishOutputFiles">
<source>NETSDK1148: Found multiple publish output files with the same relative path: {0}.</source>
<target state="new">NETSDK1148: Found multiple publish output files with the same relative path: {0}.</target>
<note>{StrBegin="NETSDK1148: "}</note>
</trans-unit>
<trans-unit id="DuplicateRuntimePackAsset">
<source>NETSDK1110: More than one asset in the runtime pack has the same destination sub-path of '{0}'. Report this error to the .NET team here: https://aka.ms/dotnet-sdk-issue.</source>
<target state="translated">NETSDK1110: mais de um ativo no pacote de runtime tem o mesmo subcaminho de destino de '{0}'. Relate esse erro à equipe do .NET: https://aka.ms/dotnet-sdk-issue.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.ru.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@
<target state="translated">NETSDK1015: для маркера препроцессора "{0}" указано множество значений. В качестве значения будет использовано "{1}".</target>
<note>{StrBegin="NETSDK1015: "}</note>
</trans-unit>
<trans-unit id="DuplicatePublishOutputFiles">
<source>NETSDK1148: Found multiple publish output files with the same relative path: {0}.</source>
<target state="new">NETSDK1148: Found multiple publish output files with the same relative path: {0}.</target>
<note>{StrBegin="NETSDK1148: "}</note>
</trans-unit>
<trans-unit id="DuplicateRuntimePackAsset">
<source>NETSDK1110: More than one asset in the runtime pack has the same destination sub-path of '{0}'. Report this error to the .NET team here: https://aka.ms/dotnet-sdk-issue.</source>
<target state="translated">NETSDK1110: сразу несколько ресурсов в пакете среды выполнения имеют один и тот же конечный вложенный путь "{0}". Сообщите об этой ошибке группе разработчиков .NET по следующему адресу: https://aka.ms/dotnet-sdk-issue.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.tr.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@
<target state="translated">NETSDK1015: '{0}' ön işlemci belirtecine birden fazla değer verildi. Değer olarak '{1}' seçiliyor.</target>
<note>{StrBegin="NETSDK1015: "}</note>
</trans-unit>
<trans-unit id="DuplicatePublishOutputFiles">
<source>NETSDK1148: Found multiple publish output files with the same relative path: {0}.</source>
<target state="new">NETSDK1148: Found multiple publish output files with the same relative path: {0}.</target>
<note>{StrBegin="NETSDK1148: "}</note>
</trans-unit>
<trans-unit id="DuplicateRuntimePackAsset">
<source>NETSDK1110: More than one asset in the runtime pack has the same destination sub-path of '{0}'. Report this error to the .NET team here: https://aka.ms/dotnet-sdk-issue.</source>
<target state="translated">NETSDK1110: Çalışma zamanı paketindeki birden fazla varlık, aynı '{0}' hedef alt yoluna sahip. Bu hatayı https://aka.ms/dotnet-sdk-issue adresinden .NET ekibine bildirin.</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@
<target state="translated">NETSDK1015: 已向预处理器标记“{0}”提供多个值。选择“{1}”作为值。</target>
<note>{StrBegin="NETSDK1015: "}</note>
</trans-unit>
<trans-unit id="DuplicatePublishOutputFiles">
<source>NETSDK1148: Found multiple publish output files with the same relative path: {0}.</source>
<target state="new">NETSDK1148: Found multiple publish output files with the same relative path: {0}.</target>
<note>{StrBegin="NETSDK1148: "}</note>
</trans-unit>
<trans-unit id="DuplicateRuntimePackAsset">
<source>NETSDK1110: More than one asset in the runtime pack has the same destination sub-path of '{0}'. Report this error to the .NET team here: https://aka.ms/dotnet-sdk-issue.</source>
<target state="translated">NETSDK1110: 运行时包中的多个资产具有“{0}”的相同目标子路径。请在此处将此错误报告给 .NET 团队: https://aka.ms/dotnet-sdk-issue。</target>
Expand Down
5 changes: 5 additions & 0 deletions src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,11 @@
<target state="translated">NETSDK1015: 已為前置處理器語彙基元 '{0}' 指定多個值。正在選擇 '{1}' 作為值。</target>
<note>{StrBegin="NETSDK1015: "}</note>
</trans-unit>
<trans-unit id="DuplicatePublishOutputFiles">
<source>NETSDK1148: Found multiple publish output files with the same relative path: {0}.</source>
<target state="new">NETSDK1148: Found multiple publish output files with the same relative path: {0}.</target>
<note>{StrBegin="NETSDK1148: "}</note>
</trans-unit>
<trans-unit id="DuplicateRuntimePackAsset">
<source>NETSDK1110: More than one asset in the runtime pack has the same destination sub-path of '{0}'. Report this error to the .NET team here: https://aka.ms/dotnet-sdk-issue.</source>
<target state="translated">NETSDK1110: 執行階段套件中有多項資產具有相同的目的地子路徑 '{0}'。請將此錯誤回報給 .NET 小組: https://aka.ms/dotnet-sdk-issue。</target>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using Microsoft.Build.Framework;
using System.Linq;

namespace Microsoft.NET.Build.Tasks
{
public class CheckForDuplicateItemMetadata : TaskBase
{
[Required]
public ITaskItem[] Items { get; set; }

[Required]
public string MetadataName { get; set; }

[Output]
public ITaskItem[] DuplicateItems { get; set; }

[Output]
public string[] DuplicatedMetadataValues { get; set; }

[Output]
public bool DuplicatesExist { get; set; }

protected override void ExecuteCore()
{
var groupings = Items.GroupBy(item => item.GetMetadata(MetadataName))
.Where(g => g.Count() > 1)
.ToList();
DuplicatesExist = groupings.Any();
DuplicatedMetadataValues = groupings
.Select(g => g.Key)
.ToArray();
DuplicateItems = groupings
.SelectMany(g => g)
.ToArray();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Copyright (c) .NET Foundation. All rights reserved.
<Import Project="Microsoft.NET.DefaultPackageConflictOverrides.targets" />

<UsingTask TaskName="ResolvePackageFileConflicts" AssemblyFile="$(MicrosoftNETBuildTasksAssembly)" />
<UsingTask TaskName="CheckForDuplicateItemMetadata" AssemblyFile="$(MicrosoftNETBuildTasksAssembly)" />

<!--
_HandlePackageFileConflicts
Expand Down Expand Up @@ -89,4 +90,25 @@ Copyright (c) .NET Foundation. All rights reserved.

</Target>

<!--
_HandleFileConflictsForPublish
Ensures there are no duplicate files being written to the publish output.
-->
<Target Name="_HandleFileConflictsForPublish"
AfterTargets="ComputeFilesToPublish"
Condition="'$(ErrorOnDuplicatePublishOutputFiles)' != 'false'">

<CheckForDuplicateItemMetadata
Items="@(ResolvedFileToPublish->Distinct())"
MetadataName="RelativePath">
<Output TaskParameter="DuplicatesExist" PropertyName="_ResolvedFileToPublishContainsDuplicates" />
<Output TaskParameter="DuplicateItems" ItemName="_ResolvedFileToPublishDuplicatedItems" />
</CheckForDuplicateItemMetadata>

<NETSdkError Condition="'$(_ResolvedFileToPublishContainsDuplicates)' == 'true'"
ResourceName="DuplicatePublishOutputFiles"
FormatArguments="@(_ResolvedFileToPublishDuplicatedItems, ', ')" />

</Target>

</Project>
Loading