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

Commit 2ca03ac

Browse files
thorgeirkzu
authored andcommitted
Only remove duplicate files with the exact same soure path.
Throw exception for files with conflicting package path
1 parent 0fe2e96 commit 2ca03ac

2 files changed

Lines changed: 16 additions & 3 deletions

File tree

src/Build/NuGet.Build.Packaging.Tasks/CreatePackage.cs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,18 @@ void AddFiles(Manifest manifest)
148148
// Remove duplicate files
149149
var contents = Contents
150150
.Where(item => !string.IsNullOrEmpty(item.GetMetadata(MetadataName.PackagePath)))
151-
.GroupBy(item => item.GetMetadata(MetadataName.PackagePath))
152-
.Select(x => x.First());
151+
.GroupBy(item => item.ItemSpec)
152+
.Select(x => x.First()).ToArray();
153+
154+
//Find files with conflicting package path
155+
var duplicates = contents.GroupBy(item => item.GetMetadata(MetadataName.PackagePath))
156+
.Where(x => x.Count() > 1)
157+
.Select(x => x.Key);
158+
159+
foreach (var duplicate in duplicates)
160+
{
161+
Log.LogErrorCode(nameof(ErrorCode.NG0012), ErrorCode.NG0012(duplicate));
162+
}
153163

154164
// All files need to be added so they are included in the nupkg
155165
manifest.Files.AddRange(contents

src/Build/NuGet.Build.Packaging.Tests/given_duplicate_package_files.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ public void build_fails()
2121

2222
Assert.Equal(TargetResultCode.Failure, result.ResultCode);
2323

24-
Assert.True(result.Logger.Errors.Any(e => e.Message.Contains("content.txt")));
24+
// content.txt is marked as PackageFile and the path to the file is exacly the same in both project a and b.
25+
Assert.False(result.Logger.Errors.Any(e => e.Message.Contains("content.txt")));
26+
27+
// nuget.js is marked as content and the path to the file is "bin\{projectname}\content\web\js\nuget.js" so to the package they are two conflicting files.
2528
Assert.True(result.Logger.Errors.Any(e => e.Message.Contains("nuget.js")));
2629
}
2730
}

0 commit comments

Comments
 (0)