Skip to content

Commit 10ecfba

Browse files
committed
Removing conflicting publish output dlls
1 parent d9e515f commit 10ecfba

19 files changed

+304
-4
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
// Copyright (c) .NET Foundation and contributors. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using Microsoft.Build.Framework;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
8+
namespace Microsoft.NET.Build.Tasks.ConflictResolution
9+
{
10+
public class ResolveOverlappingItemGroupConflicts : TaskBase
11+
{
12+
[Required]
13+
public ITaskItem[] ItemGroup1 { get; set; }
14+
15+
[Required]
16+
public ITaskItem[] ItemGroup2 { get; set; }
17+
18+
public string[] PreferredPackages { get; set; }
19+
20+
public ITaskItem[] PackageOverrides { get; set; }
21+
22+
[Output]
23+
public ITaskItem[] RemovedItemGroup1 { get; set; }
24+
25+
[Output]
26+
public ITaskItem[] RemovedItemGroup2 { get; set; }
27+
28+
protected override void ExecuteCore()
29+
{
30+
var packageRanks = new PackageRank(PreferredPackages);
31+
var packageOverrides = new PackageOverrideResolver<ConflictItem>(PackageOverrides);
32+
var conflicts = new HashSet<ConflictItem>();
33+
34+
var conflictItemGroup1 = GetConflictTaskItems(ItemGroup1, ConflictItemType.CopyLocal);
35+
var conflictItemGroup2 = GetConflictTaskItems(ItemGroup2, ConflictItemType.CopyLocal);
36+
37+
using (var conflictResolver = new ConflictResolver<ConflictItem>(packageRanks, packageOverrides, Log))
38+
{
39+
var allConflicts = conflictItemGroup1.Concat(conflictItemGroup2);
40+
conflictResolver.ResolveConflicts(allConflicts,
41+
ci => ItemUtilities.GetReferenceTargetPath(ci.OriginalItem),
42+
(ConflictItem winner, ConflictItem loser) => { conflicts.Add(loser); });
43+
44+
var conflictItems = conflicts.Select(i => i.OriginalItem);
45+
RemovedItemGroup1 = ItemGroup1.Intersect(conflictItems).ToArray();
46+
RemovedItemGroup2 = ItemGroup2.Intersect(conflictItems).ToArray();
47+
}
48+
}
49+
50+
private IEnumerable<ConflictItem> GetConflictTaskItems(ITaskItem[] items, ConflictItemType itemType)
51+
{
52+
return (items != null) ? items.Select(i => new ConflictItem(i, itemType)) : Enumerable.Empty<ConflictItem>();
53+
}
54+
}
55+
}

src/Tasks/Common/Resources/Strings.resx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,4 +686,8 @@ The following are names of parameters or literal values and should not be transl
686686
<value>NETSDK1145: The {0} pack is not installed and NuGet package restore is not supported. Upgrade Visual Studio, remove global.json if it specifies a certain SDK version, and uninstall the newer SDK. For more options visit https://aka.ms/targeting-apphost-pack-missing Pack Type:{0}, Pack directory: {1}, targetframework: {2}, Pack PackageId: {3}, Pack Package Version: {4}</value>
687687
<comment>{StrBegin="NETSDK1145: "}</comment>
688688
</data>
689+
<data name="DuplicatePublishOutputFiles" xml:space="preserve">
690+
<value>NETSDK1146: Found multiple publish output files with the same relative path: {0}.</value>
691+
<comment>{StrBegin="NETSDK1146: "}</comment>
692+
</data>
689693
</root>

src/Tasks/Common/Resources/xlf/Strings.cs.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@
284284
<target state="translated">NETSDK1015: Token preprocesoru {0} získal více než jednu hodnotu. Volí se hodnota {1}.</target>
285285
<note>{StrBegin="NETSDK1015: "}</note>
286286
</trans-unit>
287+
<trans-unit id="DuplicatePublishOutputFiles">
288+
<source>NETSDK1146: Found multiple publish output files with the same relative path: {0}.</source>
289+
<target state="new">NETSDK1146: Found multiple publish output files with the same relative path: {0}.</target>
290+
<note>{StrBegin="NETSDK1146: "}</note>
291+
</trans-unit>
287292
<trans-unit id="DuplicateRuntimePackAsset">
288293
<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>
289294
<target state="needs-review-translation">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 Core: https://aka.ms/dotnet-sdk-issue.</target>

src/Tasks/Common/Resources/xlf/Strings.de.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@
284284
<target state="translated">NETSDK1015: Das Präprozessortoken "{0}" wurde mit mehreren Werten versehen. "{1}" wird als Wert ausgewählt.</target>
285285
<note>{StrBegin="NETSDK1015: "}</note>
286286
</trans-unit>
287+
<trans-unit id="DuplicatePublishOutputFiles">
288+
<source>NETSDK1146: Found multiple publish output files with the same relative path: {0}.</source>
289+
<target state="new">NETSDK1146: Found multiple publish output files with the same relative path: {0}.</target>
290+
<note>{StrBegin="NETSDK1146: "}</note>
291+
</trans-unit>
287292
<trans-unit id="DuplicateRuntimePackAsset">
288293
<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>
289294
<target state="needs-review-translation">NETSDK1110: Mehr als eine Ressource im Runtimepaket weist den gleichen Zielunterpfad "{0}" auf. Melden Sie diesen Fehler hier dem .NET Core-Team: https://aka.ms/dotnet-sdk-issue.</target>

src/Tasks/Common/Resources/xlf/Strings.es.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@
284284
<target state="translated">NETSDK1015: Se han dado varios valores para el token de preprocesador "{0}". Se va a elegir "{1}" como valor.</target>
285285
<note>{StrBegin="NETSDK1015: "}</note>
286286
</trans-unit>
287+
<trans-unit id="DuplicatePublishOutputFiles">
288+
<source>NETSDK1146: Found multiple publish output files with the same relative path: {0}.</source>
289+
<target state="new">NETSDK1146: Found multiple publish output files with the same relative path: {0}.</target>
290+
<note>{StrBegin="NETSDK1146: "}</note>
291+
</trans-unit>
287292
<trans-unit id="DuplicateRuntimePackAsset">
288293
<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>
289294
<target state="needs-review-translation">NETSDK1110: Más de un recurso en el paquete del entorno de ejecución tiene la misma subruta de acceso de destino de "{0}". Notifique este error al equipo de .NET Core aquí: https://aka.ms/dotnet-sdk-issue.</target>

src/Tasks/Common/Resources/xlf/Strings.fr.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@
284284
<target state="translated">NETSDK1015: Le jeton de préprocesseur '{0}' a reçu plusieurs valeurs. La valeur choisie est '{1}'.</target>
285285
<note>{StrBegin="NETSDK1015: "}</note>
286286
</trans-unit>
287+
<trans-unit id="DuplicatePublishOutputFiles">
288+
<source>NETSDK1146: Found multiple publish output files with the same relative path: {0}.</source>
289+
<target state="new">NETSDK1146: Found multiple publish output files with the same relative path: {0}.</target>
290+
<note>{StrBegin="NETSDK1146: "}</note>
291+
</trans-unit>
287292
<trans-unit id="DuplicateRuntimePackAsset">
288293
<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>
289294
<target state="needs-review-translation">NETSDK1110: plusieurs composants du pack de runtime ont le même sous-chemin de destination que '{0}'. Signalez cette erreur à l'équipe .NET Core à l'adresse suivante : https://aka.ms/dotnet-sdk-issue.</target>

src/Tasks/Common/Resources/xlf/Strings.it.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@
284284
<target state="translated">NETSDK1015: al token di preprocessore '{0}' è stato assegnato più di un valore. Come valore verrà scelto '{1}'.</target>
285285
<note>{StrBegin="NETSDK1015: "}</note>
286286
</trans-unit>
287+
<trans-unit id="DuplicatePublishOutputFiles">
288+
<source>NETSDK1146: Found multiple publish output files with the same relative path: {0}.</source>
289+
<target state="new">NETSDK1146: Found multiple publish output files with the same relative path: {0}.</target>
290+
<note>{StrBegin="NETSDK1146: "}</note>
291+
</trans-unit>
287292
<trans-unit id="DuplicateRuntimePackAsset">
288293
<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>
289294
<target state="needs-review-translation">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 Core all'indirizzo: https://aka.ms/dotnet-sdk-issue.</target>

src/Tasks/Common/Resources/xlf/Strings.ja.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@
284284
<target state="translated">NETSDK1015: プリプロセッサ トークン '{0}' に複数の値が指定されています。値として '{1}' を選択します。</target>
285285
<note>{StrBegin="NETSDK1015: "}</note>
286286
</trans-unit>
287+
<trans-unit id="DuplicatePublishOutputFiles">
288+
<source>NETSDK1146: Found multiple publish output files with the same relative path: {0}.</source>
289+
<target state="new">NETSDK1146: Found multiple publish output files with the same relative path: {0}.</target>
290+
<note>{StrBegin="NETSDK1146: "}</note>
291+
</trans-unit>
287292
<trans-unit id="DuplicateRuntimePackAsset">
288293
<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>
289294
<target state="needs-review-translation">NETSDK1110: ランタイム パック内の複数のアセットに同じターゲット サブパス '{0}' が指定されています。https://aka.ms/dotnet-sdk-issue で、このエラーを .NET Core チームに報告してください。</target>

src/Tasks/Common/Resources/xlf/Strings.ko.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@
284284
<target state="translated">NETSDK1015: 전처리기 토큰 '{0}'의 값이 두 개 이상 지정되었습니다. '{1}'을(를) 값으로 선택합니다.</target>
285285
<note>{StrBegin="NETSDK1015: "}</note>
286286
</trans-unit>
287+
<trans-unit id="DuplicatePublishOutputFiles">
288+
<source>NETSDK1146: Found multiple publish output files with the same relative path: {0}.</source>
289+
<target state="new">NETSDK1146: Found multiple publish output files with the same relative path: {0}.</target>
290+
<note>{StrBegin="NETSDK1146: "}</note>
291+
</trans-unit>
287292
<trans-unit id="DuplicateRuntimePackAsset">
288293
<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>
289294
<target state="needs-review-translation">NETSDK1110: 런타임 팩에 있는 두 개 이상 자산에 동일한 대상 하위 경로인 '{0}'이(가) 있습니다. https://aka.ms/dotnet-sdk-issue에서 .NET Core 팀에 이 오류를 보고하세요.</target>

src/Tasks/Common/Resources/xlf/Strings.pl.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@
284284
<target state="translated">NETSDK1015: Dla tokenu preprocesora „{0}” podano więcej niż jedną wartość. Wybieranie elementu „{1}” jako wartości.</target>
285285
<note>{StrBegin="NETSDK1015: "}</note>
286286
</trans-unit>
287+
<trans-unit id="DuplicatePublishOutputFiles">
288+
<source>NETSDK1146: Found multiple publish output files with the same relative path: {0}.</source>
289+
<target state="new">NETSDK1146: Found multiple publish output files with the same relative path: {0}.</target>
290+
<note>{StrBegin="NETSDK1146: "}</note>
291+
</trans-unit>
287292
<trans-unit id="DuplicateRuntimePackAsset">
288293
<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>
289294
<target state="needs-review-translation">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 Core tutaj: https://aka.ms/dotnet-sdk-issue.</target>

src/Tasks/Common/Resources/xlf/Strings.pt-BR.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@
284284
<target state="translated">NETSDK1015: O token de pré-processador '{0}' recebeu mais de um valor. Escolhendo '{1}' como o valor.</target>
285285
<note>{StrBegin="NETSDK1015: "}</note>
286286
</trans-unit>
287+
<trans-unit id="DuplicatePublishOutputFiles">
288+
<source>NETSDK1146: Found multiple publish output files with the same relative path: {0}.</source>
289+
<target state="new">NETSDK1146: Found multiple publish output files with the same relative path: {0}.</target>
290+
<note>{StrBegin="NETSDK1146: "}</note>
291+
</trans-unit>
287292
<trans-unit id="DuplicateRuntimePackAsset">
288293
<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>
289294
<target state="needs-review-translation">NETSDK1110: Mais de um ativo no pacote de runtime tem o mesmo subcaminho de destino de '{0}'. Relate esse erro à equipe do .NET Core: https://aka.ms/dotnet-sdk-issue.</target>

src/Tasks/Common/Resources/xlf/Strings.ru.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@
284284
<target state="translated">NETSDK1015: для маркера препроцессора "{0}" указано множество значений. В качестве значения будет использовано "{1}".</target>
285285
<note>{StrBegin="NETSDK1015: "}</note>
286286
</trans-unit>
287+
<trans-unit id="DuplicatePublishOutputFiles">
288+
<source>NETSDK1146: Found multiple publish output files with the same relative path: {0}.</source>
289+
<target state="new">NETSDK1146: Found multiple publish output files with the same relative path: {0}.</target>
290+
<note>{StrBegin="NETSDK1146: "}</note>
291+
</trans-unit>
287292
<trans-unit id="DuplicateRuntimePackAsset">
288293
<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>
289294
<target state="needs-review-translation">NETSDK1110: сразу несколько ресурсов в пакете среды выполнения имеют один и тот же конечный вложенный путь "{0}". Сообщите об этой ошибке группе разработчиков .NET Core по следующему адресу: https://aka.ms/dotnet-sdk-issue.</target>

src/Tasks/Common/Resources/xlf/Strings.tr.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@
284284
<target state="translated">NETSDK1015: '{0}' ön işlemci belirtecine birden fazla değer verildi. Değer olarak '{1}' seçiliyor.</target>
285285
<note>{StrBegin="NETSDK1015: "}</note>
286286
</trans-unit>
287+
<trans-unit id="DuplicatePublishOutputFiles">
288+
<source>NETSDK1146: Found multiple publish output files with the same relative path: {0}.</source>
289+
<target state="new">NETSDK1146: Found multiple publish output files with the same relative path: {0}.</target>
290+
<note>{StrBegin="NETSDK1146: "}</note>
291+
</trans-unit>
287292
<trans-unit id="DuplicateRuntimePackAsset">
288293
<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>
289294
<target state="needs-review-translation">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 Core ekibine bildirin.</target>

src/Tasks/Common/Resources/xlf/Strings.zh-Hans.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@
284284
<target state="translated">NETSDK1015: 已向预处理器标记“{0}”提供多个值。选择“{1}”作为值。</target>
285285
<note>{StrBegin="NETSDK1015: "}</note>
286286
</trans-unit>
287+
<trans-unit id="DuplicatePublishOutputFiles">
288+
<source>NETSDK1146: Found multiple publish output files with the same relative path: {0}.</source>
289+
<target state="new">NETSDK1146: Found multiple publish output files with the same relative path: {0}.</target>
290+
<note>{StrBegin="NETSDK1146: "}</note>
291+
</trans-unit>
287292
<trans-unit id="DuplicateRuntimePackAsset">
288293
<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>
289294
<target state="needs-review-translation">NETSDK1110: 运行时包中的多个资源具有 "{0}" 的相同目标子路径。请访问以下网站将此问题报告给 .NET Core 团队https://aka.ms/dotnet-sdk-issue。</target>

src/Tasks/Common/Resources/xlf/Strings.zh-Hant.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,11 @@
284284
<target state="translated">NETSDK1015: 已為前置處理器語彙基元 '{0}' 指定多個值。正在選擇 '{1}' 作為值。</target>
285285
<note>{StrBegin="NETSDK1015: "}</note>
286286
</trans-unit>
287+
<trans-unit id="DuplicatePublishOutputFiles">
288+
<source>NETSDK1146: Found multiple publish output files with the same relative path: {0}.</source>
289+
<target state="new">NETSDK1146: Found multiple publish output files with the same relative path: {0}.</target>
290+
<note>{StrBegin="NETSDK1146: "}</note>
291+
</trans-unit>
287292
<trans-unit id="DuplicateRuntimePackAsset">
288293
<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>
289294
<target state="needs-review-translation">NETSDK1110: 執行階段套件中有多個資產具有相同的目的地子路徑 '{0}'。請於此處將錯誤回報給 .NET Core 小組: https://aka.ms/dotnet-sdk-issue。</target>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using Microsoft.Build.Framework;
2+
using System.Linq;
3+
4+
namespace Microsoft.NET.Build.Tasks
5+
{
6+
public class CheckForDuplicateItemMetadata : TaskBase
7+
{
8+
[Required]
9+
public ITaskItem[] Items { get; set; }
10+
11+
[Required]
12+
public string MetadataName { get; set; }
13+
14+
[Output]
15+
public ITaskItem[] DuplicateItems { get; set; }
16+
17+
[Output]
18+
public string[] DuplicatedMetadataValues { get; set; }
19+
20+
[Output]
21+
public bool DuplicatesExist { get; set; }
22+
23+
protected override void ExecuteCore()
24+
{
25+
var groupings = Items.GroupBy(item => item.GetMetadata(MetadataName))
26+
.Where(g => g.Count() > 1)
27+
.ToList();
28+
DuplicatesExist = groupings.Any();
29+
DuplicatedMetadataValues = groupings
30+
.Select(g => g.Key)
31+
.ToArray();
32+
DuplicateItems = groupings
33+
.SelectMany(g => g)
34+
.ToArray();
35+
}
36+
}
37+
}

src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.ConflictResolution.targets

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Copyright (c) .NET Foundation. All rights reserved.
1515
<Import Project="Microsoft.NET.DefaultPackageConflictOverrides.targets" />
1616

1717
<UsingTask TaskName="ResolvePackageFileConflicts" AssemblyFile="$(MicrosoftNETBuildTasksAssembly)" />
18+
<UsingTask TaskName="CheckForDuplicateItemMetadata" AssemblyFile="$(MicrosoftNETBuildTasksAssembly)" />
1819

1920
<!--
2021
_HandlePackageFileConflicts
@@ -89,4 +90,25 @@ Copyright (c) .NET Foundation. All rights reserved.
8990

9091
</Target>
9192

93+
<!--
94+
_HandleFileConflictsForPublish
95+
Ensures there are no duplicate files being written to the publish output.
96+
-->
97+
<Target Name="_HandleFileConflictsForPublish"
98+
AfterTargets="ComputeFilesToPublish"
99+
Condition="'$(ErrorOnDuplicatePublishOutputFiles)' != 'false'">
100+
101+
<CheckForDuplicateItemMetadata
102+
Items="@(ResolvedFileToPublish)"
103+
MetadataName="RelativePath">
104+
<Output TaskParameter="DuplicatesExist" PropertyName="_ResolvedFileToPublishContainsDuplicates" />
105+
<Output TaskParameter="DuplicateItems" ItemName="_ResolvedFileToPublishDuplicatedItems" />
106+
</CheckForDuplicateItemMetadata>
107+
108+
<NETSdkError Condition="'$(_ResolvedFileToPublishContainsDuplicates)' == 'true'"
109+
ResourceName="DuplicatePublishOutputFiles"
110+
FormatArguments="@(_ResolvedFileToPublishDuplicatedItems, ', ')" />
111+
112+
</Target>
113+
92114
</Project>

0 commit comments

Comments
 (0)