Replacing the LockFile APIs from the one in ProjectModel to the one in NuGet.ProjectModel.
This commit is contained in:
parent
48eafab581
commit
6527cbc592
66 changed files with 292 additions and 1525 deletions
|
@ -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;
|
||||
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using Microsoft.DotNet.ProjectModel.Graph;
|
||||
using NuGet.ProjectModel;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.Utils
|
||||
{
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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<LibraryRange> toolsLibraries,
|
||||
IEnumerable<LibraryDependency> toolsLibraries,
|
||||
string commandName,
|
||||
IEnumerable<string> 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)
|
||||
{
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.Utils
|
||||
{
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.Utils
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Microsoft.DotNet.Cli.Utils
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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<LibraryExport> GetAllProjectTypeDependencies(this LibraryExporter exporter)
|
||||
{
|
||||
return
|
||||
exporter.GetDependencies(LibraryType.Project)
|
||||
.Concat(exporter.GetDependencies(LibraryType.MSBuildProject));
|
||||
exporter.GetDependencies(LibraryType.Project);
|
||||
}
|
||||
|
||||
public static void CopyTo(this IEnumerable<LibraryAsset> assets, string destinationPath)
|
||||
|
|
|
@ -13,7 +13,8 @@
|
|||
},
|
||||
"Microsoft.DotNet.Files": {
|
||||
"target": "project"
|
||||
}
|
||||
},
|
||||
"NuGet.ProjectModel": "3.6.0-beta.1.msbuild.9"
|
||||
},
|
||||
"frameworks": {
|
||||
"net451": {
|
||||
|
|
|
@ -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<ProjectDependency> ResolveProjectDependencies(IEnumerable<ProjectContext> projectContexts, IEnumerable<string> preResolvedProjects=null)
|
||||
public IEnumerable<ProjectDependency> ResolveProjectDependencies(
|
||||
IEnumerable<ProjectContext> projectContexts,
|
||||
IEnumerable<string> preResolvedProjects=null)
|
||||
{
|
||||
foreach(var projectContext in projectContexts)
|
||||
{
|
||||
|
@ -41,7 +42,9 @@ namespace Microsoft.DotNet.ProjectJsonMigration
|
|||
}
|
||||
}
|
||||
|
||||
public IEnumerable<ProjectDependency> ResolveProjectDependencies(ProjectContext projectContext, IEnumerable<string> preResolvedProjects=null)
|
||||
public IEnumerable<ProjectDependency> ResolveProjectDependencies(
|
||||
ProjectContext projectContext,
|
||||
IEnumerable<string> preResolvedProjects=null)
|
||||
{
|
||||
preResolvedProjects = preResolvedProjects ?? new HashSet<string>();
|
||||
|
||||
|
|
|
@ -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
|
|||
/// <returns></returns>
|
||||
public IEnumerable<LibraryExport> GetDependencies()
|
||||
{
|
||||
return GetDependencies(LibraryType.Unspecified);
|
||||
return GetDependencies(null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all exports required by the project, of the specified <see cref="LibraryType"/>, NOT including the project itself
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IEnumerable<LibraryExport> GetDependencies(LibraryType type)
|
||||
public IEnumerable<LibraryExport> 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<AnalyzerReference>();
|
||||
|
||||
// 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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<string> assemblies;
|
||||
if (type == LibraryType.ReferenceAssembly)
|
||||
if (type == LibraryType.Reference)
|
||||
{
|
||||
assemblies = ResolveReferenceAssembliesPath(export.CompilationAssemblies);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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<BuildAction>
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NuGet.ProjectModel;
|
||||
|
||||
namespace Microsoft.DotNet.ProjectModel.Graph
|
||||
{
|
||||
|
|
|
@ -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<LibraryDependencyType>, IEquatable<string>
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
|
@ -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<LibraryIdentity>
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<LibraryRange>
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<LibraryType>
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<ProjectFileDependencyGroup> ProjectFileDependencyGroups { get; set; } = new List<ProjectFileDependencyGroup>();
|
||||
public IList<LockFilePackageLibrary> PackageLibraries { get; set; } = new List<LockFilePackageLibrary>();
|
||||
public IList<LockFileProjectLibrary> ProjectLibraries { get; set; } = new List<LockFileProjectLibrary>();
|
||||
public IList<LockFileTarget> Targets { get; set; } = new List<LockFileTarget>();
|
||||
public ExportFile ExportFile { get; set; }
|
||||
public IList<LockFilePackageFolder> PackageFolders { get; set; } = new List<LockFilePackageFolder>();
|
||||
|
||||
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<string> 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);
|
||||
}
|
||||
|
|
@ -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<string, string>();;
|
||||
}
|
||||
|
||||
public LockFileItem(string path) : this()
|
||||
{
|
||||
Path = path;
|
||||
}
|
||||
|
||||
public LockFileItem(string path, IDictionary<string, string> properties) : this(path)
|
||||
{
|
||||
Properties = new Dictionary<string, string>(properties);
|
||||
}
|
||||
|
||||
public string Path { get; set; }
|
||||
|
||||
public IDictionary<string, string> 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;
|
||||
}
|
||||
}
|
|
@ -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<Tuple<string, NuGetVersion>, LockFilePackageLibrary> _packages;
|
||||
private readonly Dictionary<string, LockFileProjectLibrary> _projects;
|
||||
private readonly Dictionary<Tuple<string, NuGetVersion>, LockFileLibrary> _packages;
|
||||
private readonly Dictionary<string, LockFileLibrary> _projects;
|
||||
|
||||
public LockFileLookup(LockFile lockFile)
|
||||
{
|
||||
_packages = new Dictionary<Tuple<string, NuGetVersion>, LockFilePackageLibrary>();
|
||||
_projects = new Dictionary<string, LockFileProjectLibrary>();
|
||||
_packages = new Dictionary<Tuple<string, NuGetVersion>, LockFileLibrary>();
|
||||
_projects = new Dictionary<string, LockFileLibrary>();
|
||||
|
||||
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;
|
||||
|
|
|
@ -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; }
|
||||
}
|
||||
}
|
|
@ -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<string> Files { get; set; } = new List<string>();
|
||||
|
||||
public string Path { get; set; }
|
||||
}
|
||||
}
|
|
@ -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<string, IList<LockFileTargetLibrary>> _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<LockFileTargetLibrary> 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)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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; }
|
||||
}
|
||||
}
|
|
@ -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<JObject>("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<JObject>("targets"), ReadTarget);
|
||||
lockFile.ProjectFileDependencyGroups = ReadObject(cursor.Value<JObject>("projectFileDependencyGroups"), ReadProjectFileDependencyGroup);
|
||||
ReadLibrary(cursor.Value<JObject>("libraries"), lockFile);
|
||||
lockFile.PackageFolders = ReadObject(cursor.Value<JObject>("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<JObject>(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<string>("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<string>("type"));
|
||||
var framework = jobject.Value<string>("framework");
|
||||
if (framework != null)
|
||||
{
|
||||
library.TargetFramework = _symbols.GetFramework(framework);
|
||||
}
|
||||
|
||||
library.Dependencies = ReadObject(jobject.Value<JObject>("dependencies"), ReadPackageDependency);
|
||||
library.FrameworkAssemblies = new HashSet<string>(ReadArray(jobject["frameworkAssemblies"], ReadFrameworkAssemblyReference), StringComparer.OrdinalIgnoreCase);
|
||||
library.RuntimeAssemblies = ReadObject(jobject.Value<JObject>("runtime"), ReadFileItem);
|
||||
library.CompileTimeAssemblies = ReadObject(jobject.Value<JObject>("compile"), ReadFileItem);
|
||||
library.ResourceAssemblies = ReadObject(jobject.Value<JObject>("resource"), ReadFileItem);
|
||||
library.NativeLibraries = ReadObject(jobject.Value<JObject>("native"), ReadFileItem);
|
||||
library.ContentFiles = ReadObject(jobject.Value<JObject>("contentFiles"), ReadContentFile);
|
||||
library.RuntimeTargets = ReadObject(jobject.Value<JObject>("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<string>("rid")),
|
||||
assetType: _symbols.GetString(jsonObject.Value<string>("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<string>("buildAction"), out action);
|
||||
|
||||
contentFile.BuildAction = action;
|
||||
var codeLanguage = _symbols.GetString(jsonObject.Value<string>("codeLanguage"));
|
||||
if (codeLanguage == "any")
|
||||
{
|
||||
codeLanguage = null;
|
||||
}
|
||||
contentFile.CodeLanguage = codeLanguage;
|
||||
contentFile.OutputPath = jsonObject.Value<string>("outputPath");
|
||||
contentFile.PPOutputPath = jsonObject.Value<string>("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<string>(child.Key);
|
||||
}
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
private string ReadFrameworkAssemblyReference(JToken json)
|
||||
{
|
||||
return ReadString(json);
|
||||
}
|
||||
|
||||
private static IList<TItem> ReadArray<TItem>(JToken json, Func<JToken, TItem> readItem)
|
||||
{
|
||||
if (json == null)
|
||||
{
|
||||
return new List<TItem>();
|
||||
}
|
||||
|
||||
var jarray = json as JArray;
|
||||
if (jarray == null)
|
||||
{
|
||||
throw FileFormatException.Create("The value type is not array.", json);
|
||||
}
|
||||
|
||||
var items = new List<TItem>();
|
||||
for (int i = 0; i < jarray.Count; ++i)
|
||||
{
|
||||
items.Add(readItem(jarray[i]));
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
private IList<string> ReadPathArray(JToken json, Func<JToken, string> readItem)
|
||||
{
|
||||
return ReadArray(json, readItem).Select(f => _symbols.GetString(PathUtility.GetPathWithDirectorySeparator(f))).ToList();
|
||||
}
|
||||
|
||||
private static IList<TItem> ReadObject<TItem>(JObject json, Func<string, JToken, TItem> readItem)
|
||||
{
|
||||
if (json == null)
|
||||
{
|
||||
return new List<TItem>();
|
||||
}
|
||||
var items = new List<TItem>();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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; }
|
||||
}
|
||||
}
|
|
@ -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<string, NuGetVersion> _versionTable = new ConcurrentDictionary<string, NuGetVersion>(Environment.ProcessorCount * 4, 1000, StringComparer.Ordinal);
|
||||
private ConcurrentDictionary<string, VersionRange> _versionRangeTable = new ConcurrentDictionary<string, VersionRange>(Environment.ProcessorCount * 4, 1000, StringComparer.Ordinal);
|
||||
private ConcurrentDictionary<string, NuGetFramework> _frameworksTable = new ConcurrentDictionary<string, NuGetFramework>(Environment.ProcessorCount * 4, 1000, StringComparer.Ordinal);
|
||||
private ConcurrentDictionary<string, string> _stringsTable = new ConcurrentDictionary<string, string>(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);
|
||||
}
|
||||
}
|
|
@ -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<LockFileTargetLibrary> Libraries { get; set; } = new List<LockFileTargetLibrary>();
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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<PackageDependency> Dependencies { get; set; } = new List<PackageDependency>();
|
||||
|
||||
public ISet<string> FrameworkAssemblies { get; set; } = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
public IList<LockFileItem> RuntimeAssemblies { get; set; } = new List<LockFileItem>();
|
||||
|
||||
public IList<LockFileItem> CompileTimeAssemblies { get; set; } = new List<LockFileItem>();
|
||||
|
||||
public IList<LockFileItem> ResourceAssemblies { get; set; } = new List<LockFileItem>();
|
||||
|
||||
public IList<LockFileItem> NativeLibraries { get; set; } = new List<LockFileItem>();
|
||||
|
||||
public IList<LockFileContentFile> ContentFiles { get; set; } = new List<LockFileContentFile>();
|
||||
|
||||
public IList<LockFileRuntimeTarget> RuntimeTargets { get; set; } = new List<LockFileRuntimeTarget>();
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<LibraryRange> dependencies,
|
||||
IEnumerable<ProjectLibraryDependency> 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<LibraryRange>();
|
||||
Dependencies = dependencies ?? Enumerable.Empty<ProjectLibraryDependency>();
|
||||
Framework = framework;
|
||||
Resolved = resolved;
|
||||
Compatible = compatible;
|
||||
|
@ -35,10 +33,10 @@ namespace Microsoft.DotNet.ProjectModel
|
|||
|
||||
public LibraryIdentity Identity { get; }
|
||||
public string Hash { get; }
|
||||
public HashSet<LibraryRange> RequestedRanges { get; } = new HashSet<LibraryRange>(new LibraryRangeEqualityComparer());
|
||||
public HashSet<ProjectLibraryDependency> RequestedRanges { get; } = new HashSet<ProjectLibraryDependency>();
|
||||
public List<LibraryDescription> Parents { get; } = new List<LibraryDescription>();
|
||||
public string Path { get; }
|
||||
public IEnumerable<LibraryRange> Dependencies { get; }
|
||||
public IEnumerable<ProjectLibraryDependency> 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<LibraryRange>
|
||||
{
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<LibraryRange> dependencies,
|
||||
IEnumerable<ProjectLibraryDependency> 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; }
|
||||
|
||||
|
|
|
@ -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<LibraryRange> dependencies,
|
||||
IEnumerable<ProjectLibraryDependency> 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<LockFileItem> RuntimeAssemblies => FilterPlaceholders(base.RuntimeAssemblies);
|
||||
|
||||
public override IEnumerable<LockFileItem> 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<LockFileItem> FilterPlaceholders(IEnumerable<LockFileItem> items)
|
||||
{
|
||||
return items.Where(a => !PackageDependencyProvider.IsPlaceholderFile(a));
|
||||
return items.Where(a => !PackageDependencyProvider.IsPlaceholderFile(a.Path));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<LibraryRange> Dependencies { get; set; }
|
||||
public IList<ProjectLibraryDependency> Dependencies { get; set; }
|
||||
|
||||
public List<LibraryRange> Tools { get; set; }
|
||||
public List<ProjectLibraryDependency> Tools { get; set; }
|
||||
|
||||
public string EntryPoint { get; set; }
|
||||
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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<LibraryRange?>()
|
||||
.Cast<ProjectLibraryDependency>()
|
||||
.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)
|
||||
{
|
||||
|
|
|
@ -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<LibraryRange>(),
|
||||
Enumerable.Empty<ProjectLibraryDependency>(),
|
||||
framework: null,
|
||||
resolved: false,
|
||||
compatible: false)
|
||||
|
@ -25,7 +25,7 @@ namespace Microsoft.DotNet.ProjectModel
|
|||
public ProjectDescription(
|
||||
LibraryRange libraryRange,
|
||||
Project project,
|
||||
IEnumerable<LibraryRange> dependencies,
|
||||
IEnumerable<ProjectLibraryDependency> dependencies,
|
||||
TargetFrameworkInformation targetFrameworkInfo,
|
||||
bool resolved) :
|
||||
base(
|
||||
|
|
|
@ -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<string, LibraryExport> exports, IEnumerable<LibraryRange> dependencies, HashSet<string> exclusionList)
|
||||
private static void CollectDependencies(
|
||||
IDictionary<string, LibraryExport> exports,
|
||||
IEnumerable<LibraryDependency> dependencies,
|
||||
HashSet<string> 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<string, LibraryExport> exports, IEnumerable<LibraryRange> dependencies, HashSet<string> acceptedExports)
|
||||
private static void CollectNonBuildDependencies(
|
||||
IDictionary<string, LibraryExport> exports,
|
||||
IEnumerable<LibraryDependency> dependencies,
|
||||
HashSet<string> acceptedExports)
|
||||
{
|
||||
foreach (var dependency in dependencies)
|
||||
{
|
||||
|
|
|
@ -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<bool>("embedInteropTypes");
|
||||
|
||||
project.Dependencies = new List<LibraryRange>();
|
||||
project.Tools = new List<LibraryRange>();
|
||||
project.Dependencies = new List<ProjectLibraryDependency>();
|
||||
project.Tools = new List<ProjectLibraryDependency>();
|
||||
|
||||
// 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<LibraryRange> results,
|
||||
IList<ProjectLibraryDependency> 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<string>("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<string>("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<LibraryRange>()
|
||||
Dependencies = new List<ProjectLibraryDependency>()
|
||||
};
|
||||
|
||||
// Add default configurations
|
||||
|
@ -470,13 +466,13 @@ namespace Microsoft.DotNet.ProjectModel
|
|||
var targetFrameworkInformation = new TargetFrameworkInformation
|
||||
{
|
||||
FrameworkName = frameworkName,
|
||||
Dependencies = new List<LibraryRange>(),
|
||||
Dependencies = new List<ProjectLibraryDependency>(),
|
||||
CompilerOptions = compilerOptions,
|
||||
Line = lineInfo.LineNumber,
|
||||
Column = lineInfo.LinePosition
|
||||
};
|
||||
|
||||
var frameworkDependencies = new List<LibraryRange>();
|
||||
var frameworkDependencies = new List<ProjectLibraryDependency>();
|
||||
|
||||
PopulateDependencies(
|
||||
project.ProjectFilePath,
|
||||
|
@ -485,7 +481,7 @@ namespace Microsoft.DotNet.ProjectModel
|
|||
"dependencies",
|
||||
isGacOrFrameworkReference: false);
|
||||
|
||||
var frameworkAssemblies = new List<LibraryRange>();
|
||||
var frameworkAssemblies = new List<ProjectLibraryDependency>();
|
||||
PopulateDependencies(
|
||||
project.ProjectFilePath,
|
||||
frameworkAssemblies,
|
||||
|
|
|
@ -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<DiagnosticMessage> messages,
|
||||
|
@ -229,7 +228,7 @@ namespace Microsoft.DotNet.ProjectModel.Resolution
|
|||
}
|
||||
}
|
||||
|
||||
private IEnumerable<LibraryRange> GetRangesWithSourceLocations(LibraryDescription library)
|
||||
private IEnumerable<ProjectLibraryDependency> 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;
|
||||
|
|
|
@ -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<LibraryRange>(targetLibrary.Dependencies.Count + targetLibrary.FrameworkAssemblies.Count);
|
||||
var dependencies = new List<ProjectLibraryDependency>(
|
||||
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<LibraryRange> dependencies,
|
||||
List<ProjectLibraryDependency> 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)
|
||||
|
|
|
@ -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<LibraryRange>(targetLibrary.Dependencies.Count + targetLibrary.FrameworkAssemblies.Count);
|
||||
var dependencies = new List<ProjectLibraryDependency>(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<LibraryRange> dependencies, string packagePath, LockFileTargetLibrary targetLibrary)
|
||||
private void PopulateLegacyPortableDependencies(
|
||||
NuGetFramework targetFramework,
|
||||
List<ProjectLibraryDependency> dependencies,
|
||||
string packagePath,
|
||||
LockFileTargetLibrary targetLibrary)
|
||||
{
|
||||
var seen = new HashSet<string>();
|
||||
|
||||
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<LibraryRange> dependencies,
|
||||
List<ProjectLibraryDependency> 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)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<LibraryRange>(targetFrameworkInfo.Dependencies);
|
||||
var dependencies = new List<ProjectLibraryDependency>(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<LibraryRange> dependencies, string dependencyName)
|
||||
private static void AddIfMissing(List<ProjectLibraryDependency> 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)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<LibraryRange>(),
|
||||
Enumerable.Empty<ProjectLibraryDependency>(),
|
||||
targetFramework,
|
||||
resolved: true,
|
||||
compatible: true);
|
||||
|
|
|
@ -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<LibraryRange>(),
|
||||
dependencies: Enumerable.Empty<ProjectLibraryDependency>(),
|
||||
framework: targetFramework,
|
||||
resolved: false,
|
||||
compatible: true);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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<LibraryRange> Dependencies { get; set; }
|
||||
public IReadOnlyList<ProjectLibraryDependency> Dependencies { get; set; }
|
||||
|
||||
public CommonCompilerOptions CompilerOptions { get; set; }
|
||||
|
||||
|
|
|
@ -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<LibraryRange> dependencies,
|
||||
IEnumerable<ProjectLibraryDependency> dependencies,
|
||||
bool compatible,
|
||||
bool resolved,
|
||||
NuGetFramework framework = null)
|
||||
|
|
|
@ -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<string, ProjectContextCollection>();
|
||||
|
||||
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;
|
||||
|
|
|
@ -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": {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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()}");
|
||||
|
|
|
@ -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<string> projectCandidates,
|
||||
Dictionary<string, LibraryRange> rootDependencies)
|
||||
Dictionary<string, ProjectLibraryDependency> 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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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}";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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
|
||||
{
|
||||
|
|
|
@ -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<string, LibraryExport> exportsLookup)
|
||||
{
|
||||
return new DependencyItem
|
||||
|
|
Loading…
Reference in a new issue