diff --git a/src/Microsoft.DotNet.Cli.Utils/Command.cs b/src/Microsoft.DotNet.Cli.Utils/Command.cs index 083bd5139..e0eee974e 100644 --- a/src/Microsoft.DotNet.Cli.Utils/Command.cs +++ b/src/Microsoft.DotNet.Cli.Utils/Command.cs @@ -7,7 +7,6 @@ using System.Diagnostics; using System.IO; using System.Linq; using System.Runtime.CompilerServices; -using System.Threading.Tasks; using Microsoft.DotNet.ProjectModel; using NuGet.Frameworks; diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ICommandResolver.cs b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ICommandResolver.cs index 25b983598..363893d88 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ICommandResolver.cs +++ b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ICommandResolver.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace Microsoft.DotNet.Cli.Utils +namespace Microsoft.DotNet.Cli.Utils { public interface ICommandResolver { diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/IPackagedCommandSpecFactory.cs b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/IPackagedCommandSpecFactory.cs index 24e82fa6c..becf5b74f 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/IPackagedCommandSpecFactory.cs +++ b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/IPackagedCommandSpecFactory.cs @@ -1,5 +1,5 @@ using System.Collections.Generic; -using Microsoft.DotNet.ProjectModel.Graph; +using NuGet.ProjectModel; namespace Microsoft.DotNet.Cli.Utils { diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/PackagedCommandSpecFactory.cs b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/PackagedCommandSpecFactory.cs index 6842d3e13..393218a08 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/PackagedCommandSpecFactory.cs +++ b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/PackagedCommandSpecFactory.cs @@ -3,8 +3,8 @@ using System.Collections.Generic; using System.IO; using System.Linq; using Microsoft.DotNet.ProjectModel; -using Microsoft.DotNet.ProjectModel.Graph; using NuGet.Packaging; +using NuGet.ProjectModel; namespace Microsoft.DotNet.Cli.Utils { diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectDependenciesCommandResolver.cs b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectDependenciesCommandResolver.cs index 60bb1a87b..5742a9fb2 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectDependenciesCommandResolver.cs +++ b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectDependenciesCommandResolver.cs @@ -4,8 +4,8 @@ using System.IO; using System.Linq; using Microsoft.DotNet.InternalAbstractions; using Microsoft.DotNet.ProjectModel; -using Microsoft.DotNet.ProjectModel.Graph; using NuGet.Frameworks; +using NuGet.ProjectModel; namespace Microsoft.DotNet.Cli.Utils { diff --git a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectToolsCommandResolver.cs b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectToolsCommandResolver.cs index 753b079d0..853126359 100644 --- a/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectToolsCommandResolver.cs +++ b/src/Microsoft.DotNet.Cli.Utils/CommandResolution/ProjectToolsCommandResolver.cs @@ -4,11 +4,11 @@ using System.IO; using System.Linq; using Microsoft.DotNet.InternalAbstractions; using Microsoft.DotNet.ProjectModel; -using Microsoft.DotNet.ProjectModel.Graph; using Microsoft.Extensions.DependencyModel; using NuGet.Frameworks; +using NuGet.LibraryModel; +using NuGet.ProjectModel; using FileFormatException = Microsoft.DotNet.ProjectModel.FileFormatException; -using LockFile = Microsoft.DotNet.ProjectModel.Graph.LockFile; namespace Microsoft.DotNet.Cli.Utils { @@ -71,14 +71,14 @@ namespace Microsoft.DotNet.Cli.Utils } private CommandSpec ResolveCommandSpecFromAllToolLibraries( - IEnumerable toolsLibraries, + IEnumerable toolsLibraries, string commandName, IEnumerable args, ProjectContext projectContext) { foreach (var toolLibrary in toolsLibraries) { - var commandSpec = ResolveCommandSpecFromToolLibrary(toolLibrary, commandName, args, projectContext); + var commandSpec = ResolveCommandSpecFromToolLibrary(toolLibrary.LibraryRange, commandName, args, projectContext); if (commandSpec != null) { @@ -108,7 +108,7 @@ namespace Microsoft.DotNet.Cli.Utils return null; } - var depsFileRoot = Path.GetDirectoryName(lockFile.LockFilePath); + var depsFileRoot = Path.GetDirectoryName(lockFile.Path); var depsFilePath = GetToolDepsFilePath(toolLibraryRange, lockFile, depsFileRoot); return _packagedCommandSpecFactory.CreateCommandSpecFromLibrary( @@ -137,7 +137,7 @@ namespace Microsoft.DotNet.Cli.Utils try { - lockFile = LockFileReader.Read(lockFilePath, designTime: false); + lockFile = new LockFileFormat().Read(lockFilePath); } catch (FileFormatException ex) { diff --git a/src/Microsoft.DotNet.Cli.Utils/DepsJsonCommandFactory.cs b/src/Microsoft.DotNet.Cli.Utils/DepsJsonCommandFactory.cs index 55108f4f8..33f89529a 100644 --- a/src/Microsoft.DotNet.Cli.Utils/DepsJsonCommandFactory.cs +++ b/src/Microsoft.DotNet.Cli.Utils/DepsJsonCommandFactory.cs @@ -3,9 +3,6 @@ using System.Collections.Generic; using NuGet.Frameworks; -using System.IO; -using System; -using Microsoft.DotNet.ProjectModel; namespace Microsoft.DotNet.Cli.Utils { diff --git a/src/Microsoft.DotNet.Cli.Utils/InvalidProjectException.cs b/src/Microsoft.DotNet.Cli.Utils/InvalidProjectException.cs index c858f0301..ac3946b96 100644 --- a/src/Microsoft.DotNet.Cli.Utils/InvalidProjectException.cs +++ b/src/Microsoft.DotNet.Cli.Utils/InvalidProjectException.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; namespace Microsoft.DotNet.Cli.Utils { diff --git a/src/Microsoft.DotNet.Cli.Utils/Product.cs b/src/Microsoft.DotNet.Cli.Utils/Product.cs index 8d2a8f05b..7fe41776c 100644 --- a/src/Microsoft.DotNet.Cli.Utils/Product.cs +++ b/src/Microsoft.DotNet.Cli.Utils/Product.cs @@ -1,4 +1,3 @@ -using System; using System.Reflection; namespace Microsoft.DotNet.Cli.Utils diff --git a/src/Microsoft.DotNet.Cli.Utils/ScriptNames.cs b/src/Microsoft.DotNet.Cli.Utils/ScriptNames.cs index 41bece07c..18ac76f3e 100644 --- a/src/Microsoft.DotNet.Cli.Utils/ScriptNames.cs +++ b/src/Microsoft.DotNet.Cli.Utils/ScriptNames.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; - -namespace Microsoft.DotNet.Cli.Utils +namespace Microsoft.DotNet.Cli.Utils { public static class ScriptNames { diff --git a/src/Microsoft.DotNet.Cli.Utils/Tracing/PerfTraceOutput.cs b/src/Microsoft.DotNet.Cli.Utils/Tracing/PerfTraceOutput.cs index 2212efb14..403ee079b 100644 --- a/src/Microsoft.DotNet.Cli.Utils/Tracing/PerfTraceOutput.cs +++ b/src/Microsoft.DotNet.Cli.Utils/Tracing/PerfTraceOutput.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Linq; using System.Text; namespace Microsoft.DotNet.Cli.Utils diff --git a/src/Microsoft.DotNet.Compiler.Common/Executable.cs b/src/Microsoft.DotNet.Compiler.Common/Executable.cs index a3ee3544b..591cbf25e 100644 --- a/src/Microsoft.DotNet.Compiler.Common/Executable.cs +++ b/src/Microsoft.DotNet.Compiler.Common/Executable.cs @@ -5,18 +5,17 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using System.Xml.Linq; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Files; using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.ProjectModel.Compilation; using Microsoft.DotNet.ProjectModel.Files; -using Microsoft.DotNet.ProjectModel.Graph; using Microsoft.DotNet.Tools.Common; using Microsoft.Extensions.DependencyModel; using NuGet.Frameworks; using Newtonsoft.Json; using Newtonsoft.Json.Linq; +using NuGet.LibraryModel; namespace Microsoft.DotNet.Cli.Compiler.Common { diff --git a/src/Microsoft.DotNet.Compiler.Common/LibraryExporterExtensions.cs b/src/Microsoft.DotNet.Compiler.Common/LibraryExporterExtensions.cs index 8c5cfc355..7ae531785 100644 --- a/src/Microsoft.DotNet.Compiler.Common/LibraryExporterExtensions.cs +++ b/src/Microsoft.DotNet.Compiler.Common/LibraryExporterExtensions.cs @@ -4,9 +4,8 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; using Microsoft.DotNet.ProjectModel.Compilation; -using Microsoft.DotNet.ProjectModel.Graph; +using NuGet.LibraryModel; namespace Microsoft.DotNet.Cli.Compiler.Common { @@ -15,8 +14,7 @@ namespace Microsoft.DotNet.Cli.Compiler.Common public static IEnumerable GetAllProjectTypeDependencies(this LibraryExporter exporter) { return - exporter.GetDependencies(LibraryType.Project) - .Concat(exporter.GetDependencies(LibraryType.MSBuildProject)); + exporter.GetDependencies(LibraryType.Project); } public static void CopyTo(this IEnumerable assets, string destinationPath) diff --git a/src/Microsoft.DotNet.Compiler.Common/project.json b/src/Microsoft.DotNet.Compiler.Common/project.json index af2251b47..d527346ba 100644 --- a/src/Microsoft.DotNet.Compiler.Common/project.json +++ b/src/Microsoft.DotNet.Compiler.Common/project.json @@ -13,7 +13,8 @@ }, "Microsoft.DotNet.Files": { "target": "project" - } + }, + "NuGet.ProjectModel": "3.6.0-beta.1.msbuild.9" }, "frameworks": { "net451": { diff --git a/src/Microsoft.DotNet.ProjectJsonMigration/ProjectDependencyFinder.cs b/src/Microsoft.DotNet.ProjectJsonMigration/ProjectDependencyFinder.cs index 0fcd24896..4be944cae 100644 --- a/src/Microsoft.DotNet.ProjectJsonMigration/ProjectDependencyFinder.cs +++ b/src/Microsoft.DotNet.ProjectJsonMigration/ProjectDependencyFinder.cs @@ -8,9 +8,8 @@ using Microsoft.DotNet.ProjectModel; using System.Linq; using System.IO; using Newtonsoft.Json.Linq; -using Microsoft.DotNet.ProjectModel.Compilation; -using Microsoft.DotNet.ProjectModel.Graph; using Microsoft.DotNet.Tools.Common; +using NuGet.LibraryModel; namespace Microsoft.DotNet.ProjectJsonMigration { @@ -30,7 +29,9 @@ namespace Microsoft.DotNet.ProjectJsonMigration return ResolveProjectDependencies(projectContexts, ResolveXProjProjectDependencyNames(xproj)); } - public IEnumerable ResolveProjectDependencies(IEnumerable projectContexts, IEnumerable preResolvedProjects=null) + public IEnumerable ResolveProjectDependencies( + IEnumerable projectContexts, + IEnumerable preResolvedProjects=null) { foreach(var projectContext in projectContexts) { @@ -41,7 +42,9 @@ namespace Microsoft.DotNet.ProjectJsonMigration } } - public IEnumerable ResolveProjectDependencies(ProjectContext projectContext, IEnumerable preResolvedProjects=null) + public IEnumerable ResolveProjectDependencies( + ProjectContext projectContext, + IEnumerable preResolvedProjects=null) { preResolvedProjects = preResolvedProjects ?? new HashSet(); diff --git a/src/Microsoft.DotNet.ProjectModel/Compilation/LibraryExporter.cs b/src/Microsoft.DotNet.ProjectModel/Compilation/LibraryExporter.cs index f5682ef29..d9ead1959 100644 --- a/src/Microsoft.DotNet.ProjectModel/Compilation/LibraryExporter.cs +++ b/src/Microsoft.DotNet.ProjectModel/Compilation/LibraryExporter.cs @@ -3,16 +3,16 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.IO; using System.Linq; using Microsoft.DotNet.ProjectModel.Compilation.Preprocessor; using Microsoft.DotNet.ProjectModel.Files; -using Microsoft.DotNet.ProjectModel.Graph; using Microsoft.DotNet.ProjectModel.Resolution; using Microsoft.DotNet.ProjectModel.Utilities; using Microsoft.DotNet.Tools.Compiler; using NuGet.Frameworks; +using NuGet.LibraryModel; +using NuGet.ProjectModel; namespace Microsoft.DotNet.ProjectModel.Compilation { @@ -63,14 +63,14 @@ namespace Microsoft.DotNet.ProjectModel.Compilation /// public IEnumerable GetDependencies() { - return GetDependencies(LibraryType.Unspecified); + return GetDependencies(null); } /// /// Gets all exports required by the project, of the specified , NOT including the project itself /// /// - public IEnumerable GetDependencies(LibraryType type) + public IEnumerable GetDependencies(LibraryType? type) { // Export all but the main project return ExportLibraries(library => @@ -177,7 +177,7 @@ namespace Microsoft.DotNet.ProjectModel.Compilation } var libraryType = library.Identity.Type; - if (Equals(LibraryType.Package, libraryType) || Equals(LibraryType.MSBuildProject, libraryType)) + if (library is TargetLibraryWithAssets) { return ExportPackage((TargetLibraryWithAssets)library); } @@ -412,11 +412,12 @@ namespace Microsoft.DotNet.ProjectModel.Compilation var analyzers = package .PackageLibrary .Files - .Where(path => path.StartsWith("analyzers" + Path.DirectorySeparatorChar) && + .Where(path => path.StartsWith("analyzers" + LockFile.DirectorySeparatorChar) && path.EndsWith(".dll")); var analyzerRefs = new List(); + // See https://docs.nuget.org/create/analyzers-conventions for the analyzer // NuGet specification foreach (var analyzer in analyzers) @@ -499,9 +500,9 @@ namespace Microsoft.DotNet.ProjectModel.Compilation } } - private static bool LibraryIsOfType(LibraryType type, LibraryDescription library) + private static bool LibraryIsOfType(LibraryType? type, LibraryDescription library) { - return type.Equals(LibraryType.Unspecified) || // No type filter was requested + return type == null || // No type filter was requested library.Identity.Type.Equals(type); // OR, library type matches requested type } } diff --git a/src/Microsoft.DotNet.ProjectModel/DependencyContextBuilder.cs b/src/Microsoft.DotNet.ProjectModel/DependencyContextBuilder.cs index de63280d7..d59047c3b 100644 --- a/src/Microsoft.DotNet.ProjectModel/DependencyContextBuilder.cs +++ b/src/Microsoft.DotNet.ProjectModel/DependencyContextBuilder.cs @@ -9,10 +9,10 @@ using System.Security.Cryptography; using System.Text; using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.ProjectModel.Compilation; -using Microsoft.DotNet.ProjectModel.Graph; using Microsoft.DotNet.ProjectModel.Resolution; using Microsoft.DotNet.ProjectModel.Utilities; using NuGet.Frameworks; +using NuGet.LibraryModel; namespace Microsoft.Extensions.DependencyModel { @@ -153,7 +153,7 @@ namespace Microsoft.Extensions.DependencyModel else { IEnumerable assemblies; - if (type == LibraryType.ReferenceAssembly) + if (type == LibraryType.Reference) { assemblies = ResolveReferenceAssembliesPath(export.CompilationAssemblies); } diff --git a/src/Microsoft.DotNet.ProjectModel/DesignTimeWorkspace.cs b/src/Microsoft.DotNet.ProjectModel/DesignTimeWorkspace.cs index 307d76b35..33982fa2e 100644 --- a/src/Microsoft.DotNet.ProjectModel/DesignTimeWorkspace.cs +++ b/src/Microsoft.DotNet.ProjectModel/DesignTimeWorkspace.cs @@ -5,7 +5,7 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using Microsoft.DotNet.ProjectModel.Graph; +using NuGet.LibraryModel; namespace Microsoft.DotNet.ProjectModel { diff --git a/src/Microsoft.DotNet.ProjectModel/Graph/BuildAction.cs b/src/Microsoft.DotNet.ProjectModel/Graph/BuildAction.cs deleted file mode 100644 index 8d59abbb0..000000000 --- a/src/Microsoft.DotNet.ProjectModel/Graph/BuildAction.cs +++ /dev/null @@ -1,86 +0,0 @@ -// 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 System; -using System.Collections.Generic; - -namespace Microsoft.DotNet.ProjectModel.Graph -{ - public struct BuildAction : IEquatable - { - public static readonly BuildAction Compile = new BuildAction(nameof(Compile)); - public static readonly BuildAction EmbeddedResource = new BuildAction(nameof(EmbeddedResource)); - public static readonly BuildAction Resource = new BuildAction(nameof(Resource)); - - // Default value - public static readonly BuildAction None = new BuildAction(nameof(None)); - - public string Value { get; } - - private BuildAction(string value) - { - Value = value; - } - - public static bool TryParse(string value, out BuildAction type) - { - // We only support values we know about - if (string.Equals(Compile.Value, value, StringComparison.OrdinalIgnoreCase)) - { - type = Compile; - return true; - } - else if (string.Equals(EmbeddedResource.Value, value, StringComparison.OrdinalIgnoreCase)) - { - type = EmbeddedResource; - return true; - } - else if (string.Equals(Resource.Value, value, StringComparison.OrdinalIgnoreCase)) - { - type = Resource; - return true; - } - else if (string.Equals(None.Value, value, StringComparison.OrdinalIgnoreCase)) - { - type = None; - return true; - } - type = None; - return false; - } - - public override string ToString() - { - return $"BuildAction.{Value}"; - } - - public bool Equals(BuildAction other) - { - return string.Equals(other.Value, Value, StringComparison.OrdinalIgnoreCase); - } - - public override bool Equals(object obj) - { - return obj is BuildAction && Equals((BuildAction)obj); - } - - public static bool operator ==(BuildAction left, BuildAction right) - { - return Equals(left, right); - } - - public static bool operator !=(BuildAction left, BuildAction right) - { - return !Equals(left, right); - } - - public override int GetHashCode() - { - if (string.IsNullOrEmpty(Value)) - { - return 0; - } - return StringComparer.OrdinalIgnoreCase.GetHashCode(Value); - } - } -} \ No newline at end of file diff --git a/src/Microsoft.DotNet.ProjectModel/Graph/ExportFile.cs b/src/Microsoft.DotNet.ProjectModel/Graph/ExportFile.cs index 933742559..226bd0d5f 100644 --- a/src/Microsoft.DotNet.ProjectModel/Graph/ExportFile.cs +++ b/src/Microsoft.DotNet.ProjectModel/Graph/ExportFile.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Linq; +using NuGet.ProjectModel; namespace Microsoft.DotNet.ProjectModel.Graph { diff --git a/src/Microsoft.DotNet.ProjectModel/Graph/LibraryDependencyType.cs b/src/Microsoft.DotNet.ProjectModel/Graph/LibraryDependencyType.cs deleted file mode 100644 index e2ea7c2d7..000000000 --- a/src/Microsoft.DotNet.ProjectModel/Graph/LibraryDependencyType.cs +++ /dev/null @@ -1,32 +0,0 @@ -// 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 System; - -namespace Microsoft.DotNet.ProjectModel.Graph -{ - public struct LibraryDependencyType : IEquatable, IEquatable - { - public static LibraryDependencyType Empty = new LibraryDependencyType(); - public static LibraryDependencyType Default = new LibraryDependencyType("default"); - public static LibraryDependencyType Build = new LibraryDependencyType("build"); - public static LibraryDependencyType Platform = new LibraryDependencyType("platform"); - - public string Value { get; } - - private LibraryDependencyType(string value) - { - Value = value; - } - - public static LibraryDependencyType Parse(string value) => new LibraryDependencyType(value.ToLowerInvariant()); - - public override int GetHashCode() => Value.GetHashCode(); - - public override bool Equals(object obj) => obj is LibraryDependencyType && Equals((LibraryDependencyType)obj); - - public bool Equals(string other) => string.Equals(Value, other, StringComparison.Ordinal); - - public bool Equals(LibraryDependencyType other) => string.Equals(Value, other.Value, StringComparison.Ordinal); - } -} diff --git a/src/Microsoft.DotNet.ProjectModel/Graph/LibraryIdentity.cs b/src/Microsoft.DotNet.ProjectModel/Graph/LibraryIdentity.cs deleted file mode 100644 index 581974882..000000000 --- a/src/Microsoft.DotNet.ProjectModel/Graph/LibraryIdentity.cs +++ /dev/null @@ -1,80 +0,0 @@ -// 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 System; -using Microsoft.DotNet.PlatformAbstractions; -using NuGet.Versioning; - -namespace Microsoft.DotNet.ProjectModel.Graph -{ - public struct LibraryIdentity : IEquatable - { - public string Name { get; } - - public NuGetVersion Version { get; } - - public LibraryType Type { get; } - - public LibraryIdentity(string name, LibraryType type) - : this(name, null, type) - { } - - public LibraryIdentity(string name, NuGetVersion version, LibraryType type) - { - Name = name; - Version = version; - Type = type; - } - - public override string ToString() - { - return $"{Name} {Version?.ToString()}"; - } - - public bool Equals(LibraryIdentity other) - { - return string.Equals(Name, other.Name) && - Equals(Version, other.Version) && - Equals(Type, other.Type); - } - - public override bool Equals(object obj) - { - return obj is LibraryIdentity && Equals((LibraryIdentity)obj); - } - - public override int GetHashCode() - { - var combiner = HashCodeCombiner.Start(); - combiner.Add(Name); - combiner.Add(Version); - combiner.Add(Type); - return combiner.CombinedHash; - } - - public static bool operator ==(LibraryIdentity left, LibraryIdentity right) - { - return Equals(left, right); - } - - public static bool operator !=(LibraryIdentity left, LibraryIdentity right) - { - return !Equals(left, right); - } - - public LibraryRange ToLibraryRange() - { - return new LibraryRange(Name, CreateVersionRange(Version), Type, LibraryDependencyType.Default); - } - - private static VersionRange CreateVersionRange(NuGetVersion version) - { - return version == null ? null : new VersionRange(version, new FloatRange(NuGetVersionFloatBehavior.None)); - } - - public LibraryIdentity ChangeName(string name) - { - return new LibraryIdentity(name, Version, Type); - } - } -} diff --git a/src/Microsoft.DotNet.ProjectModel/Graph/LibraryRange.cs b/src/Microsoft.DotNet.ProjectModel/Graph/LibraryRange.cs deleted file mode 100644 index 77af3d1a0..000000000 --- a/src/Microsoft.DotNet.ProjectModel/Graph/LibraryRange.cs +++ /dev/null @@ -1,149 +0,0 @@ -// 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 System; -using System.Text; -using Microsoft.DotNet.PlatformAbstractions; -using NuGet.Versioning; - -namespace Microsoft.DotNet.ProjectModel.Graph -{ - public struct LibraryRange : IEquatable - { - public string Name { get; } - public VersionRange VersionRange { get; } - public LibraryType Target { get; } - public LibraryDependencyType Type { get; } - - public string SourceFilePath { get; } - public int SourceLine { get; } - public int SourceColumn { get; } - - public LibraryRange(string name, LibraryType target) - : this(name, null, target, LibraryDependencyType.Default, sourceFilePath: string.Empty, sourceLine: 0, sourceColumn: 0) - { } - - public LibraryRange(string name, LibraryType target, LibraryDependencyType type) - : this(name, null, target, type, sourceFilePath: string.Empty, sourceLine: 0, sourceColumn: 0) - { } - - public LibraryRange(string name, VersionRange versionRange, LibraryType target, LibraryDependencyType type) - : this(name, versionRange, target, type, sourceFilePath: string.Empty, sourceLine: 0, sourceColumn: 0) - { } - - public LibraryRange(string name, VersionRange versionRange, LibraryType target, LibraryDependencyType type, string sourceFilePath, int sourceLine, int sourceColumn) - { - Name = name; - VersionRange = versionRange; - Target = target; - Type = type; - SourceFilePath = sourceFilePath; - SourceLine = sourceLine; - SourceColumn = sourceColumn; - } - - public bool Equals(LibraryRange other) - { - return string.Equals(other.Name, Name, StringComparison.OrdinalIgnoreCase) && - Equals(VersionRange, other.VersionRange) && - Equals(Target, other.Target) && - Equals(Type, other.Type); - // SourceFilePath, SourceLine, SourceColumn are irrelevant for equality, they are diagnostic - } - - public override bool Equals(object obj) - { - return obj is LibraryRange && Equals((LibraryRange)obj); - } - - public static bool operator ==(LibraryRange left, LibraryRange right) - { - return Equals(left, right); - } - - public static bool operator !=(LibraryRange left, LibraryRange right) - { - return !Equals(left, right); - } - - public override int GetHashCode() - { - var combiner = HashCodeCombiner.Start(); - combiner.Add(Name); - combiner.Add(VersionRange); - combiner.Add(Target); - combiner.Add(Type); - return combiner.CombinedHash; - } - - public override string ToString() - { - var sb = new StringBuilder(); - sb.Append(Name); - - if (VersionRange != null) - { - sb.Append(" "); - sb.Append(VersionRange); - } - - if (!Equals(Type, LibraryDependencyType.Default)) - { - sb.Append(" ("); - sb.Append(Type); - sb.Append(")"); - } - - if (!Equals(Target, LibraryType.Unspecified)) - { - sb.Append(" (Target: "); - sb.Append(Target); - sb.Append(")"); - } - - return sb.ToString(); - } - - public string ToLockFileDependencyGroupString() - { - var sb = new StringBuilder(); - sb.Append(Name); - - if (VersionRange != null) - { - if (VersionRange.HasLowerBound) - { - sb.Append(" "); - - if (VersionRange.IsMinInclusive) - { - sb.Append(">= "); - } - else - { - sb.Append("> "); - } - - if (VersionRange.IsFloating) - { - sb.Append(VersionRange.Float.ToString()); - } - else - { - sb.Append(VersionRange.MinVersion.ToNormalizedString()); - } - } - - if (VersionRange.HasUpperBound) - { - sb.Append(" "); - - sb.Append(VersionRange.IsMaxInclusive ? "<= " : "< "); - sb.Append(VersionRange.MaxVersion.ToNormalizedString()); - } - } - - return sb.ToString(); - } - } -} \ No newline at end of file diff --git a/src/Microsoft.DotNet.ProjectModel/Graph/LibraryType.cs b/src/Microsoft.DotNet.ProjectModel/Graph/LibraryType.cs deleted file mode 100644 index 4a18dccbe..000000000 --- a/src/Microsoft.DotNet.ProjectModel/Graph/LibraryType.cs +++ /dev/null @@ -1,95 +0,0 @@ -// 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 System; -using System.Collections.Generic; - -namespace Microsoft.DotNet.ProjectModel.Graph -{ - public struct LibraryType : IEquatable - { - public static readonly LibraryType Package = new LibraryType(nameof(Package)); - public static readonly LibraryType Project = new LibraryType(nameof(Project)); - public static readonly LibraryType ReferenceAssembly = new LibraryType(nameof(ReferenceAssembly)); - public static readonly LibraryType MSBuildProject = new LibraryType(nameof(MSBuildProject)); - - // Default value - public static readonly LibraryType Unspecified = new LibraryType(); - - public string Value { get; } - - - private LibraryType(string value) - { - Value = value; - } - - public static bool TryParse(string value, out LibraryType type) - { - // We only support values we know about - if (string.Equals(Package.Value, value, StringComparison.OrdinalIgnoreCase)) - { - type = Package; - return true; - } - else if (string.Equals(Project.Value, value, StringComparison.OrdinalIgnoreCase)) - { - type = Project; - return true; - } - type = Unspecified; - return false; - } - - public override string ToString() - { - return Value ?? nameof(Unspecified); - } - - public bool CanSatisfyConstraint(LibraryType constraint) - { - // Reference assemblies must be explicitly asked for - if (Equals(ReferenceAssembly, constraint)) - { - return Equals(ReferenceAssembly, this); - } - else if (Equals(constraint, Unspecified)) - { - return true; - } - else - { - return string.Equals(constraint.Value, Value, StringComparison.OrdinalIgnoreCase); - } - } - - public bool Equals(LibraryType other) - { - return string.Equals(other.Value, Value, StringComparison.OrdinalIgnoreCase); - } - - public override bool Equals(object obj) - { - return obj is LibraryType && Equals((LibraryType)obj); - } - - public static bool operator ==(LibraryType left, LibraryType right) - { - return Equals(left, right); - } - - public static bool operator !=(LibraryType left, LibraryType right) - { - return !Equals(left, right); - } - - public override int GetHashCode() - { - if (string.IsNullOrEmpty(Value)) - { - return 0; - } - return StringComparer.OrdinalIgnoreCase.GetHashCode(Value); - } - } -} \ No newline at end of file diff --git a/src/Microsoft.DotNet.ProjectModel/Graph/LockFile.cs b/src/Microsoft.DotNet.ProjectModel/Graph/LockFileExtensions.cs similarity index 53% rename from src/Microsoft.DotNet.ProjectModel/Graph/LockFile.cs rename to src/Microsoft.DotNet.ProjectModel/Graph/LockFileExtensions.cs index ab3355426..be97d3de8 100644 --- a/src/Microsoft.DotNet.ProjectModel/Graph/LockFile.cs +++ b/src/Microsoft.DotNet.ProjectModel/Graph/LockFileExtensions.cs @@ -1,41 +1,22 @@ -// 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 System; -using System.Collections.Generic; using System.Linq; +using NuGet.ProjectModel; namespace Microsoft.DotNet.ProjectModel.Graph { - public class LockFile + public static class LockFileExtensions { public static readonly int CurrentVersion = 2; - public static readonly string FileName = "project.lock.json"; - public string LockFilePath { get; } - - public int Version { get; set; } - public IList ProjectFileDependencyGroups { get; set; } = new List(); - public IList PackageLibraries { get; set; } = new List(); - public IList ProjectLibraries { get; set; } = new List(); - public IList Targets { get; set; } = new List(); - public ExportFile ExportFile { get; set; } - public IList PackageFolders { get; set; } = new List(); - - public LockFile(string lockFilePath) - { - LockFilePath = lockFilePath; - } - - public bool IsValidForProject(Project project) + public static bool IsValidForProject(this LockFile lockFile, Project project) { string message; - return IsValidForProject(project, out message); + return lockFile.IsValidForProject(project, out message); } - public bool IsValidForProject(Project project, out string message) + public static bool IsValidForProject(this LockFile lockFile, Project project, out string message) { - if (Version != CurrentVersion) + if (lockFile.Version != CurrentVersion) { message = $"The expected lock file version does not match the actual version"; return false; @@ -46,12 +27,12 @@ namespace Microsoft.DotNet.ProjectModel.Graph var actualTargetFrameworks = project.GetTargetFrameworks(); // The lock file should contain dependencies for each framework plus dependencies shared by all frameworks - if (ProjectFileDependencyGroups.Count != actualTargetFrameworks.Count() + 1) + if (lockFile.ProjectFileDependencyGroups.Count != actualTargetFrameworks.Count() + 1) { return false; } - foreach (var group in ProjectFileDependencyGroups) + foreach (var group in lockFile.ProjectFileDependencyGroups) { IOrderedEnumerable actualDependencies; var expectedDependencies = group.Dependencies.OrderBy(x => x); @@ -60,7 +41,7 @@ namespace Microsoft.DotNet.ProjectModel.Graph if (group.FrameworkName == null) { actualDependencies = project.Dependencies - .Select(d => d.ToLockFileDependencyGroupString()) + .Select(d => d.LibraryRange.ToLockFileDependencyGroupString()) .OrderBy(x => x, StringComparer.OrdinalIgnoreCase); } else @@ -73,7 +54,7 @@ namespace Microsoft.DotNet.ProjectModel.Graph } actualDependencies = framework.Dependencies - .Select(d => d.ToLockFileDependencyGroupString()) + .Select(d => d.LibraryRange.ToLockFileDependencyGroupString()) .OrderBy(x => x, StringComparer.OrdinalIgnoreCase); } diff --git a/src/Microsoft.DotNet.ProjectModel/Graph/LockFileItem.cs b/src/Microsoft.DotNet.ProjectModel/Graph/LockFileItem.cs deleted file mode 100644 index fcd040ede..000000000 --- a/src/Microsoft.DotNet.ProjectModel/Graph/LockFileItem.cs +++ /dev/null @@ -1,35 +0,0 @@ -// 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 System.Collections.Generic; - -namespace Microsoft.DotNet.ProjectModel.Graph -{ - public class LockFileItem - { - public LockFileItem() - { - Properties = new Dictionary();; - } - - public LockFileItem(string path) : this() - { - Path = path; - } - - public LockFileItem(string path, IDictionary properties) : this(path) - { - Properties = new Dictionary(properties); - } - - public string Path { get; set; } - - public IDictionary Properties { get; } - - public static implicit operator string (LockFileItem item) => item.Path; - - public static implicit operator LockFileItem(string path) => new LockFileItem { Path = path }; - - public override string ToString() => Path; - } -} diff --git a/src/Microsoft.DotNet.ProjectModel/Graph/LockFileLookup.cs b/src/Microsoft.DotNet.ProjectModel/Graph/LockFileLookup.cs index f76af2fa3..4939f2f49 100644 --- a/src/Microsoft.DotNet.ProjectModel/Graph/LockFileLookup.cs +++ b/src/Microsoft.DotNet.ProjectModel/Graph/LockFileLookup.cs @@ -3,6 +3,8 @@ using System; using System.Collections.Generic; +using NuGet.LibraryModel; +using NuGet.ProjectModel; using NuGet.Versioning; namespace Microsoft.DotNet.ProjectModel.Graph @@ -10,28 +12,32 @@ namespace Microsoft.DotNet.ProjectModel.Graph public class LockFileLookup { // REVIEW: Case sensitivity? - private readonly Dictionary, LockFilePackageLibrary> _packages; - private readonly Dictionary _projects; + private readonly Dictionary, LockFileLibrary> _packages; + private readonly Dictionary _projects; public LockFileLookup(LockFile lockFile) { - _packages = new Dictionary, LockFilePackageLibrary>(); - _projects = new Dictionary(); + _packages = new Dictionary, LockFileLibrary>(); + _projects = new Dictionary(); - foreach (var library in lockFile.PackageLibraries) + foreach (var library in lockFile.Libraries) { - _packages[Tuple.Create(library.Name, library.Version)] = library; - } + var libraryType = LibraryType.Parse(library.Type); - foreach (var libary in lockFile.ProjectLibraries) - { - _projects[libary.Name] = libary; + if (libraryType == LibraryType.Package) + { + _packages[Tuple.Create(library.Name, library.Version)] = library; + } + if (libraryType == LibraryType.Project) + { + _projects[library.Name] = library; + } } } - public LockFileProjectLibrary GetProject(string name) + public LockFileLibrary GetProject(string name) { - LockFileProjectLibrary project; + LockFileLibrary project; if (_projects.TryGetValue(name, out project)) { return project; @@ -40,9 +46,9 @@ namespace Microsoft.DotNet.ProjectModel.Graph return null; } - public LockFilePackageLibrary GetPackage(string id, NuGetVersion version) + public LockFileLibrary GetPackage(string id, NuGetVersion version) { - LockFilePackageLibrary package; + LockFileLibrary package; if (_packages.TryGetValue(Tuple.Create(id, version), out package)) { return package; diff --git a/src/Microsoft.DotNet.ProjectModel/Graph/LockFilePackageFolder.cs b/src/Microsoft.DotNet.ProjectModel/Graph/LockFilePackageFolder.cs deleted file mode 100644 index fc77a453f..000000000 --- a/src/Microsoft.DotNet.ProjectModel/Graph/LockFilePackageFolder.cs +++ /dev/null @@ -1,10 +0,0 @@ -// 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. - -namespace Microsoft.DotNet.ProjectModel.Graph -{ - public class LockFilePackageFolder - { - public string Path { get; set; } - } -} \ No newline at end of file diff --git a/src/Microsoft.DotNet.ProjectModel/Graph/LockFilePackageLibrary.cs b/src/Microsoft.DotNet.ProjectModel/Graph/LockFilePackageLibrary.cs deleted file mode 100644 index 16504536a..000000000 --- a/src/Microsoft.DotNet.ProjectModel/Graph/LockFilePackageLibrary.cs +++ /dev/null @@ -1,23 +0,0 @@ -// 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 System.Collections.Generic; -using NuGet.Versioning; - -namespace Microsoft.DotNet.ProjectModel.Graph -{ - public class LockFilePackageLibrary - { - public string Name { get; set; } - - public NuGetVersion Version { get; set; } - - public bool IsServiceable { get; set; } - - public string Sha512 { get; set; } - - public IList Files { get; set; } = new List(); - - public string Path { get; set; } - } -} diff --git a/src/Microsoft.DotNet.ProjectModel/Graph/LockFilePatcher.cs b/src/Microsoft.DotNet.ProjectModel/Graph/LockFilePatcher.cs deleted file mode 100644 index 9c8956964..000000000 --- a/src/Microsoft.DotNet.ProjectModel/Graph/LockFilePatcher.cs +++ /dev/null @@ -1,132 +0,0 @@ -// 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 System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Microsoft.DotNet.ProjectModel.Resolution; - -namespace Microsoft.DotNet.ProjectModel.Graph -{ - public class LockFilePatcher - { - private readonly LockFile _lockFile; - private Dictionary> _msbuildTargetLibraries; - private readonly LockFileReader _reader; - - public LockFilePatcher(LockFile lockFile, LockFileReader reader) - { - _lockFile = lockFile; - _reader = reader; - - var msbuildProjectLibraries = lockFile.ProjectLibraries.Where(MSBuildDependencyProvider.IsMSBuildProjectLibrary); - _msbuildTargetLibraries = msbuildProjectLibraries.ToDictionary( - GetProjectLibraryKey, - l => GetTargetsForLibrary(_lockFile, l), - StringComparer.OrdinalIgnoreCase); - } - - public void Patch() - { - var exportFilePath = GetExportFilePath(_lockFile.LockFilePath); - if (File.Exists(exportFilePath) && _msbuildTargetLibraries.Any()) - { - var exportFile = _reader.ReadExportFile(exportFilePath); - PatchLockWithExport(exportFile); - } - else - { - ThrowIfAnyMsbuildLibrariesPresent(); - } - } - - public void ThrowIfAnyMsbuildLibrariesPresent() - { - if (_msbuildTargetLibraries.Any()) - { - throw new LockFilePatchingException($"Lock file {_lockFile} contains msbuild projects but there is no export file"); - } - } - - private void PatchLockWithExport(ExportFile exportFile) - { - if (_lockFile.Version != exportFile.Version) - { - throw new LockFilePatchingException($"Export file {exportFile.ExportFilePath} has a different version than the lock file {_lockFile.LockFilePath}"); - } - - var exportDict = exportFile.Exports.ToDictionary(GetTargetLibraryKey, StringComparer.OrdinalIgnoreCase); - - var uncoveredLibraries = _msbuildTargetLibraries.Keys.Except(exportDict.Keys); - if (uncoveredLibraries.Any()) - { - throw new LockFilePatchingException($"Export {exportFile.ExportFilePath} does not provide exports for all the msbuild projects in {_lockFile.LockFilePath}"); - } - - foreach(var exportKey in exportDict.Keys) - { - var export = exportDict[exportKey]; - var librariesToPatch = _msbuildTargetLibraries[exportKey]; - - foreach (var libraryToPatch in librariesToPatch) - { - Patch(libraryToPatch, export); - } - } - - _lockFile.ExportFile = exportFile; - } - - private static void Patch(LockFileTargetLibrary libraryToPatch, LockFileTargetLibrary export) - { - libraryToPatch.CompileTimeAssemblies = export.CompileTimeAssemblies; - libraryToPatch.ContentFiles = export.ContentFiles; - libraryToPatch.FrameworkAssemblies = export.FrameworkAssemblies; - libraryToPatch.NativeLibraries = export.NativeLibraries; - libraryToPatch.ResourceAssemblies = export.ResourceAssemblies; - libraryToPatch.RuntimeAssemblies = export.RuntimeAssemblies; - } - - private static IList GetTargetsForLibrary(LockFile lockFile, LockFileProjectLibrary library) - { - return lockFile.Targets - .SelectMany( - t => t.Libraries - .Where( - l => string.Equals(GetProjectLibraryKey(library), (GetTargetLibraryKey(l))) - ) - ) - .ToList(); - } - - private static object TypeName(LockFileTargetLibrary library) - { - return library.Name + "/" + library.Version + "/" + library.Type; - } - - private static string GetTargetLibraryKey(LockFileTargetLibrary library) - { - return library.Name + "/" + library.Version; - } - - private static string GetProjectLibraryKey(LockFileProjectLibrary library) - { - return library.Name + "/" + library.Version; - } - - private static string GetExportFilePath(string masterLockFilePath) - { - var parentDirectory = Directory.GetParent(masterLockFilePath).FullName; - return Path.Combine(parentDirectory, ExportFile.ExportFileName); - } - } - - internal class LockFilePatchingException : Exception - { - public LockFilePatchingException(string message) : base(message) - { - } - } - -} diff --git a/src/Microsoft.DotNet.ProjectModel/Graph/LockFileProjectLibrary.cs b/src/Microsoft.DotNet.ProjectModel/Graph/LockFileProjectLibrary.cs deleted file mode 100644 index bdc459235..000000000 --- a/src/Microsoft.DotNet.ProjectModel/Graph/LockFileProjectLibrary.cs +++ /dev/null @@ -1,18 +0,0 @@ -// 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 NuGet.Versioning; - -namespace Microsoft.DotNet.ProjectModel.Graph -{ - public class LockFileProjectLibrary - { - public string Name { get; set; } - - public NuGetVersion Version { get; set; } - - public string Path { get; set; } - - public string MSBuildProject { get; set; } - } -} \ No newline at end of file diff --git a/src/Microsoft.DotNet.ProjectModel/Graph/LockFileReader.cs b/src/Microsoft.DotNet.ProjectModel/Graph/LockFileReader.cs deleted file mode 100644 index 153fbb3ba..000000000 --- a/src/Microsoft.DotNet.ProjectModel/Graph/LockFileReader.cs +++ /dev/null @@ -1,417 +0,0 @@ -// 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 System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using Microsoft.DotNet.ProjectModel.Utilities; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using NuGet.Frameworks; -using NuGet.Packaging.Core; -using NuGet.Versioning; - -namespace Microsoft.DotNet.ProjectModel.Graph -{ - public class LockFileReader - { - private readonly LockFileSymbolTable _symbols; - - public LockFileReader() : this(new LockFileSymbolTable()) { } - - public LockFileReader(LockFileSymbolTable symbols) - { - _symbols = symbols; - } - - public static LockFile Read(string lockFilePath, bool designTime) - { - using (var stream = ResilientFileStreamOpener.OpenFile(lockFilePath)) - { - try - { - return new LockFileReader().ReadLockFile(lockFilePath, stream, designTime); - } - catch (FileFormatException ex) - { - throw ex.WithFilePath(lockFilePath); - } - catch (Exception ex) - { - throw FileFormatException.Create(ex, lockFilePath); - } - } - } - - public LockFile ReadLockFile(string lockFilePath, Stream stream, bool designTime) - { - try - { - var reader = new StreamReader(stream); - var jobject = JObject.Load(new JsonTextReader(reader)); - - if (jobject == null) - { - throw new InvalidDataException(); - } - - var lockFile = ReadLockFile(lockFilePath, jobject); - - if (!designTime) - { - var patcher = new LockFilePatcher(lockFile, this); - patcher.Patch(); - } - - return lockFile; - } - catch (LockFilePatchingException) - { - throw; - } - catch - { - // Ran into parsing errors, mark it as unlocked and out-of-date - return new LockFile(lockFilePath) - { - Version = int.MinValue - }; - } - } - - public ExportFile ReadExportFile(string fragmentLockFilePath) - { - using (var stream = ResilientFileStreamOpener.OpenFile(fragmentLockFilePath)) - { - try - { - var rootJObject = JObject.ReadFrom(new JsonTextReader(new StreamReader(stream))) as JObject; - - if (rootJObject == null) - { - throw new InvalidDataException(); - } - - var version = ReadInt(rootJObject, "version", defaultValue: int.MinValue); - var exports = ReadObject(rootJObject.Value("exports"), ReadTargetLibrary); - - return new ExportFile(fragmentLockFilePath, version, exports); - - } - catch (FileFormatException ex) - { - throw ex.WithFilePath(fragmentLockFilePath); - } - catch (Exception ex) - { - throw FileFormatException.Create(ex, fragmentLockFilePath); - } - } - } - - private LockFile ReadLockFile(string lockFilePath, JObject cursor) - { - var lockFile = new LockFile(lockFilePath); - lockFile.Version = ReadInt(cursor, "version", defaultValue: int.MinValue); - lockFile.Targets = ReadObject(cursor.Value("targets"), ReadTarget); - lockFile.ProjectFileDependencyGroups = ReadObject(cursor.Value("projectFileDependencyGroups"), ReadProjectFileDependencyGroup); - ReadLibrary(cursor.Value("libraries"), lockFile); - lockFile.PackageFolders = ReadObject(cursor.Value("packageFolders"), ReadPackageFolder); - - return lockFile; - } - - private void ReadLibrary(JObject json, LockFile lockFile) - { - if (json == null) - { - return; - } - - foreach (var child in json) - { - var key = child.Key; - var value = json.Value(key); - if (value == null) - { - throw FileFormatException.Create("The value type is not object.", json[key]); - } - - var parts = key.Split(new[] { '/' }, 2); - var name = parts[0]; - var version = parts.Length == 2 ? _symbols.GetVersion(parts[1]) : null; - - var type = _symbols.GetString(value.Value("type")); - - var pathValue = value["path"]; - var path = pathValue == null ? null : ReadString(pathValue); - - if (type == null || string.Equals(type, "package", StringComparison.OrdinalIgnoreCase)) - { - lockFile.PackageLibraries.Add(new LockFilePackageLibrary - { - Name = name, - Version = version, - IsServiceable = ReadBool(value, "serviceable", defaultValue: false), - Sha512 = ReadString(value["sha512"]), - Files = ReadPathArray(value["files"], ReadString), - Path = path - }); - } - else if (type == "project") - { - var projectLibrary = new LockFileProjectLibrary - { - Name = name, - Version = version - }; - - projectLibrary.Path = path; - - var buildTimeDependencyValue = value["msbuildProject"]; - projectLibrary.MSBuildProject = buildTimeDependencyValue == null ? null : ReadString(buildTimeDependencyValue); - - lockFile.ProjectLibraries.Add(projectLibrary); - } - } - } - - private LockFileTarget ReadTarget(string property, JToken json) - { - var jobject = json as JObject; - if (jobject == null) - { - throw FileFormatException.Create("The value type is not an object.", json); - } - - var target = new LockFileTarget(); - var parts = property.Split(new[] { '/' }, 2); - target.TargetFramework = _symbols.GetFramework(parts[0]); - if (parts.Length == 2) - { - target.RuntimeIdentifier = _symbols.GetString(parts[1]); - } - - target.Libraries = ReadObject(jobject, ReadTargetLibrary); - - return target; - } - - private LockFilePackageFolder ReadPackageFolder(string property, JToken json) - { - var jobject = json as JObject; - if (jobject == null) - { - throw FileFormatException.Create("The value type is not an object.", json); - } - - var packageFolder = new LockFilePackageFolder(); - packageFolder.Path = property; - - return packageFolder; - } - - private LockFileTargetLibrary ReadTargetLibrary(string property, JToken json) - { - var jobject = json as JObject; - if (jobject == null) - { - throw FileFormatException.Create("The value type is not an object.", json); - } - - var library = new LockFileTargetLibrary(); - - var parts = property.Split(new[] { '/' }, 2); - library.Name = _symbols.GetString(parts[0]); - if (parts.Length == 2) - { - library.Version = _symbols.GetVersion(parts[1]); - } - - library.Type = _symbols.GetString(jobject.Value("type")); - var framework = jobject.Value("framework"); - if (framework != null) - { - library.TargetFramework = _symbols.GetFramework(framework); - } - - library.Dependencies = ReadObject(jobject.Value("dependencies"), ReadPackageDependency); - library.FrameworkAssemblies = new HashSet(ReadArray(jobject["frameworkAssemblies"], ReadFrameworkAssemblyReference), StringComparer.OrdinalIgnoreCase); - library.RuntimeAssemblies = ReadObject(jobject.Value("runtime"), ReadFileItem); - library.CompileTimeAssemblies = ReadObject(jobject.Value("compile"), ReadFileItem); - library.ResourceAssemblies = ReadObject(jobject.Value("resource"), ReadFileItem); - library.NativeLibraries = ReadObject(jobject.Value("native"), ReadFileItem); - library.ContentFiles = ReadObject(jobject.Value("contentFiles"), ReadContentFile); - library.RuntimeTargets = ReadObject(jobject.Value("runtimeTargets"), ReadRuntimeTarget); - - return library; - } - - private LockFileRuntimeTarget ReadRuntimeTarget(string property, JToken json) - { - var jsonObject = json as JObject; - if (jsonObject == null) - { - throw FileFormatException.Create("The value type is not an object.", json); - } - - return new LockFileRuntimeTarget( - path: _symbols.GetString(property), - runtime: _symbols.GetString(jsonObject.Value("rid")), - assetType: _symbols.GetString(jsonObject.Value("assetType")) - ); - } - - private LockFileContentFile ReadContentFile(string property, JToken json) - { - var contentFile = new LockFileContentFile() - { - Path = property - }; - - var jsonObject = json as JObject; - if (jsonObject != null) - { - - BuildAction action; - BuildAction.TryParse(jsonObject.Value("buildAction"), out action); - - contentFile.BuildAction = action; - var codeLanguage = _symbols.GetString(jsonObject.Value("codeLanguage")); - if (codeLanguage == "any") - { - codeLanguage = null; - } - contentFile.CodeLanguage = codeLanguage; - contentFile.OutputPath = jsonObject.Value("outputPath"); - contentFile.PPOutputPath = jsonObject.Value("ppOutputPath"); - contentFile.CopyToOutput = ReadBool(jsonObject, "copyToOutput", false); - } - - return contentFile; - } - - private ProjectFileDependencyGroup ReadProjectFileDependencyGroup(string property, JToken json) - { - return new ProjectFileDependencyGroup( - string.IsNullOrEmpty(property) ? null : NuGetFramework.Parse(property), - ReadArray(json, ReadString)); - } - - private PackageDependency ReadPackageDependency(string property, JToken json) - { - var versionStr = ReadString(json); - return new PackageDependency( - _symbols.GetString(property), - versionStr == null ? null : _symbols.GetVersionRange(versionStr)); - } - - private LockFileItem ReadFileItem(string property, JToken json) - { - var item = new LockFileItem { Path = _symbols.GetString(PathUtility.GetPathWithDirectorySeparator(property)) }; - var jobject = json as JObject; - - if (jobject != null) - { - foreach (var child in jobject) - { - item.Properties[_symbols.GetString(child.Key)] = jobject.Value(child.Key); - } - } - return item; - } - - private string ReadFrameworkAssemblyReference(JToken json) - { - return ReadString(json); - } - - private static IList ReadArray(JToken json, Func readItem) - { - if (json == null) - { - return new List(); - } - - var jarray = json as JArray; - if (jarray == null) - { - throw FileFormatException.Create("The value type is not array.", json); - } - - var items = new List(); - for (int i = 0; i < jarray.Count; ++i) - { - items.Add(readItem(jarray[i])); - } - return items; - } - - private IList ReadPathArray(JToken json, Func readItem) - { - return ReadArray(json, readItem).Select(f => _symbols.GetString(PathUtility.GetPathWithDirectorySeparator(f))).ToList(); - } - - private static IList ReadObject(JObject json, Func readItem) - { - if (json == null) - { - return new List(); - } - var items = new List(); - foreach (var child in json) - { - items.Add(readItem(child.Key, json[child.Key])); - } - return items; - } - - private static bool ReadBool(JObject cursor, string property, bool defaultValue) - { - var valueToken = cursor[property] as JValue; - if (valueToken == null || valueToken.Type != JTokenType.Boolean) - { - return defaultValue; - } - - return (bool)valueToken.Value; - } - - private static int ReadInt(JObject cursor, string property, int defaultValue) - { - var number = cursor[property] as JValue; - if (number == null || number.Type != JTokenType.Integer) - { - return defaultValue; - } - - try - { - var resultInInt = Convert.ToInt32(number.Value); - return resultInInt; - } - catch (Exception ex) - { - // FormatException or OverflowException - throw FileFormatException.Create(ex, cursor); - } - } - - private string ReadString(JToken json) - { - if (json.Type == JTokenType.String) - { - return _symbols.GetString(json.ToString()); - } - else if (json.Type == JTokenType.Null) - { - return null; - } - else - { - throw FileFormatException.Create("The value type is not string.", json); - } - } - } -} diff --git a/src/Microsoft.DotNet.ProjectModel/Graph/LockFileRuntimeTarget.cs b/src/Microsoft.DotNet.ProjectModel/Graph/LockFileRuntimeTarget.cs deleted file mode 100644 index 2573c1680..000000000 --- a/src/Microsoft.DotNet.ProjectModel/Graph/LockFileRuntimeTarget.cs +++ /dev/null @@ -1,21 +0,0 @@ -// 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. - -namespace Microsoft.DotNet.ProjectModel.Graph -{ - public class LockFileRuntimeTarget - { - public LockFileRuntimeTarget(string path, string runtime, string assetType) - { - Path = path; - Runtime = runtime; - AssetType = assetType; - } - - public string Path { get; } - - public string Runtime { get; } - - public string AssetType { get; } - } -} \ No newline at end of file diff --git a/src/Microsoft.DotNet.ProjectModel/Graph/LockFileSymbolTable.cs b/src/Microsoft.DotNet.ProjectModel/Graph/LockFileSymbolTable.cs deleted file mode 100644 index a81da4530..000000000 --- a/src/Microsoft.DotNet.ProjectModel/Graph/LockFileSymbolTable.cs +++ /dev/null @@ -1,23 +0,0 @@ -// 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 System; -using System.Collections.Concurrent; -using NuGet.Frameworks; -using NuGet.Versioning; - -namespace Microsoft.DotNet.ProjectModel.Graph -{ - public class LockFileSymbolTable - { - private ConcurrentDictionary _versionTable = new ConcurrentDictionary(Environment.ProcessorCount * 4, 1000, StringComparer.Ordinal); - private ConcurrentDictionary _versionRangeTable = new ConcurrentDictionary(Environment.ProcessorCount * 4, 1000, StringComparer.Ordinal); - private ConcurrentDictionary _frameworksTable = new ConcurrentDictionary(Environment.ProcessorCount * 4, 1000, StringComparer.Ordinal); - private ConcurrentDictionary _stringsTable = new ConcurrentDictionary(Environment.ProcessorCount * 4, 1000, StringComparer.Ordinal); - - public NuGetVersion GetVersion(string versionString) => _versionTable.GetOrAdd(versionString, (s) => NuGetVersion.Parse(s)); - public VersionRange GetVersionRange(string versionRangeString) => _versionRangeTable.GetOrAdd(versionRangeString, (s) => VersionRange.Parse(s)); - public NuGetFramework GetFramework(string frameworkString) => _frameworksTable.GetOrAdd(frameworkString, (s) => NuGetFramework.Parse(s)); - public string GetString(string frameworkString) => _stringsTable.GetOrAdd(frameworkString, frameworkString); - } -} diff --git a/src/Microsoft.DotNet.ProjectModel/Graph/LockFileTarget.cs b/src/Microsoft.DotNet.ProjectModel/Graph/LockFileTarget.cs deleted file mode 100644 index ad061559a..000000000 --- a/src/Microsoft.DotNet.ProjectModel/Graph/LockFileTarget.cs +++ /dev/null @@ -1,17 +0,0 @@ -// 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 System.Collections.Generic; -using NuGet.Frameworks; - -namespace Microsoft.DotNet.ProjectModel.Graph -{ - public class LockFileTarget - { - public NuGetFramework TargetFramework { get; set; } - - public string RuntimeIdentifier { get; set; } - - public IList Libraries { get; set; } = new List(); - } -} diff --git a/src/Microsoft.DotNet.ProjectModel/Graph/LockFileTargetContentFile.cs b/src/Microsoft.DotNet.ProjectModel/Graph/LockFileTargetContentFile.cs deleted file mode 100644 index 72eecd0c1..000000000 --- a/src/Microsoft.DotNet.ProjectModel/Graph/LockFileTargetContentFile.cs +++ /dev/null @@ -1,20 +0,0 @@ -// 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. - -namespace Microsoft.DotNet.ProjectModel.Graph -{ - public class LockFileContentFile - { - public string Path { get; set; } - - public string OutputPath { get; set; } - - public string PPOutputPath { get; set; } - - public BuildAction BuildAction { get; set; } - - public string CodeLanguage { get; set; } - - public bool CopyToOutput { get; set; } = false; - } -} \ No newline at end of file diff --git a/src/Microsoft.DotNet.ProjectModel/Graph/LockFileTargetLibrary.cs b/src/Microsoft.DotNet.ProjectModel/Graph/LockFileTargetLibrary.cs deleted file mode 100644 index f35cdb031..000000000 --- a/src/Microsoft.DotNet.ProjectModel/Graph/LockFileTargetLibrary.cs +++ /dev/null @@ -1,38 +0,0 @@ -// 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 System; -using System.Collections.Generic; -using NuGet.Frameworks; -using NuGet.Packaging.Core; -using NuGet.Versioning; - -namespace Microsoft.DotNet.ProjectModel.Graph -{ - public class LockFileTargetLibrary - { - public string Name { get; set; } - - public string Type { get; set; } - - public NuGetFramework TargetFramework { get; set; } - - public NuGetVersion Version { get; set; } - - public IList Dependencies { get; set; } = new List(); - - public ISet FrameworkAssemblies { get; set; } = new HashSet(StringComparer.OrdinalIgnoreCase); - - public IList RuntimeAssemblies { get; set; } = new List(); - - public IList CompileTimeAssemblies { get; set; } = new List(); - - public IList ResourceAssemblies { get; set; } = new List(); - - public IList NativeLibraries { get; set; } = new List(); - - public IList ContentFiles { get; set; } = new List(); - - public IList RuntimeTargets { get; set; } = new List(); - } -} diff --git a/src/Microsoft.DotNet.ProjectModel/Graph/ProjectLibraryDependency.cs b/src/Microsoft.DotNet.ProjectModel/Graph/ProjectLibraryDependency.cs new file mode 100644 index 000000000..d67661aaa --- /dev/null +++ b/src/Microsoft.DotNet.ProjectModel/Graph/ProjectLibraryDependency.cs @@ -0,0 +1,20 @@ +using NuGet.LibraryModel; + +namespace Microsoft.DotNet.ProjectModel +{ + public class ProjectLibraryDependency : LibraryDependency + { + public string SourceFilePath { get; set; } + public int SourceLine { get; set; } + public int SourceColumn { get; set; } + + public ProjectLibraryDependency() + { + } + + public ProjectLibraryDependency(LibraryRange libraryRange) + { + LibraryRange = libraryRange; + } + } +} \ No newline at end of file diff --git a/src/Microsoft.DotNet.ProjectModel/LibraryDescription.cs b/src/Microsoft.DotNet.ProjectModel/LibraryDescription.cs index a93461415..6355984dd 100644 --- a/src/Microsoft.DotNet.ProjectModel/LibraryDescription.cs +++ b/src/Microsoft.DotNet.ProjectModel/LibraryDescription.cs @@ -1,12 +1,10 @@ // 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 System; using System.Collections.Generic; using System.Linq; -using Microsoft.DotNet.PlatformAbstractions; -using Microsoft.DotNet.ProjectModel.Graph; using NuGet.Frameworks; +using NuGet.LibraryModel; namespace Microsoft.DotNet.ProjectModel { @@ -19,7 +17,7 @@ namespace Microsoft.DotNet.ProjectModel LibraryIdentity identity, string hash, string path, - IEnumerable dependencies, + IEnumerable dependencies, NuGetFramework framework, bool resolved, bool compatible) @@ -27,7 +25,7 @@ namespace Microsoft.DotNet.ProjectModel Path = path; Identity = identity; Hash = hash; - Dependencies = dependencies ?? Enumerable.Empty(); + Dependencies = dependencies ?? Enumerable.Empty(); Framework = framework; Resolved = resolved; Compatible = compatible; @@ -35,10 +33,10 @@ namespace Microsoft.DotNet.ProjectModel public LibraryIdentity Identity { get; } public string Hash { get; } - public HashSet RequestedRanges { get; } = new HashSet(new LibraryRangeEqualityComparer()); + public HashSet RequestedRanges { get; } = new HashSet(); public List Parents { get; } = new List(); public string Path { get; } - public IEnumerable Dependencies { get; } + public IEnumerable Dependencies { get; } public bool Compatible { get; } public NuGetFramework Framework { get; set; } @@ -48,29 +46,5 @@ namespace Microsoft.DotNet.ProjectModel { return $"{Identity} ({Identity.Type}) = {Path}"; } - - // For diagnostics, we don't want to duplicate requested dependencies so we - // dedupe dependencies defined in project.json - private class LibraryRangeEqualityComparer : IEqualityComparer - { - public bool Equals(LibraryRange x, LibraryRange y) - { - return x.Equals(y) && - x.SourceColumn == y.SourceColumn && - x.SourceLine == y.SourceLine && - string.Equals(x.SourceFilePath, y.SourceFilePath, StringComparison.Ordinal); - } - - public int GetHashCode(LibraryRange obj) - { - var combiner = HashCodeCombiner.Start(); - combiner.Add(obj); - combiner.Add(obj.SourceFilePath); - combiner.Add(obj.SourceLine); - combiner.Add(obj.SourceColumn); - - return combiner.CombinedHash; - } - } } } diff --git a/src/Microsoft.DotNet.ProjectModel/MSBuildProjectDescription.cs b/src/Microsoft.DotNet.ProjectModel/MSBuildProjectDescription.cs index 85c26a49f..42b95ef72 100644 --- a/src/Microsoft.DotNet.ProjectModel/MSBuildProjectDescription.cs +++ b/src/Microsoft.DotNet.ProjectModel/MSBuildProjectDescription.cs @@ -2,7 +2,8 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System.Collections.Generic; -using Microsoft.DotNet.ProjectModel.Graph; +using NuGet.LibraryModel; +using NuGet.ProjectModel; namespace Microsoft.DotNet.ProjectModel { @@ -18,14 +19,14 @@ namespace Microsoft.DotNet.ProjectModel public MSBuildProjectDescription( string path, string msbuildProjectPath, - LockFileProjectLibrary projectLibrary, + LockFileLibrary projectLibrary, LockFileTargetLibrary lockFileLibrary, Project projectFile, - IEnumerable dependencies, + IEnumerable dependencies, bool compatible, bool resolved) : base( - new LibraryIdentity(projectLibrary.Name, projectLibrary.Version, LibraryType.MSBuildProject), + new LibraryIdentity(projectLibrary.Name, projectLibrary.Version, LibraryType.Project), string.Empty, //msbuild projects don't have hashes path, lockFileLibrary, @@ -39,7 +40,7 @@ namespace Microsoft.DotNet.ProjectModel ProjectLibrary = projectLibrary; } - public LockFileProjectLibrary ProjectLibrary { get; } + public LockFileLibrary ProjectLibrary { get; } public string MSBuildProjectPath { get; set; } diff --git a/src/Microsoft.DotNet.ProjectModel/PackageDescription.cs b/src/Microsoft.DotNet.ProjectModel/PackageDescription.cs index 2f8202f40..62bd5be22 100644 --- a/src/Microsoft.DotNet.ProjectModel/PackageDescription.cs +++ b/src/Microsoft.DotNet.ProjectModel/PackageDescription.cs @@ -3,8 +3,9 @@ using System.Collections.Generic; using System.Linq; -using Microsoft.DotNet.ProjectModel.Graph; using Microsoft.DotNet.ProjectModel.Resolution; +using NuGet.LibraryModel; +using NuGet.ProjectModel; namespace Microsoft.DotNet.ProjectModel { @@ -13,9 +14,9 @@ namespace Microsoft.DotNet.ProjectModel public PackageDescription( string path, string hashPath, - LockFilePackageLibrary package, + LockFileLibrary package, LockFileTargetLibrary lockFileLibrary, - IEnumerable dependencies, + IEnumerable dependencies, bool compatible, bool resolved) : base( @@ -34,17 +35,19 @@ namespace Microsoft.DotNet.ProjectModel public string HashPath { get; } - public LockFilePackageLibrary PackageLibrary { get; } + public LockFileLibrary PackageLibrary { get; } public override IEnumerable RuntimeAssemblies => FilterPlaceholders(base.RuntimeAssemblies); public override IEnumerable CompileTimeAssemblies => FilterPlaceholders(base.CompileTimeAssemblies); - public bool HasCompileTimePlaceholder => base.CompileTimeAssemblies.Any() && base.CompileTimeAssemblies.All(a => PackageDependencyProvider.IsPlaceholderFile(a)); + public bool HasCompileTimePlaceholder => + base.CompileTimeAssemblies.Any() && + base.CompileTimeAssemblies.All(a => PackageDependencyProvider.IsPlaceholderFile(a.Path)); private static IEnumerable FilterPlaceholders(IEnumerable items) { - return items.Where(a => !PackageDependencyProvider.IsPlaceholderFile(a)); + return items.Where(a => !PackageDependencyProvider.IsPlaceholderFile(a.Path)); } } } diff --git a/src/Microsoft.DotNet.ProjectModel/Project.cs b/src/Microsoft.DotNet.ProjectModel/Project.cs index c248e8a8d..c174a1806 100644 --- a/src/Microsoft.DotNet.ProjectModel/Project.cs +++ b/src/Microsoft.DotNet.ProjectModel/Project.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.IO; using Microsoft.DotNet.ProjectModel.Files; -using Microsoft.DotNet.ProjectModel.Graph; using NuGet.Frameworks; using NuGet.Versioning; @@ -56,9 +55,9 @@ namespace Microsoft.DotNet.ProjectModel public Version AssemblyFileVersion { get; set; } - public IList Dependencies { get; set; } + public IList Dependencies { get; set; } - public List Tools { get; set; } + public List Tools { get; set; } public string EntryPoint { get; set; } diff --git a/src/Microsoft.DotNet.ProjectModel/ProjectContext.cs b/src/Microsoft.DotNet.ProjectModel/ProjectContext.cs index 14a6d17f9..897a65b6a 100644 --- a/src/Microsoft.DotNet.ProjectModel/ProjectContext.cs +++ b/src/Microsoft.DotNet.ProjectModel/ProjectContext.cs @@ -1,14 +1,13 @@ // 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 System; using System.Collections.Generic; using System.IO; using System.Linq; using Microsoft.DotNet.ProjectModel.Compilation; -using Microsoft.DotNet.ProjectModel.Graph; using Microsoft.DotNet.ProjectModel.Resolution; using NuGet.Frameworks; +using NuGet.ProjectModel; namespace Microsoft.DotNet.ProjectModel { diff --git a/src/Microsoft.DotNet.ProjectModel/ProjectContextBuilder.cs b/src/Microsoft.DotNet.ProjectModel/ProjectContextBuilder.cs index 27d4e9b98..d5e0a7517 100644 --- a/src/Microsoft.DotNet.ProjectModel/ProjectContextBuilder.cs +++ b/src/Microsoft.DotNet.ProjectModel/ProjectContextBuilder.cs @@ -13,6 +13,8 @@ using Microsoft.DotNet.ProjectModel.Resolution; using NuGet.Common; using NuGet.Configuration; using NuGet.Frameworks; +using NuGet.LibraryModel; +using NuGet.ProjectModel; namespace Microsoft.DotNet.ProjectModel { @@ -264,12 +266,12 @@ namespace Microsoft.DotNet.ProjectModel libraries.Add(new LibraryKey(mainProject.Identity.Name), mainProject); } - LibraryRange? platformDependency = null; + ProjectLibraryDependency platformDependency = null; if (mainProject != null) { platformDependency = mainProject.Dependencies .Where(d => d.Type.Equals(LibraryDependencyType.Platform)) - .Cast() + .Cast() .FirstOrDefault(); } bool isPortable = platformDependency != null; @@ -288,7 +290,7 @@ namespace Microsoft.DotNet.ProjectModel if (platformDependency != null) { - libraries.TryGetValue(new LibraryKey(platformDependency.Value.Name), out platformLibrary); + libraries.TryGetValue(new LibraryKey(platformDependency.Name), out platformLibrary); } } } @@ -321,7 +323,7 @@ namespace Microsoft.DotNet.ProjectModel diagnostics.Add(new DiagnosticMessage( ErrorCodes.NU1009, $"The expected lock file doesn't exist. Please run \"dotnet restore\" to generate a new lock file.", - Path.Combine(Project.ProjectDirectory, LockFile.FileName), + Path.Combine(Project.ProjectDirectory, LockFileFormat.LockFileName), DiagnosticMessageSeverity.Error)); } @@ -330,7 +332,7 @@ namespace Microsoft.DotNet.ProjectModel diagnostics.Add(new DiagnosticMessage( ErrorCodes.NU1006, $"{lockFileValidationMessage}. Please run \"dotnet restore\" to generate a new lock file.", - Path.Combine(Project.ProjectDirectory, LockFile.FileName), + Path.Combine(Project.ProjectDirectory, LockFileFormat.LockFileName), DiagnosticMessageSeverity.Warning)); } @@ -392,9 +394,9 @@ namespace Microsoft.DotNet.ProjectModel { string result = null; - if (LockFile != null && !string.IsNullOrEmpty(LockFile.LockFilePath)) + if (LockFile != null && !string.IsNullOrEmpty(LockFile.Path)) { - result = Path.GetDirectoryName(LockFile.LockFilePath); + result = Path.GetDirectoryName(LockFile.Path); } return result; @@ -411,11 +413,11 @@ namespace Microsoft.DotNet.ProjectModel var lockFilePath = ""; if (LockFile != null) { - lockFilePath = LockFile.LockFilePath; + lockFilePath = LockFile.Path; } else if (Project != null) { - lockFilePath = Path.Combine(Project.ProjectDirectory, LockFile.FileName); + lockFilePath = Path.Combine(Project.ProjectDirectory, LockFileFormat.LockFileName); } diagnostics.Add(new DiagnosticMessage( @@ -470,8 +472,11 @@ namespace Microsoft.DotNet.ProjectModel // the target framework installed. requiresFrameworkAssemblies = true; - var newKey = new LibraryKey(library.Identity.Name, LibraryType.ReferenceAssembly); - var dependency = new LibraryRange(library.Identity.Name, LibraryType.ReferenceAssembly); + var newKey = new LibraryKey(library.Identity.Name, LibraryType.Reference); + var dependency = new ProjectLibraryDependency + { + LibraryRange = new LibraryRange(library.Identity.Name, LibraryDependencyTarget.Reference) + }; var replacement = referenceAssemblyDependencyResolver.GetDescription(dependency, TargetFramework); @@ -498,16 +503,16 @@ namespace Microsoft.DotNet.ProjectModel library.Framework = library.Framework ?? TargetFramework; foreach (var dependency in library.Dependencies) { - var keyType = dependency.Target == LibraryType.ReferenceAssembly ? - LibraryType.ReferenceAssembly : - LibraryType.Unspecified; + var keyType = dependency.LibraryRange.TypeConstraint == LibraryDependencyTarget.Reference ? + LibraryType.Reference : + (LibraryType?) null; var key = new LibraryKey(dependency.Name, keyType); LibraryDescription dependencyDescription; if (!libraries.TryGetValue(key, out dependencyDescription)) { - if (keyType == LibraryType.ReferenceAssembly) + if (keyType == LibraryType.Reference) { // a dependency is specified to be reference assembly but fail to match // then add a unresolved dependency @@ -515,7 +520,7 @@ namespace Microsoft.DotNet.ProjectModel UnresolvedDependencyProvider.GetDescription(dependency, TargetFramework); libraries[key] = dependencyDescription; } - else if (!libraries.TryGetValue(new LibraryKey(dependency.Name, LibraryType.ReferenceAssembly), out dependencyDescription)) + else if (!libraries.TryGetValue(new LibraryKey(dependency.Name, LibraryType.Reference), out dependencyDescription)) { // a dependency which type is unspecified fails to match, then try to find a // reference assembly type dependency @@ -531,7 +536,7 @@ namespace Microsoft.DotNet.ProjectModel // 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 priorities = new[] { LibraryType.Package, LibraryType.Project, LibraryType.Reference }; var nameGroups = libraries.Keys.ToLookup(libraryKey => libraryKey.Name); foreach (var nameGroup in nameGroups) { @@ -556,7 +561,7 @@ namespace Microsoft.DotNet.ProjectModel foreach (var library in target.Libraries) { LibraryDescription description = null; - var type = LibraryType.Unspecified; + LibraryDependencyTarget type = LibraryDependencyTarget.All; if (string.Equals(library.Type, "project")) { @@ -567,13 +572,13 @@ namespace Microsoft.DotNet.ProjectModel if (MSBuildDependencyProvider.IsMSBuildProjectLibrary(projectLibrary)) { description = msbuildResolver.GetDescription(TargetFramework, projectLibrary, library, IsDesignTime); - type = LibraryType.MSBuildProject; + type = LibraryDependencyTarget.Project; } else { var path = Path.GetFullPath(Path.Combine(ProjectDirectory, projectLibrary.Path)); description = projectResolver.GetDescription(library.Name, path, library, ProjectResolver); - type = LibraryType.Project; + type = LibraryDependencyTarget.Project; } } } @@ -586,13 +591,16 @@ namespace Microsoft.DotNet.ProjectModel description = packageResolver.GetDescription(TargetFramework, packageEntry, library); } - type = LibraryType.Package; + type = LibraryDependencyTarget.Package; } - description = description ?? - UnresolvedDependencyProvider.GetDescription( - new LibraryRange(library.Name, type), - target.TargetFramework); + description = description ?? + UnresolvedDependencyProvider.GetDescription( + new ProjectLibraryDependency + { + LibraryRange = new LibraryRange(library.Name, type) + }, + target.TargetFramework); libraries.Add(new LibraryKey(library.Name), description); } @@ -653,26 +661,26 @@ namespace Microsoft.DotNet.ProjectModel private static LockFile ResolveLockFile(string projectDir) { - var projectLockJsonPath = Path.Combine(projectDir, LockFile.FileName); + var projectLockJsonPath = Path.Combine(projectDir, LockFileFormat.LockFileName); return File.Exists(projectLockJsonPath) ? - LockFileReader.Read(Path.Combine(projectDir, LockFile.FileName), designTime: false) : + new LockFileFormat().Read(Path.Combine(projectDir, LockFileFormat.LockFileName)) : null; } private struct LibraryKey { - public LibraryKey(string name) : this(name, LibraryType.Unspecified) + public LibraryKey(string name) : this(name, null) { } - public LibraryKey(string name, LibraryType libraryType) + public LibraryKey(string name, LibraryType? libraryType) { Name = name; LibraryType = libraryType; } public string Name { get; } - public LibraryType LibraryType { get; } + public LibraryType? LibraryType { get; } public override bool Equals(object obj) { diff --git a/src/Microsoft.DotNet.ProjectModel/ProjectDescription.cs b/src/Microsoft.DotNet.ProjectModel/ProjectDescription.cs index d5e7511ce..bdd161d50 100644 --- a/src/Microsoft.DotNet.ProjectModel/ProjectDescription.cs +++ b/src/Microsoft.DotNet.ProjectModel/ProjectDescription.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Linq; -using Microsoft.DotNet.ProjectModel.Graph; +using NuGet.LibraryModel; namespace Microsoft.DotNet.ProjectModel { @@ -12,10 +12,10 @@ namespace Microsoft.DotNet.ProjectModel // Create an unresolved project description public ProjectDescription(string name, string path) : base( - new LibraryIdentity(name, LibraryType.Project), + new LibraryIdentity(name, null, LibraryType.Project), string.Empty, // Projects don't have hashes path, - Enumerable.Empty(), + Enumerable.Empty(), framework: null, resolved: false, compatible: false) @@ -25,7 +25,7 @@ namespace Microsoft.DotNet.ProjectModel public ProjectDescription( LibraryRange libraryRange, Project project, - IEnumerable dependencies, + IEnumerable dependencies, TargetFrameworkInformation targetFrameworkInfo, bool resolved) : base( diff --git a/src/Microsoft.DotNet.ProjectModel/ProjectModelPlatformExtensions.cs b/src/Microsoft.DotNet.ProjectModel/ProjectModelPlatformExtensions.cs index 5f6ea1b94..220d9a84b 100644 --- a/src/Microsoft.DotNet.ProjectModel/ProjectModelPlatformExtensions.cs +++ b/src/Microsoft.DotNet.ProjectModel/ProjectModelPlatformExtensions.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.Linq; using Microsoft.DotNet.ProjectModel.Compilation; -using Microsoft.DotNet.ProjectModel.Graph; +using NuGet.LibraryModel; namespace Microsoft.DotNet.ProjectModel { @@ -23,12 +23,15 @@ namespace Microsoft.DotNet.ProjectModel return exclusionList; } - private static void CollectDependencies(IDictionary exports, IEnumerable dependencies, HashSet exclusionList) + private static void CollectDependencies( + IDictionary exports, + IEnumerable dependencies, + HashSet exclusionList) { foreach (var dependency in dependencies) { var export = exports[dependency.Name]; - if (export.Library.Identity.Version.Equals(dependency.VersionRange.MinVersion)) + if (export.Library.Identity.Version.Equals(dependency.LibraryRange.VersionRange.MinVersion)) { exclusionList.Add(export.Library.Identity.Name); CollectDependencies(exports, export.Library.Dependencies, exclusionList); @@ -52,7 +55,10 @@ namespace Microsoft.DotNet.ProjectModel return exclusionList; } - private static void CollectNonBuildDependencies(IDictionary exports, IEnumerable dependencies, HashSet acceptedExports) + private static void CollectNonBuildDependencies( + IDictionary exports, + IEnumerable dependencies, + HashSet acceptedExports) { foreach (var dependency in dependencies) { diff --git a/src/Microsoft.DotNet.ProjectModel/ProjectReader.cs b/src/Microsoft.DotNet.ProjectModel/ProjectReader.cs index 6e4e466e7..091076c88 100644 --- a/src/Microsoft.DotNet.ProjectModel/ProjectReader.cs +++ b/src/Microsoft.DotNet.ProjectModel/ProjectReader.cs @@ -6,11 +6,11 @@ using System.Collections.Generic; using System.IO; using System.Linq; using Microsoft.DotNet.ProjectModel.Files; -using Microsoft.DotNet.ProjectModel.Graph; using Microsoft.DotNet.ProjectModel.Utilities; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using NuGet.Frameworks; +using NuGet.LibraryModel; using NuGet.Versioning; namespace Microsoft.DotNet.ProjectModel @@ -157,8 +157,8 @@ namespace Microsoft.DotNet.ProjectModel // REVIEW: Move this to the dependencies node? project.EmbedInteropTypes = rawProject.Value("embedInteropTypes"); - project.Dependencies = new List(); - project.Tools = new List(); + project.Dependencies = new List(); + project.Tools = new List(); // Project files project.Files = new ProjectFilesCollection(rawProject, project.ProjectDirectory, project.ProjectFilePath); @@ -258,7 +258,7 @@ namespace Microsoft.DotNet.ProjectModel private static void PopulateDependencies( string projectPath, - IList results, + IList results, JObject settings, string propertyName, bool isGacOrFrameworkReference) @@ -278,8 +278,8 @@ namespace Microsoft.DotNet.ProjectModel var dependencyValue = dependency.Value; var dependencyTypeValue = LibraryDependencyType.Default; + var target = isGacOrFrameworkReference ? LibraryDependencyTarget.Reference: LibraryDependencyTarget.None; string dependencyVersionAsString = null; - LibraryType target = isGacOrFrameworkReference ? LibraryType.ReferenceAssembly : LibraryType.Unspecified; if (dependencyValue.Type == JTokenType.Object) { @@ -289,18 +289,14 @@ namespace Microsoft.DotNet.ProjectModel var type = dependencyValue.Value("type"); if (type != null) { - dependencyTypeValue = LibraryDependencyType.Parse(type); + dependencyTypeValue = LibraryDependencyType.Parse(new [] { type }); } // Read the target if specified if (!isGacOrFrameworkReference) { - LibraryType parsedTarget; var targetStr = dependencyValue.Value("target"); - if (!string.IsNullOrEmpty(targetStr) && LibraryType.TryParse(targetStr, out parsedTarget)) - { - target = parsedTarget; - } + target = LibraryDependencyTargetUtils.Parse(targetStr); } } else if (dependencyValue.Type == JTokenType.String) @@ -332,14 +328,14 @@ namespace Microsoft.DotNet.ProjectModel } var lineInfo = (IJsonLineInfo)dependencyValue; - results.Add(new LibraryRange( - dependency.Key, - dependencyVersionRange, - target, - dependencyTypeValue, - projectPath, - lineInfo.LineNumber, - lineInfo.LinePosition)); + results.Add(new ProjectLibraryDependency + { + LibraryRange = new LibraryRange( + dependency.Key, + dependencyVersionRange, + target), + Type = dependencyTypeValue + }); } } } @@ -352,7 +348,7 @@ namespace Microsoft.DotNet.ProjectModel project._defaultTargetFrameworkConfiguration = new TargetFrameworkInformation { - Dependencies = new List() + Dependencies = new List() }; // Add default configurations @@ -470,13 +466,13 @@ namespace Microsoft.DotNet.ProjectModel var targetFrameworkInformation = new TargetFrameworkInformation { FrameworkName = frameworkName, - Dependencies = new List(), + Dependencies = new List(), CompilerOptions = compilerOptions, Line = lineInfo.LineNumber, Column = lineInfo.LinePosition }; - var frameworkDependencies = new List(); + var frameworkDependencies = new List(); PopulateDependencies( project.ProjectFilePath, @@ -485,7 +481,7 @@ namespace Microsoft.DotNet.ProjectModel "dependencies", isGacOrFrameworkReference: false); - var frameworkAssemblies = new List(); + var frameworkAssemblies = new List(); PopulateDependencies( project.ProjectFilePath, frameworkAssemblies, diff --git a/src/Microsoft.DotNet.ProjectModel/Resolution/LibraryManager.cs b/src/Microsoft.DotNet.ProjectModel/Resolution/LibraryManager.cs index 6cbf9c021..15227f3a7 100644 --- a/src/Microsoft.DotNet.ProjectModel/Resolution/LibraryManager.cs +++ b/src/Microsoft.DotNet.ProjectModel/Resolution/LibraryManager.cs @@ -3,9 +3,8 @@ using System.Collections.Generic; using System.Linq; -using Microsoft.DotNet.ProjectModel.Graph; using Microsoft.DotNet.ProjectModel.Utilities; -using NuGet.Versioning; +using NuGet.LibraryModel; namespace Microsoft.DotNet.ProjectModel.Resolution { @@ -101,7 +100,7 @@ namespace Microsoft.DotNet.ProjectModel.Resolution continue; } - if (range.VersionRange == null) + if (range.LibraryRange.VersionRange == null) { // TODO: Show errors/warnings for things without versions continue; @@ -113,10 +112,10 @@ namespace Microsoft.DotNet.ProjectModel.Resolution // then report a warning // Case 1: Non floating version and the minimum doesn't match what was specified // Case 2: Floating version that fell outside of the range - if ((!range.VersionRange.IsFloating && - range.VersionRange.MinVersion != library.Identity.Version) || - (range.VersionRange.IsFloating && - !range.VersionRange.Float.Satisfies(library.Identity.Version))) + if ((!range.LibraryRange.VersionRange.IsFloating && + range.LibraryRange.VersionRange.MinVersion != library.Identity.Version) || + (range.LibraryRange.VersionRange.IsFloating && + !range.LibraryRange.VersionRange.Float.Satisfies(library.Identity.Version))) { var message = $"Dependency specified was {FormatLibraryRange(range)} but ended up with {library.Identity}."; @@ -163,7 +162,7 @@ namespace Microsoft.DotNet.ProjectModel.Resolution { foreach (var item in items) { - var versionRange = item.Dependency.VersionRange; + var versionRange = item.Dependency.LibraryRange.VersionRange; if (versionRange == null) { @@ -191,14 +190,14 @@ namespace Microsoft.DotNet.ProjectModel.Resolution return messages; } - private static string FormatLibraryRange(LibraryRange range) + private static string FormatLibraryRange(ProjectLibraryDependency range) { - if (range.VersionRange == null) + if (range.LibraryRange.VersionRange == null) { return range.Name; } - return range.Name + " " + VersionUtility.RenderVersion(range.VersionRange); + return range.Name + " " + VersionUtility.RenderVersion(range.LibraryRange.VersionRange); } private void AddDiagnostics(List messages, @@ -229,7 +228,7 @@ namespace Microsoft.DotNet.ProjectModel.Resolution } } - private IEnumerable GetRangesWithSourceLocations(LibraryDescription library) + private IEnumerable GetRangesWithSourceLocations(LibraryDescription library) { foreach (var range in library.RequestedRanges) { @@ -250,10 +249,10 @@ namespace Microsoft.DotNet.ProjectModel.Resolution private struct DependencyItem { - public LibraryRange Dependency { get; private set; } + public ProjectLibraryDependency Dependency { get; private set; } public LibraryDescription Library { get; private set; } - public DependencyItem(LibraryRange dependency, LibraryDescription library) + public DependencyItem(ProjectLibraryDependency dependency, LibraryDescription library) { Dependency = dependency; Library = library; @@ -262,10 +261,10 @@ namespace Microsoft.DotNet.ProjectModel.Resolution private struct LibraryItem { - public LibraryRange RequestedRange { get; private set; } + public ProjectLibraryDependency RequestedRange { get; private set; } public LibraryDescription Library { get; private set; } - public LibraryItem(LibraryRange requestedRange, LibraryDescription library) + public LibraryItem(ProjectLibraryDependency requestedRange, LibraryDescription library) { RequestedRange = requestedRange; Library = library; diff --git a/src/Microsoft.DotNet.ProjectModel/Resolution/MSBuildDependencyProvider.cs b/src/Microsoft.DotNet.ProjectModel/Resolution/MSBuildDependencyProvider.cs index 216f56bb6..a0a58f290 100644 --- a/src/Microsoft.DotNet.ProjectModel/Resolution/MSBuildDependencyProvider.cs +++ b/src/Microsoft.DotNet.ProjectModel/Resolution/MSBuildDependencyProvider.cs @@ -5,8 +5,9 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using Microsoft.DotNet.ProjectModel.Graph; using NuGet.Frameworks; +using NuGet.LibraryModel; +using NuGet.ProjectModel; namespace Microsoft.DotNet.ProjectModel.Resolution { @@ -22,7 +23,7 @@ namespace Microsoft.DotNet.ProjectModel.Resolution } public MSBuildProjectDescription GetDescription(NuGetFramework targetFramework, - LockFileProjectLibrary projectLibrary, + LockFileLibrary projectLibrary, LockFileTargetLibrary targetLibrary, bool isDesignTime) { @@ -33,7 +34,8 @@ namespace Microsoft.DotNet.ProjectModel.Resolution targetLibrary.RuntimeAssemblies.Any() || isDesignTime; - var dependencies = new List(targetLibrary.Dependencies.Count + targetLibrary.FrameworkAssemblies.Count); + var dependencies = new List( + targetLibrary.Dependencies.Count + targetLibrary.FrameworkAssemblies.Count); PopulateDependencies(dependencies, targetLibrary, targetFramework); var msbuildProjectFilePath = GetMSBuildProjectFilePath(projectLibrary); @@ -56,7 +58,7 @@ namespace Microsoft.DotNet.ProjectModel.Resolution return msbuildPackageDescription; } - private string GetMSBuildProjectFilePath(LockFileProjectLibrary projectLibrary) + private string GetMSBuildProjectFilePath(LockFileLibrary projectLibrary) { if (_rootProject == null) { @@ -70,17 +72,16 @@ namespace Microsoft.DotNet.ProjectModel.Resolution } private void PopulateDependencies( - List dependencies, + List dependencies, LockFileTargetLibrary targetLibrary, NuGetFramework targetFramework) { foreach (var dependency in targetLibrary.Dependencies) { - dependencies.Add(new LibraryRange( - dependency.Id, - dependency.VersionRange, - LibraryType.Unspecified, - LibraryDependencyType.Default)); + dependencies.Add(new ProjectLibraryDependency + { + LibraryRange = new LibraryRange(dependency.Id, dependency.VersionRange, LibraryDependencyTarget.All) + }); } if (!targetFramework.IsPackageBased) @@ -88,15 +89,15 @@ namespace Microsoft.DotNet.ProjectModel.Resolution // Only add framework assemblies for non-package based frameworks. foreach (var frameworkAssembly in targetLibrary.FrameworkAssemblies) { - dependencies.Add(new LibraryRange( - frameworkAssembly, - LibraryType.ReferenceAssembly, - LibraryDependencyType.Default)); + dependencies.Add(new ProjectLibraryDependency + { + LibraryRange = new LibraryRange(frameworkAssembly, LibraryDependencyTarget.Reference) + }); } } } - public static bool IsMSBuildProjectLibrary(LockFileProjectLibrary projectLibrary) + public static bool IsMSBuildProjectLibrary(LockFileLibrary projectLibrary) { var msbuildProjectPath = projectLibrary.MSBuildProject; if (msbuildProjectPath == null) diff --git a/src/Microsoft.DotNet.ProjectModel/Resolution/PackageDependencyProvider.cs b/src/Microsoft.DotNet.ProjectModel/Resolution/PackageDependencyProvider.cs index e77906edd..f38c0134a 100644 --- a/src/Microsoft.DotNet.ProjectModel/Resolution/PackageDependencyProvider.cs +++ b/src/Microsoft.DotNet.ProjectModel/Resolution/PackageDependencyProvider.cs @@ -7,10 +7,11 @@ using System.IO; using System.Linq; using System.Reflection.Metadata; using System.Reflection.PortableExecutable; -using Microsoft.DotNet.ProjectModel.Graph; using NuGet.Common; using NuGet.Frameworks; +using NuGet.LibraryModel; using NuGet.Packaging; +using NuGet.ProjectModel; namespace Microsoft.DotNet.ProjectModel.Resolution { @@ -33,7 +34,10 @@ namespace Microsoft.DotNet.ProjectModel.Resolution _frameworkReferenceResolver = frameworkReferenceResolver; } - public PackageDescription GetDescription(NuGetFramework targetFramework, LockFilePackageLibrary package, LockFileTargetLibrary targetLibrary) + public PackageDescription GetDescription( + NuGetFramework targetFramework, + LockFileLibrary package, + LockFileTargetLibrary targetLibrary) { // If a NuGet dependency is supposed to provide assemblies but there is no assembly compatible with // current target framework, we should mark this dependency as unresolved @@ -46,7 +50,7 @@ namespace Microsoft.DotNet.ProjectModel.Resolution targetLibrary.RuntimeAssemblies.Any() || !containsAssembly; - var dependencies = new List(targetLibrary.Dependencies.Count + targetLibrary.FrameworkAssemblies.Count); + var dependencies = new List(targetLibrary.Dependencies.Count + targetLibrary.FrameworkAssemblies.Count); PopulateDependencies(dependencies, targetLibrary, targetFramework); var path = _packagePathResolver?.GetPackageDirectory(package.Name, package.Version); @@ -77,13 +81,17 @@ namespace Microsoft.DotNet.ProjectModel.Resolution return packageDescription; } - private void PopulateLegacyPortableDependencies(NuGetFramework targetFramework, List dependencies, string packagePath, LockFileTargetLibrary targetLibrary) + private void PopulateLegacyPortableDependencies( + NuGetFramework targetFramework, + List dependencies, + string packagePath, + LockFileTargetLibrary targetLibrary) { var seen = new HashSet(); foreach (var assembly in targetLibrary.CompileTimeAssemblies) { - if (IsPlaceholderFile(assembly)) + if (IsPlaceholderFile(assembly.Path)) { continue; } @@ -116,9 +124,10 @@ namespace Microsoft.DotNet.ProjectModel.Resolution // framework assembly dependency if (_frameworkReferenceResolver.TryGetAssembly(dependency, targetFramework, out path, out version)) { - dependencies.Add(new LibraryRange(dependency, - LibraryType.ReferenceAssembly, - LibraryDependencyType.Build)); + dependencies.Add(new ProjectLibraryDependency + { + LibraryRange = new LibraryRange(dependency, LibraryDependencyTarget.Reference) + }); } } } @@ -141,17 +150,15 @@ namespace Microsoft.DotNet.ProjectModel.Resolution } private void PopulateDependencies( - List dependencies, + List dependencies, LockFileTargetLibrary targetLibrary, NuGetFramework targetFramework) { foreach (var dependency in targetLibrary.Dependencies) { - dependencies.Add(new LibraryRange( - dependency.Id, - dependency.VersionRange, - LibraryType.Unspecified, - LibraryDependencyType.Default)); + dependencies.Add(new ProjectLibraryDependency{ + LibraryRange = new LibraryRange(dependency.Id, dependency.VersionRange, LibraryDependencyTarget.All) + }); } if (!targetFramework.IsPackageBased) @@ -159,10 +166,10 @@ namespace Microsoft.DotNet.ProjectModel.Resolution // Only add framework assemblies for non-package based frameworks. foreach (var frameworkAssembly in targetLibrary.FrameworkAssemblies) { - dependencies.Add(new LibraryRange( - frameworkAssembly, - LibraryType.ReferenceAssembly, - LibraryDependencyType.Default)); + dependencies.Add(new ProjectLibraryDependency + { + LibraryRange = new LibraryRange(frameworkAssembly, LibraryDependencyTarget.Reference) + }); } } } diff --git a/src/Microsoft.DotNet.ProjectModel/Resolution/ProjectDependencyProvider.cs b/src/Microsoft.DotNet.ProjectModel/Resolution/ProjectDependencyProvider.cs index c83d705f9..0b9cb615c 100644 --- a/src/Microsoft.DotNet.ProjectModel/Resolution/ProjectDependencyProvider.cs +++ b/src/Microsoft.DotNet.ProjectModel/Resolution/ProjectDependencyProvider.cs @@ -5,8 +5,9 @@ using System; using System.Collections.Generic; using System.IO; using System.Linq; -using Microsoft.DotNet.ProjectModel.Graph; using NuGet.Frameworks; +using NuGet.LibraryModel; +using NuGet.ProjectModel; namespace Microsoft.DotNet.ProjectModel.Resolution { @@ -27,7 +28,7 @@ namespace Microsoft.DotNet.ProjectModel.Resolution var project = _resolveProject(Path.GetDirectoryName(path)); if (project != null) { - return GetDescription(targetLibrary.TargetFramework, project, targetLibrary); + return GetDescription(NuGetFramework.Parse(targetLibrary.Framework), project, targetLibrary); } else { @@ -44,7 +45,7 @@ namespace Microsoft.DotNet.ProjectModel.Resolution { // This never returns null var targetFrameworkInfo = project.GetTargetFramework(targetFramework); - var dependencies = new List(targetFrameworkInfo.Dependencies); + var dependencies = new List(targetFrameworkInfo.Dependencies); // Add all of the project's dependencies dependencies.AddRange(project.Dependencies); @@ -72,7 +73,9 @@ namespace Microsoft.DotNet.ProjectModel.Resolution StringComparer.OrdinalIgnoreCase); // Remove all non-framework dependencies that don't appear in the lock file entry - dependencies.RemoveAll(m => !lockFileDependencies.ContainsKey(m.Name) && m.Target != LibraryType.ReferenceAssembly); + dependencies.RemoveAll(m => + !lockFileDependencies.ContainsKey(m.Name) && + m.LibraryRange.TypeConstraint != LibraryDependencyTarget.Reference); } // Mark the library as unresolved if there were specified frameworks @@ -80,18 +83,20 @@ namespace Microsoft.DotNet.ProjectModel.Resolution bool unresolved = targetFrameworkInfo.FrameworkName == null; return new ProjectDescription( - new LibraryRange(project.Name, LibraryType.Unspecified), + new LibraryRange(project.Name, LibraryDependencyTarget.All), project, dependencies, targetFrameworkInfo, !unresolved); } - private static void AddIfMissing(List dependencies, string dependencyName) + private static void AddIfMissing(List dependencies, string dependencyName) { if (!dependencies.Any(dep => string.Equals(dep.Name, dependencyName, StringComparison.OrdinalIgnoreCase))) { - dependencies.Add(new LibraryRange(dependencyName, LibraryType.ReferenceAssembly, LibraryDependencyType.Build)); + dependencies.Add(new ProjectLibraryDependency { + LibraryRange = new LibraryRange(dependencyName, LibraryDependencyTarget.All) + }); } } } diff --git a/src/Microsoft.DotNet.ProjectModel/Resolution/ReferenceAssemblyDependencyResolver.cs b/src/Microsoft.DotNet.ProjectModel/Resolution/ReferenceAssemblyDependencyResolver.cs index 79602547d..795059831 100644 --- a/src/Microsoft.DotNet.ProjectModel/Resolution/ReferenceAssemblyDependencyResolver.cs +++ b/src/Microsoft.DotNet.ProjectModel/Resolution/ReferenceAssemblyDependencyResolver.cs @@ -3,10 +3,8 @@ using System; using System.Linq; -using System.Runtime.Versioning; -using Microsoft.DotNet.ProjectModel.Graph; -using NuGet; using NuGet.Frameworks; +using NuGet.LibraryModel; using NuGet.Versioning; namespace Microsoft.DotNet.ProjectModel.Resolution @@ -20,15 +18,15 @@ namespace Microsoft.DotNet.ProjectModel.Resolution private FrameworkReferenceResolver FrameworkResolver { get; set; } - public LibraryDescription GetDescription(LibraryRange libraryRange, NuGetFramework targetFramework) + public LibraryDescription GetDescription(ProjectLibraryDependency libraryDependency, NuGetFramework targetFramework) { - if (!LibraryType.ReferenceAssembly.CanSatisfyConstraint(libraryRange.Target)) + if (!libraryDependency.LibraryRange.TypeConstraintAllows(LibraryDependencyTarget.Reference)) { return null; } - var name = libraryRange.Name; - var version = libraryRange.VersionRange?.MinVersion; + var name = libraryDependency.Name; + var version = libraryDependency.LibraryRange.VersionRange?.MinVersion; string path; Version assemblyVersion; @@ -39,10 +37,10 @@ namespace Microsoft.DotNet.ProjectModel.Resolution } return new LibraryDescription( - new LibraryIdentity(libraryRange.Name, new NuGetVersion(assemblyVersion), LibraryType.ReferenceAssembly), + new LibraryIdentity(libraryDependency.Name, new NuGetVersion(assemblyVersion), LibraryType.Reference), string.Empty, // Framework assemblies don't have hashes path, - Enumerable.Empty(), + Enumerable.Empty(), targetFramework, resolved: true, compatible: true); diff --git a/src/Microsoft.DotNet.ProjectModel/Resolution/UnresolvedDependencyProvider.cs b/src/Microsoft.DotNet.ProjectModel/Resolution/UnresolvedDependencyProvider.cs index 1c37516e3..63221b108 100644 --- a/src/Microsoft.DotNet.ProjectModel/Resolution/UnresolvedDependencyProvider.cs +++ b/src/Microsoft.DotNet.ProjectModel/Resolution/UnresolvedDependencyProvider.cs @@ -2,20 +2,23 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System.Linq; -using Microsoft.DotNet.ProjectModel.Graph; using NuGet.Frameworks; +using NuGet.LibraryModel; namespace Microsoft.DotNet.ProjectModel.Resolution { public static class UnresolvedDependencyProvider { - public static LibraryDescription GetDescription(LibraryRange libraryRange, NuGetFramework targetFramework) + public static LibraryDescription GetDescription(ProjectLibraryDependency libraryDependency, NuGetFramework targetFramework) { return new LibraryDescription( - new LibraryIdentity(libraryRange.Name, libraryRange.VersionRange?.MinVersion, libraryRange.Target), + new LibraryIdentity( + libraryDependency.Name, + libraryDependency.LibraryRange.VersionRange?.MinVersion, + LibraryType.Unresolved), hash: null, path: null, - dependencies: Enumerable.Empty(), + dependencies: Enumerable.Empty(), framework: targetFramework, resolved: false, compatible: true); diff --git a/src/Microsoft.DotNet.ProjectModel/RuntimeGraphCollector.cs b/src/Microsoft.DotNet.ProjectModel/RuntimeGraphCollector.cs index c2625c982..a85b3a1a7 100644 --- a/src/Microsoft.DotNet.ProjectModel/RuntimeGraphCollector.cs +++ b/src/Microsoft.DotNet.ProjectModel/RuntimeGraphCollector.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using Microsoft.DotNet.ProjectModel.Graph; +using NuGet.LibraryModel; using NuGet.RuntimeModel; namespace Microsoft.DotNet.ProjectModel diff --git a/src/Microsoft.DotNet.ProjectModel/TargetFrameworkInformation.cs b/src/Microsoft.DotNet.ProjectModel/TargetFrameworkInformation.cs index 9f53b62da..811135c94 100644 --- a/src/Microsoft.DotNet.ProjectModel/TargetFrameworkInformation.cs +++ b/src/Microsoft.DotNet.ProjectModel/TargetFrameworkInformation.cs @@ -2,7 +2,6 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System.Collections.Generic; -using Microsoft.DotNet.ProjectModel.Graph; using NuGet.Frameworks; namespace Microsoft.DotNet.ProjectModel @@ -11,7 +10,7 @@ namespace Microsoft.DotNet.ProjectModel { public NuGetFramework FrameworkName { get; set; } - public IReadOnlyList Dependencies { get; set; } + public IReadOnlyList Dependencies { get; set; } public CommonCompilerOptions CompilerOptions { get; set; } diff --git a/src/Microsoft.DotNet.ProjectModel/TargetLibraryWithAssets.cs b/src/Microsoft.DotNet.ProjectModel/TargetLibraryWithAssets.cs index 31a8b48da..97fa24e3b 100644 --- a/src/Microsoft.DotNet.ProjectModel/TargetLibraryWithAssets.cs +++ b/src/Microsoft.DotNet.ProjectModel/TargetLibraryWithAssets.cs @@ -2,8 +2,9 @@ // Licensed under the MIT license. See LICENSE file in the project root for full license information. using System.Collections.Generic; -using Microsoft.DotNet.ProjectModel.Graph; using NuGet.Frameworks; +using NuGet.LibraryModel; +using NuGet.ProjectModel; namespace Microsoft.DotNet.ProjectModel { @@ -14,7 +15,7 @@ namespace Microsoft.DotNet.ProjectModel string sha512, string path, LockFileTargetLibrary lockFileLibrary, - IEnumerable dependencies, + IEnumerable dependencies, bool compatible, bool resolved, NuGetFramework framework = null) diff --git a/src/Microsoft.DotNet.ProjectModel/Workspace.cs b/src/Microsoft.DotNet.ProjectModel/Workspace.cs index 2cf402e2d..8ec8880aa 100644 --- a/src/Microsoft.DotNet.ProjectModel/Workspace.cs +++ b/src/Microsoft.DotNet.ProjectModel/Workspace.cs @@ -6,9 +6,9 @@ using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; using System.Linq; -using Microsoft.DotNet.ProjectModel.Graph; using Microsoft.DotNet.ProjectModel.Utilities; using NuGet.Frameworks; +using NuGet.ProjectModel; namespace Microsoft.DotNet.ProjectModel { @@ -30,13 +30,13 @@ namespace Microsoft.DotNet.ProjectModel = new ConcurrentDictionary(); private readonly ProjectReaderSettings _settings; - private readonly LockFileReader _lockFileReader; + private readonly LockFileFormat _lockFileReader; private readonly bool _designTime; protected Workspace(ProjectReaderSettings settings, bool designTime) { _settings = settings; - _lockFileReader = new LockFileReader(); + _lockFileReader = new LockFileFormat(); _designTime = designTime; } @@ -153,19 +153,19 @@ namespace Microsoft.DotNet.ProjectModel { currentEntry.Reset(); - if (!File.Exists(Path.Combine(projectDirectory, LockFile.FileName))) + if (!File.Exists(Path.Combine(projectDirectory, LockFileFormat.LockFileName))) { return currentEntry; } else { - currentEntry.FilePath = Path.Combine(projectDirectory, LockFile.FileName); + currentEntry.FilePath = Path.Combine(projectDirectory, LockFileFormat.LockFileName); using (var fs = ResilientFileStreamOpener.OpenFile(currentEntry.FilePath, retry: 2)) { try { - currentEntry.Model = _lockFileReader.ReadLockFile(currentEntry.FilePath, fs, designTime: _designTime); + currentEntry.Model = _lockFileReader.Read(fs, currentEntry.FilePath); currentEntry.UpdateLastWriteTimeUtc(); } catch (FileFormatException ex) @@ -214,7 +214,7 @@ namespace Microsoft.DotNet.ProjectModel currentEntry.ProjectFilePath = project.ProjectFilePath; currentEntry.LastProjectFileWriteTimeUtc = File.GetLastWriteTimeUtc(currentEntry.ProjectFilePath); - var lockFilePath = Path.Combine(project.ProjectDirectory, LockFile.FileName); + var lockFilePath = Path.Combine(project.ProjectDirectory, LockFileFormat.LockFileName); if (File.Exists(lockFilePath)) { currentEntry.LockFilePath = lockFilePath; diff --git a/src/Microsoft.DotNet.ProjectModel/project.json b/src/Microsoft.DotNet.ProjectModel/project.json index 8724e521a..e81bfefed 100644 --- a/src/Microsoft.DotNet.ProjectModel/project.json +++ b/src/Microsoft.DotNet.ProjectModel/project.json @@ -11,6 +11,7 @@ "NuGet.Configuration": "3.6.0-beta.1.msbuild.16", "NuGet.Packaging": "3.6.0-beta.1.msbuild.16", "NuGet.RuntimeModel": "3.6.0-beta.1.msbuild.16", + "NuGet.ProjectModel": "3.6.0-beta.1.msbuild.16", "System.Reflection.Metadata": "1.4.1-beta-24410-02" }, "frameworks": { diff --git a/src/dotnet/commands/dotnet-build/CompilerIOManager.cs b/src/dotnet/commands/dotnet-build/CompilerIOManager.cs index 6aa69c0dc..77e35002b 100644 --- a/src/dotnet/commands/dotnet-build/CompilerIOManager.cs +++ b/src/dotnet/commands/dotnet-build/CompilerIOManager.cs @@ -109,12 +109,7 @@ namespace Microsoft.DotNet.Tools.Build throw new InvalidOperationException(errorMessage); } - inputs.Add(project.LockFile.LockFilePath); - - if (project.LockFile.ExportFile != null) - { - inputs.Add(project.LockFile.ExportFile.ExportFilePath); - } + inputs.Add(project.LockFile.Path); } diff --git a/src/dotnet/commands/dotnet-build/ProjectGraphCollector.cs b/src/dotnet/commands/dotnet-build/ProjectGraphCollector.cs index d91384e97..a9035e253 100644 --- a/src/dotnet/commands/dotnet-build/ProjectGraphCollector.cs +++ b/src/dotnet/commands/dotnet-build/ProjectGraphCollector.cs @@ -5,9 +5,9 @@ using System; using System.Collections.Generic; using NuGet.Frameworks; using Microsoft.DotNet.ProjectModel; -using Microsoft.DotNet.ProjectModel.Graph; using System.Linq; using System.Threading.Tasks; +using NuGet.LibraryModel; namespace Microsoft.DotNet.Tools.Build { diff --git a/src/dotnet/commands/dotnet-compile/ManagedCompiler.cs b/src/dotnet/commands/dotnet-compile/ManagedCompiler.cs index 2fb91099a..782c3a653 100644 --- a/src/dotnet/commands/dotnet-compile/ManagedCompiler.cs +++ b/src/dotnet/commands/dotnet-compile/ManagedCompiler.cs @@ -7,15 +7,13 @@ using System.Diagnostics; using System.IO; using System.Linq; using System.Runtime.InteropServices; -using System.Text; -using Microsoft.DotNet.Cli; using Microsoft.DotNet.Cli.Compiler.Common; using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.ProjectModel.Compilation; using Microsoft.Extensions.DependencyModel; using NuGet.Frameworks; -using Microsoft.DotNet.ProjectModel.Graph; +using NuGet.LibraryModel; namespace Microsoft.DotNet.Tools.Compiler { @@ -131,7 +129,7 @@ namespace Microsoft.DotNet.Tools.Compiler StringComparer.OrdinalIgnoreCase); var buildExclusionList = context.GetTypeBuildExclusionList(exportsLookup); var filteredExports = allExports - .Where(e => e.Library.Identity.Type.Equals(LibraryType.ReferenceAssembly) || + .Where(e => e.Library.Identity.Type.Equals(LibraryType.Reference) || !buildExclusionList.Contains(e.Library.Identity.Name)); var dependencyContext = new DependencyContextBuilder().Build(compilationOptions, diff --git a/src/dotnet/commands/dotnet-pack/PackageGenerator.cs b/src/dotnet/commands/dotnet-pack/PackageGenerator.cs index 1edf880ea..62873dd6f 100644 --- a/src/dotnet/commands/dotnet-pack/PackageGenerator.cs +++ b/src/dotnet/commands/dotnet-pack/PackageGenerator.cs @@ -10,7 +10,6 @@ using Microsoft.DotNet.ProjectModel; using Microsoft.DotNet.ProjectModel.Files; using Microsoft.DotNet.ProjectModel.FileSystemGlobbing; using Microsoft.DotNet.ProjectModel.FileSystemGlobbing.Abstractions; -using Microsoft.DotNet.ProjectModel.Graph; using Microsoft.DotNet.ProjectModel.Resources; using Microsoft.DotNet.ProjectModel.Utilities; using Microsoft.DotNet.Tools.Pack; @@ -20,6 +19,7 @@ using NuGet.Packaging.Core; using NuGet.Versioning; using PackageBuilder = NuGet.Legacy.PackageBuilder; using NuGetConstants = NuGet.Legacy.Constants; +using NuGet.LibraryModel; namespace Microsoft.DotNet.Tools.Compiler { @@ -316,7 +316,7 @@ namespace Microsoft.DotNet.Tools.Compiler continue; } - if (dependency.Target == LibraryType.ReferenceAssembly) + if (dependency.LibraryRange.TypeConstraint == LibraryDependencyTarget.Reference) { PackageBuilder.FrameworkAssemblies.Add(new FrameworkAssemblyReference(dependency.Name, new[] { context.TargetFramework })); @@ -326,14 +326,14 @@ namespace Microsoft.DotNet.Tools.Compiler { VersionRange dependencyVersion = null; - if (dependency.VersionRange == null || - dependency.VersionRange.IsFloating) + if (dependency.LibraryRange.VersionRange == null || + dependency.LibraryRange.VersionRange.IsFloating) { dependencyVersion = new VersionRange(dependencyDescription.Identity.Version); } else { - dependencyVersion = dependency.VersionRange; + dependencyVersion = dependency.LibraryRange.VersionRange; } Reporter.Verbose.WriteLine($"Adding dependency {dependency.Name.Yellow()} {VersionUtility.RenderVersion(dependencyVersion).Yellow()}"); diff --git a/src/dotnet/commands/dotnet-projectmodel-server/Helpers/DependencyTypeChangeFinder.cs b/src/dotnet/commands/dotnet-projectmodel-server/Helpers/DependencyTypeChangeFinder.cs index 7865c3126..eed52c0b9 100644 --- a/src/dotnet/commands/dotnet-projectmodel-server/Helpers/DependencyTypeChangeFinder.cs +++ b/src/dotnet/commands/dotnet-projectmodel-server/Helpers/DependencyTypeChangeFinder.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using Microsoft.DotNet.ProjectModel.Graph; +using NuGet.LibraryModel; namespace Microsoft.DotNet.ProjectModel.Server.Helpers { @@ -35,7 +35,7 @@ namespace Microsoft.DotNet.ProjectModel.Server.Helpers private static DiagnosticMessage Validate(LibraryDescription library, HashSet projectCandidates, - Dictionary rootDependencies) + Dictionary rootDependencies) { if (!library.Resolved || projectCandidates == null) { @@ -54,10 +54,10 @@ namespace Microsoft.DotNet.ProjectModel.Server.Helpers return new DiagnosticMessage( ErrorCodes.NU1010, $"The type of dependency {library.Identity.Name} was changed.", - libraryRange.SourceFilePath, + string.Empty, DiagnosticMessageSeverity.Error, - libraryRange.SourceLine, - libraryRange.SourceColumn, + 0, + 0, library); } diff --git a/src/dotnet/commands/dotnet-projectmodel-server/Helpers/LibraryExtensions.cs b/src/dotnet/commands/dotnet-projectmodel-server/Helpers/LibraryExtensions.cs deleted file mode 100644 index 2c86daade..000000000 --- a/src/dotnet/commands/dotnet-projectmodel-server/Helpers/LibraryExtensions.cs +++ /dev/null @@ -1,21 +0,0 @@ -// 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.DotNet.ProjectModel.Graph; - -namespace Microsoft.DotNet.ProjectModel.Server.Helpers -{ - public static class LibraryExtensions - { - public static string GetUniqueName(this LibraryDescription library) - { - var identity = library.Identity; - return identity.Type != LibraryType.ReferenceAssembly ? identity.Name : $"fx/{identity.Name}"; - } - - public static string GetUniqueName(this LibraryRange range) - { - return range.Target != LibraryType.ReferenceAssembly ? range.Name : $"fx/{range.Name}"; - } - } -} diff --git a/src/dotnet/commands/dotnet-projectmodel-server/InternalModels/ProjectContextSnapshot.cs b/src/dotnet/commands/dotnet-projectmodel-server/InternalModels/ProjectContextSnapshot.cs index 1307714d0..997e56cd2 100644 --- a/src/dotnet/commands/dotnet-projectmodel-server/InternalModels/ProjectContextSnapshot.cs +++ b/src/dotnet/commands/dotnet-projectmodel-server/InternalModels/ProjectContextSnapshot.cs @@ -6,10 +6,10 @@ using System.Collections.Generic; using System.Linq; using Microsoft.DotNet.Cli.Compiler.Common; using Microsoft.DotNet.ProjectModel.Files; -using Microsoft.DotNet.ProjectModel.Graph; using Microsoft.DotNet.ProjectModel.Server.Helpers; using Microsoft.DotNet.ProjectModel.Server.Models; using NuGet.Frameworks; +using NuGet.LibraryModel; namespace Microsoft.DotNet.ProjectModel.Server { diff --git a/src/dotnet/commands/dotnet-projectmodel-server/Models/DependencyDescription.cs b/src/dotnet/commands/dotnet-projectmodel-server/Models/DependencyDescription.cs index 32c3854e5..7c1e3ee1e 100644 --- a/src/dotnet/commands/dotnet-projectmodel-server/Models/DependencyDescription.cs +++ b/src/dotnet/commands/dotnet-projectmodel-server/Models/DependencyDescription.cs @@ -4,7 +4,7 @@ using System.Collections.Generic; using System.Linq; using Microsoft.DotNet.ProjectModel.Compilation; -using Microsoft.DotNet.ProjectModel.Graph; +using NuGet.LibraryModel; using NuGet.Versioning; namespace Microsoft.DotNet.ProjectModel.Server.Models @@ -81,7 +81,7 @@ namespace Microsoft.DotNet.ProjectModel.Server.Models return result; } - private static DependencyItem GetDependencyItem(LibraryRange dependency, + private static DependencyItem GetDependencyItem(LibraryDependency dependency, IDictionary exportsLookup) { return new DependencyItem