From cb471485a90a383d56b11a9391d2a878611ffc10 Mon Sep 17 00:00:00 2001 From: David Fowler Date: Sun, 8 Nov 2015 10:22:09 -0800 Subject: [PATCH] Change the line number for version conflcits - Use the project.json that caused the conflict --- .../Resolution/LibraryManager.cs | 38 ++++++++++++++++--- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.DotNet.ProjectModel/Resolution/LibraryManager.cs b/src/Microsoft.DotNet.ProjectModel/Resolution/LibraryManager.cs index 5a7287802..3f130563c 100644 --- a/src/Microsoft.DotNet.ProjectModel/Resolution/LibraryManager.cs +++ b/src/Microsoft.DotNet.ProjectModel/Resolution/LibraryManager.cs @@ -39,7 +39,7 @@ namespace Microsoft.Extensions.ProjectModel.Resolution } var dependencies = new Dictionary>(); - var topLevel = new List(); + var topLevel = new List(); foreach (var library in GetLibraries()) { @@ -101,7 +101,7 @@ namespace Microsoft.Extensions.ProjectModel.Resolution continue; } - topLevel.Add(library); + topLevel.Add(new LibraryItem(range, library)); // If we ended up with a declared version that isn't what was asked for directly // then report a warning @@ -129,8 +129,15 @@ namespace Microsoft.Extensions.ProjectModel.Resolution } // Version conflicts - foreach (var library in topLevel) + foreach (var libraryItem in topLevel) { + var library = libraryItem.Library; + + if (library.Identity.Type != LibraryType.Package) + { + continue; + } + List items; if (dependencies.TryGetValue(library.Identity.Name, out items)) { @@ -138,7 +145,7 @@ namespace Microsoft.Extensions.ProjectModel.Resolution { var versionRange = item.Dependency.VersionRange; - if (versionRange == null || item.Dependency.Target != LibraryType.Package) + if (versionRange == null) { continue; } @@ -150,10 +157,17 @@ namespace Microsoft.Extensions.ProjectModel.Resolution if (item.Library != library && !versionRange.Satisfies(library.Identity.Version)) { - var errorCode = ErrorCodes.NU1012; var message = $"Dependency conflict. {item.Library.Identity} expected {FormatLibraryRange(item.Dependency)} but got {library.Identity.Version}"; - AddDiagnostics(messages, item.Library, message, DiagnosticMessageSeverity.Warning, errorCode); + messages.Add( + new DiagnosticMessage( + ErrorCodes.NU1012, + message, + libraryItem.RequestedRange.SourceFilePath, + DiagnosticMessageSeverity.Warning, + libraryItem.RequestedRange.SourceLine, + libraryItem.RequestedRange.SourceColumn, + library)); } } } @@ -230,5 +244,17 @@ namespace Microsoft.Extensions.ProjectModel.Resolution Library = library; } } + + private struct LibraryItem + { + public LibraryRange RequestedRange { get; private set; } + public LibraryDescription Library { get; private set; } + + public LibraryItem(LibraryRange requestedRange, LibraryDescription library) + { + RequestedRange = requestedRange; + Library = library; + } + } } } \ No newline at end of file