Deduplicate libraries
This commit is contained in:
parent
4f1dbeba0e
commit
eb32a40ea2
9 changed files with 74 additions and 0 deletions
|
@ -0,0 +1 @@
|
|||
noautobuild
|
|
@ -0,0 +1,10 @@
|
|||
namespace TestApp
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
{
|
||||
"version": "1.0.0",
|
||||
"dependencies": {
|
||||
"TestLibrary": "1.0.0",
|
||||
"System.IO.Compression": "4.1.0-rc2-24027"
|
||||
},
|
||||
"frameworks": {
|
||||
"net461": {
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
noautobuild
|
|
@ -0,0 +1,10 @@
|
|||
namespace TestLibrary
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"version": "1.0.0",
|
||||
"frameworks": {
|
||||
"net461": {
|
||||
"frameworkAssemblies": {
|
||||
"System.IO.Compression": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
{ }
|
|
@ -497,6 +497,22 @@ namespace Microsoft.DotNet.ProjectModel
|
|||
dependencyDescription.Parents.Add(library);
|
||||
}
|
||||
}
|
||||
|
||||
// Deduplicate libraries with the same name
|
||||
// Priority list is backwards so not found -1 would be last when sorting by descending
|
||||
var priorities = new[] { LibraryType.Package, LibraryType.Project, LibraryType.ReferenceAssembly };
|
||||
var nameGroups = libraries.Keys.ToLookup(libraryKey => libraryKey.Name);
|
||||
foreach (var nameGroup in nameGroups)
|
||||
{
|
||||
var librariesToRemove = nameGroup
|
||||
.OrderByDescending(libraryKey => Array.IndexOf(priorities, libraryKey.LibraryType))
|
||||
.Skip(1);
|
||||
|
||||
foreach (var library in librariesToRemove)
|
||||
{
|
||||
libraries.Remove(library);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ScanLibraries(LockFileTarget target,
|
||||
|
|
|
@ -6,6 +6,7 @@ using Microsoft.DotNet.Tools.Test.Utilities;
|
|||
using NuGet.Frameworks;
|
||||
using NuGet.Versioning;
|
||||
using Xunit;
|
||||
using System.IO;
|
||||
|
||||
namespace Microsoft.DotNet.ProjectModel.Tests
|
||||
{
|
||||
|
@ -140,5 +141,18 @@ namespace Microsoft.DotNet.ProjectModel.Tests
|
|||
var diagnostics = context.LibraryManager.GetAllDiagnostics();
|
||||
Assert.False(diagnostics.Any(d => d.ErrorCode == ErrorCodes.DOTNET1011));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void NoDuplicatesWithProjectAndReferenceAssemblyWithSameName()
|
||||
{
|
||||
var instance = TestAssetsManager.CreateTestInstance("DuplicatedReferenceAssembly")
|
||||
.WithLockFiles();
|
||||
var context = new ProjectContextBuilder().WithProjectDirectory(Path.Combine(instance.TestRoot, "TestApp"))
|
||||
.WithTargetFramework("net461")
|
||||
.Build();
|
||||
|
||||
// Will fail with dupes if any
|
||||
context.LibraryManager.GetLibraries().ToDictionary(l => l.Identity.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue