Merge pull request #4253 from livarcocc/projectlockfile_from_nuget_projectmodel

Moving Projectlockfile Apis from Microsoft.DotNet.ProjectModel to NuGet.ProjectModel
This commit is contained in:
Livar 2016-09-27 15:51:07 -07:00 committed by GitHub
commit 1278e9d6bf
77 changed files with 427 additions and 1803 deletions

View file

@ -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;

View file

@ -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
{

View file

@ -1,5 +1,5 @@
using System.Collections.Generic;
using Microsoft.DotNet.ProjectModel.Graph;
using NuGet.ProjectModel;
namespace Microsoft.DotNet.Cli.Utils
{

View file

@ -3,8 +3,9 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.DotNet.Tools.Common;
using NuGet.Packaging;
using NuGet.ProjectModel;
namespace Microsoft.DotNet.Cli.Utils
{
@ -50,7 +51,7 @@ namespace Microsoft.DotNet.Cli.Utils
var packageDirectory = new VersionFolderPathResolver(nugetPackagesRoot)
.GetInstallPath(toolLibrary.Name, toolLibrary.Version);
var filePath = Path.Combine(packageDirectory, runtimeAssembly.Path);
var filePath = Path.Combine(packageDirectory, PathUtility.GetPathWithDirectorySeparator(runtimeAssembly.Path));
return filePath;
}

View file

@ -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
{

View file

@ -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)
{

View file

@ -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
{

View file

@ -1,7 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Microsoft.DotNet.Cli.Utils
{

View file

@ -1,4 +1,3 @@
using System;
using System.Reflection;
namespace Microsoft.DotNet.Cli.Utils

View file

@ -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
{

View file

@ -3,7 +3,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Microsoft.DotNet.Cli.Utils

View file

@ -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
{

View file

@ -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)

View file

@ -13,7 +13,8 @@
},
"Microsoft.DotNet.Files": {
"target": "project"
}
},
"NuGet.ProjectModel": "3.6.0-beta.1.msbuild.16"
},
"frameworks": {
"net451": {
@ -29,6 +30,9 @@
},
"System.Threading.Tasks": {
"type": "build"
},
"System.Text.Encoding": {
"type": "build"
}
}
},

View file

@ -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>();

View file

@ -8,7 +8,6 @@ using System.Linq;
using Microsoft.Build.Construction;
using Microsoft.DotNet.ProjectJsonMigration.Transforms;
using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.DotNet.Tools.Common;
using NuGet.Frameworks;

View file

@ -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);
}
@ -212,13 +212,16 @@ namespace Microsoft.DotNet.ProjectModel.Compilation
var sourceCodeLanguage = _rootProject.Project.GetSourceCodeLanguage();
var languageGroups = library.ContentFiles.GroupBy(file => file.CodeLanguage);
var selectedGroup = languageGroups.FirstOrDefault(g => g.Key == sourceCodeLanguage) ??
languageGroups.FirstOrDefault(g => g.Key == "any") ??
languageGroups.FirstOrDefault(g => g.Key == null);
if (selectedGroup != null)
{
foreach (var contentFile in selectedGroup)
{
if (contentFile.CodeLanguage != null &&
contentFile.CodeLanguage != "any" &&
string.Compare(contentFile.CodeLanguage, sourceCodeLanguage, StringComparison.OrdinalIgnoreCase) != 0)
{
continue;
@ -403,6 +406,7 @@ namespace Microsoft.DotNet.ProjectModel.Compilation
return package
.PackageLibrary
.Files
.Select(f => PathUtility.GetPathWithDirectorySeparator(f))
.Where(path => path.StartsWith("shared" + Path.DirectorySeparatorChar))
.Select(path => LibraryAsset.CreateFromRelativePath(package.Path, path));
}
@ -412,11 +416,13 @@ namespace Microsoft.DotNet.ProjectModel.Compilation
var analyzers = package
.PackageLibrary
.Files
.Select(f => PathUtility.GetPathWithDirectorySeparator(f))
.Where(path => path.StartsWith("analyzers" + Path.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 +505,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
}
}

View file

@ -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);
}

View file

@ -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
{

View file

@ -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);
}
}
}

View file

@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using NuGet.ProjectModel;
namespace Microsoft.DotNet.ProjectModel.Graph
{

View file

@ -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);
}
}

View file

@ -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);
}
}
}

View file

@ -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();
}
}
}

View file

@ -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);
}
}
}

View file

@ -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,39 +27,41 @@ 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)
{
Console.WriteLine($"Different count; {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);
// If the framework name is empty, the associated dependencies are shared by all frameworks
if (group.FrameworkName == null)
if (string.IsNullOrEmpty(group.FrameworkName))
{
actualDependencies = project.Dependencies
.Select(d => d.ToLockFileDependencyGroupString())
.Select(d => d.LibraryRange.ToLockFileDependencyGroupString())
.OrderBy(x => x, StringComparer.OrdinalIgnoreCase);
}
else
{
var framework = actualTargetFrameworks
.FirstOrDefault(f => Equals(f.FrameworkName, group.FrameworkName));
.FirstOrDefault(f => Equals(f.FrameworkName.DotNetFrameworkName, group.FrameworkName));
if (framework == null)
{
return false;
}
actualDependencies = framework.Dependencies
.Select(d => d.ToLockFileDependencyGroupString())
.Select(d => d.LibraryRange.ToLockFileDependencyGroupString())
.OrderBy(x => x, StringComparer.OrdinalIgnoreCase);
}
if (!actualDependencies.SequenceEqual(expectedDependencies))
{
Console.WriteLine($"ActualDependencies don't match");
return false;
}
}

View file

@ -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;
}
}

View file

@ -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;

View file

@ -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; }
}
}

View file

@ -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; }
}
}

View file

@ -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)
{
}
}
}

View file

@ -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; }
}
}

View file

@ -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);
}
}
}
}

View file

@ -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; }
}
}

View file

@ -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);
}
}

View file

@ -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>();
}
}

View file

@ -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;
}
}

View file

@ -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>();
}
}

View file

@ -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;
}
}
}

View file

@ -4,9 +4,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.DotNet.PlatformAbstractions;
using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.DotNet.PlatformAbstractions;
using NuGet.Frameworks;
using NuGet.LibraryModel;
namespace Microsoft.DotNet.ProjectModel
{
@ -19,7 +19,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 +27,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 +35,11 @@ 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>(new LibraryRangeEqualityComparer());
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; }
@ -49,28 +50,28 @@ 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)
// For diagnostics, we don't want to duplicate requested dependencies so we
// dedupe dependencies defined in project.json
private class LibraryRangeEqualityComparer : IEqualityComparer<ProjectLibraryDependency>
{
public bool Equals(ProjectLibraryDependency x, ProjectLibraryDependency y)
{
return x.Equals(y) &&
x.SourceColumn == y.SourceColumn &&
x.SourceLine == y.SourceLine &&
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;
}
}
public int GetHashCode(ProjectLibraryDependency obj)
{
var combiner = HashCodeCombiner.Start();
combiner.Add(obj);
combiner.Add(obj.SourceFilePath);
combiner.Add(obj.SourceLine);
combiner.Add(obj.SourceColumn);
return combiner.CombinedHash;
}
}
}
}

View file

@ -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; }

View file

@ -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));
}
}
}

View file

@ -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; }

View file

@ -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
{

View file

@ -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)
{

View file

@ -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(

View file

@ -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)
{

View file

@ -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.All;
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,17 @@ 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,
SourceFilePath = projectPath,
SourceLine = lineInfo.LineNumber,
SourceColumn = lineInfo.LinePosition
});
}
}
}
@ -352,7 +351,7 @@ namespace Microsoft.DotNet.ProjectModel
project._defaultTargetFrameworkConfiguration = new TargetFrameworkInformation
{
Dependencies = new List<LibraryRange>()
Dependencies = new List<ProjectLibraryDependency>()
};
// Add default configurations
@ -470,13 +469,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 +484,7 @@ namespace Microsoft.DotNet.ProjectModel
"dependencies",
isGacOrFrameworkReference: false);
var frameworkAssemblies = new List<LibraryRange>();
var frameworkAssemblies = new List<ProjectLibraryDependency>();
PopulateDependencies(
project.ProjectFilePath,
frameworkAssemblies,

View file

@ -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;

View file

@ -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)

View file

@ -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,11 +34,15 @@ 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
var containsAssembly = package.Files
.Select(f => f.Replace('/', Path.DirectorySeparatorChar))
.Any(x => x.StartsWith($"ref{Path.DirectorySeparatorChar}") ||
x.StartsWith($"lib{Path.DirectorySeparatorChar}"));
@ -46,7 +51,8 @@ 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 +83,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 +126,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 +152,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 +168,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)
});
}
}
}

View file

@ -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.Reference)
});
}
}
}

View file

@ -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);

View file

@ -2,23 +2,47 @@
// 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,
GetLibraryTypeFromLibraryDependencyTarget(libraryDependency.LibraryRange.TypeConstraint)),
hash: null,
path: null,
dependencies: Enumerable.Empty<LibraryRange>(),
dependencies: Enumerable.Empty<ProjectLibraryDependency>(),
framework: targetFramework,
resolved: false,
compatible: true);
}
private static LibraryType GetLibraryTypeFromLibraryDependencyTarget(LibraryDependencyTarget target)
{
switch(target)
{
case LibraryDependencyTarget.Package:
return LibraryType.Package;
case LibraryDependencyTarget.Project:
return LibraryType.Project;
case LibraryDependencyTarget.Reference:
return LibraryType.Reference;
case LibraryDependencyTarget.Assembly:
return LibraryType.Assembly;
case LibraryDependencyTarget.ExternalProject:
return LibraryType.ExternalProject;
case LibraryDependencyTarget.WinMD:
return LibraryType.WinMD;
default:
return LibraryType.Unresolved;
}
}
}
}

View file

@ -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

View file

@ -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; }

View file

@ -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)

View file

@ -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;

View file

@ -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": {

View file

@ -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);
}

View file

@ -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
{

View file

@ -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,

View file

@ -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
{
@ -124,7 +124,10 @@ namespace Microsoft.DotNet.Tools.Compiler
if (Project.PackOptions.PackInclude != null)
{
var files = IncludeFilesResolver.GetIncludeFiles(Project.PackOptions.PackInclude, "/", diagnostics: packDiagnostics);
var files = IncludeFilesResolver.GetIncludeFiles(
Project.PackOptions.PackInclude,
"/",
diagnostics: packDiagnostics);
PackageBuilder.Files.AddRange(GetPackageFiles(files, packDiagnostics));
}
else if (Project.Files.PackInclude != null && Project.Files.PackInclude.Any())
@ -300,9 +303,10 @@ namespace Microsoft.DotNet.Tools.Compiler
{
continue;
}
// TODO: Efficiency
var dependencyDescription = context.LibraryManager.GetLibraries().First(l => l.RequestedRanges.Contains(dependency));
var dependencyDescription =
context.LibraryManager.GetLibraries().First(l => l.RequestedRanges.Contains(dependency));
// REVIEW: Can we get this far with unresolved dependencies
if (dependencyDescription == null || !dependencyDescription.Resolved)
@ -316,9 +320,10 @@ 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 }));
PackageBuilder.FrameworkAssemblies.Add(
new FrameworkAssemblyReference(dependency.Name, new[] { context.TargetFramework }));
Reporter.Verbose.WriteLine($"Adding framework assembly {dependency.Name.Yellow()}");
}
@ -326,14 +331,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()}");

View file

@ -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)
{

View file

@ -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}";
}
}
}

View file

@ -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
{

View file

@ -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

View file

@ -1,15 +1,14 @@
// 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.IO;
using System.Linq;
using FluentAssertions;
using Microsoft.DotNet.ProjectModel;
using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.DotNet.TestFramework;
using Microsoft.DotNet.Tools.Test.Utilities;
using NuGet.Frameworks;
using NuGet.ProjectModel;
using NuGet.Versioning;
using Xunit;
@ -208,7 +207,7 @@ namespace Microsoft.DotNet.Cli.Utils.Tests
new NuGetVersion("1.0.0"),
s_toolPackageFramework);
var lockFile = LockFileReader.Read(lockFilePath, designTime: false);
var lockFile = new LockFileFormat().Read(lockFilePath);
var depsJsonFile = Path.Combine(
Path.GetDirectoryName(lockFilePath),

View file

@ -20,10 +20,10 @@
},
"System.Diagnostics.TraceSource": "4.0.0",
"System.Runtime.Serialization.Primitives": "4.1.1",
"NuGet.Versioning": "3.6.0-beta.1.msbuild.4",
"NuGet.Packaging": "3.6.0-beta.1.msbuild.4",
"NuGet.Frameworks": "3.6.0-beta.1.msbuild.4",
"NuGet.ProjectModel": "3.6.0-beta.1.msbuild.4",
"NuGet.Versioning": "3.6.0-beta.1.msbuild.15",
"NuGet.Packaging": "3.6.0-beta.1.msbuild.15",
"NuGet.Frameworks": "3.6.0-beta.1.msbuild.15",
"NuGet.ProjectModel": "3.6.0-beta.1.msbuild.15",
"Microsoft.DotNet.ProjectModel": {
"target": "project"
},

View file

@ -2,10 +2,8 @@
// 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.Text;
using Microsoft.DotNet.ProjectModel;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Xunit;

View file

@ -1,19 +1,16 @@
// 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 System.IO;
using System.Text;
using Xunit;
using Microsoft.DotNet.ProjectModel;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using FluentAssertions;
using NuGet.Versioning;
using System.Linq;
using NuGet.ProjectModel;
using Microsoft.DotNet.ProjectModel.Graph;
using NuGet.LibraryModel;
namespace Microsoft.DotNet.ProjectModel.Tests
{
@ -727,7 +724,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests
var dependency = project.Dependencies.First();
dependency.VersionRange.Should().BeNull();
dependency.LibraryRange.VersionRange.Should().BeNull();
}
[Fact]
@ -742,8 +739,8 @@ namespace Microsoft.DotNet.ProjectModel.Tests
var dependency = project.Dependencies.First();
dependency.Name.Should().Be(DependencyName);
dependency.VersionRange.Should().Be(_versionRange);
dependency.Target.Should().Be(LibraryType.Unspecified);
dependency.LibraryRange.VersionRange.Should().Be(_versionRange);
dependency.LibraryRange.TypeConstraint.Should().Be(LibraryDependencyTarget.All);
dependency.Type.Should().Be(LibraryDependencyType.Default);
dependency.SourceFilePath.Should().Be(ProjectFilePath);
dependency.SourceLine.Should().Be(3);
@ -764,8 +761,8 @@ namespace Microsoft.DotNet.ProjectModel.Tests
var dependency = project.Dependencies.First();
dependency.Name.Should().Be(DependencyName);
dependency.VersionRange.Should().Be(_versionRange);
dependency.Target.Should().Be(LibraryType.Unspecified);
dependency.LibraryRange.VersionRange.Should().Be(_versionRange);
dependency.LibraryRange.TypeConstraint.Should().Be(LibraryDependencyTarget.All);
dependency.Type.Should().Be(LibraryDependencyType.Default);
dependency.SourceFilePath.Should().Be(ProjectFilePath);
dependency.SourceLine.Should().Be(3);
@ -801,7 +798,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests
var project = GetProject(json);
var dependency = project.Dependencies.First();
dependency.Target.Should().Be(LibraryType.Unspecified);
dependency.LibraryRange.TypeConstraint.Should().Be(LibraryDependencyTarget.None);
}
[Fact]
@ -817,7 +814,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests
var project = GetProject(json);
var dependency = project.Dependencies.First();
dependency.Target.Should().Be(LibraryType.Project);
dependency.LibraryRange.TypeConstraint.Should().Be(LibraryDependencyTarget.Project);
}
[Fact]
@ -889,7 +886,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests
var tool = project.Tools.First();
tool.VersionRange.Should().BeNull();
tool.LibraryRange.VersionRange.Should().BeNull();
}
[Fact]
@ -904,8 +901,8 @@ namespace Microsoft.DotNet.ProjectModel.Tests
var tool = project.Tools.First();
tool.Name.Should().Be(ToolName);
tool.VersionRange.Should().Be(_versionRange);
tool.Target.Should().Be(LibraryType.Unspecified);
tool.LibraryRange.VersionRange.Should().Be(_versionRange);
tool.LibraryRange.TypeConstraint.Should().Be(LibraryDependencyTarget.All);
tool.Type.Should().Be(LibraryDependencyType.Default);
tool.SourceFilePath.Should().Be(ProjectFilePath);
tool.SourceLine.Should().Be(3);
@ -926,8 +923,8 @@ namespace Microsoft.DotNet.ProjectModel.Tests
var tool = project.Tools.First();
tool.Name.Should().Be(ToolName);
tool.VersionRange.Should().Be(_versionRange);
tool.Target.Should().Be(LibraryType.Unspecified);
tool.LibraryRange.VersionRange.Should().Be(_versionRange);
tool.LibraryRange.TypeConstraint.Should().Be(LibraryDependencyTarget.All);
tool.Type.Should().Be(LibraryDependencyType.Default);
tool.SourceFilePath.Should().Be(ProjectFilePath);
tool.SourceLine.Should().Be(3);
@ -963,7 +960,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests
var project = GetProject(json);
var tool = project.Tools.First();
tool.Target.Should().Be(LibraryType.Unspecified);
tool.LibraryRange.TypeConstraint.Should().Be(LibraryDependencyTarget.None);
}
[Fact]
@ -979,7 +976,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests
var project = GetProject(json);
var tool = project.Tools.First();
tool.Target.Should().Be(LibraryType.Project);
tool.LibraryRange.TypeConstraint.Should().Be(LibraryDependencyTarget.Project);
}
public Project GetProject(JObject json, ProjectReaderSettings settings = null)

View file

@ -1,7 +1,6 @@
// 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;
@ -9,6 +8,8 @@ using Microsoft.DotNet.ProjectModel.Compilation;
using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.DotNet.ProjectModel.Resolution;
using Microsoft.DotNet.Tools.Test.Utilities;
using NuGet.LibraryModel;
using NuGet.ProjectModel;
using FluentAssertions;
using Xunit;
@ -21,15 +22,15 @@ namespace Microsoft.DotNet.ProjectModel.Tests
private PackageDescription CreateDescription(
LockFileTargetLibrary target = null,
LockFilePackageLibrary package = null,
LockFileLibrary package = null,
string hashPath = null)
{
return new PackageDescription(
PackagePath,
hashPath ?? HashPath,
package ?? new LockFilePackageLibrary(),
package ?? new LockFileLibrary(),
target ?? new LockFileTargetLibrary(),
new List<LibraryRange>(), compatible: true, resolved: true);
new List<ProjectLibraryDependency>(), compatible: true, resolved: true);
}
[Fact]
@ -40,7 +41,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests
{
NativeLibraries = new List<LockFileItem>()
{
{ new LockFileItem() { Path = "lib/Native.so" } }
{ new LockFileItem("lib/Native.so") }
}
});
@ -62,7 +63,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests
{
CompileTimeAssemblies = new List<LockFileItem>()
{
{ new LockFileItem() { Path = "ref/Native.dll" } }
{ new LockFileItem("ref/Native.dll") }
}
});
@ -84,7 +85,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests
{
RuntimeAssemblies = new List<LockFileItem>()
{
{ new LockFileItem() { Path = "ref/Native.dll" } }
{ new LockFileItem("ref/Native.dll") }
}
});
@ -135,13 +136,17 @@ namespace Microsoft.DotNet.ProjectModel.Tests
[Fact]
public void ExportsPackageResourceAssemblies()
{
var enUsResource = new LockFileItem("resources/en-US/Res.dll");
enUsResource.Properties.Add("locale", "en-US");
var ruRuResource = new LockFileItem("resources/ru-RU/Res.dll");
ruRuResource.Properties.Add("locale", "ru-RU");
var description = CreateDescription(
new LockFileTargetLibrary()
{
ResourceAssemblies = new List<LockFileItem>()
{
new LockFileItem("resources/en-US/Res.dll", new Dictionary<string, string>() { { "locale", "en-US"} }),
new LockFileItem("resources/ru-RU/Res.dll", new Dictionary<string, string>() { { "locale", "ru-RU" } }),
{
enUsResource,
ruRuResource
}
});
@ -163,14 +168,9 @@ namespace Microsoft.DotNet.ProjectModel.Tests
[Fact]
public void ExportsSources()
{
var description = CreateDescription(
package: new LockFilePackageLibrary()
{
Files = new List<string>()
{
Path.Combine("shared", "file.cs")
}
});
var lockFileLibrary = new LockFileLibrary();
lockFileLibrary.Files.Add(Path.Combine("shared", "file.cs"));
var description = CreateDescription(package: lockFileLibrary);
var result = ExportSingle(description);
result.SourceReferences.Should().HaveCount(1);
@ -190,10 +190,9 @@ namespace Microsoft.DotNet.ProjectModel.Tests
{
ContentFiles = new List<LockFileContentFile>()
{
new LockFileContentFile()
new LockFileContentFile(Path.Combine("content", "file.txt"))
{
CopyToOutput = true,
Path = Path.Combine("content", "file.txt"),
OutputPath = Path.Combine("Out","Path.txt"),
PPOutputPath = "something"
}
@ -218,10 +217,9 @@ namespace Microsoft.DotNet.ProjectModel.Tests
{
ContentFiles = new List<LockFileContentFile>()
{
new LockFileContentFile()
new LockFileContentFile(Path.Combine("content", "file.txt"))
{
BuildAction = BuildAction.EmbeddedResource,
Path = Path.Combine("content", "file.txt"),
PPOutputPath = "something"
}
}
@ -244,10 +242,9 @@ namespace Microsoft.DotNet.ProjectModel.Tests
{
ContentFiles = new List<LockFileContentFile>()
{
new LockFileContentFile()
new LockFileContentFile(Path.Combine("content", "file.cs"))
{
BuildAction = BuildAction.Compile,
Path = Path.Combine("content", "file.cs"),
PPOutputPath = "something"
}
}
@ -272,24 +269,21 @@ namespace Microsoft.DotNet.ProjectModel.Tests
{
ContentFiles = new List<LockFileContentFile>()
{
new LockFileContentFile()
new LockFileContentFile(Path.Combine("content", "file.cs"))
{
BuildAction = BuildAction.Compile,
Path = Path.Combine("content", "file.cs"),
PPOutputPath = "something",
CodeLanguage = "cs"
},
new LockFileContentFile()
new LockFileContentFile(Path.Combine("content", "file.vb"))
{
BuildAction = BuildAction.Compile,
Path = Path.Combine("content", "file.vb"),
PPOutputPath = "something",
CodeLanguage = "vb"
},
new LockFileContentFile()
new LockFileContentFile(Path.Combine("content", "file.any"))
{
BuildAction = BuildAction.Compile,
Path = Path.Combine("content", "file.any"),
PPOutputPath = "something",
}
}
@ -312,17 +306,15 @@ namespace Microsoft.DotNet.ProjectModel.Tests
{
ContentFiles = new List<LockFileContentFile>()
{
new LockFileContentFile()
new LockFileContentFile(Path.Combine("content", "file.vb"))
{
BuildAction = BuildAction.Compile,
Path = Path.Combine("content", "file.vb"),
PPOutputPath = "something",
CodeLanguage = "vb"
},
new LockFileContentFile()
new LockFileContentFile(Path.Combine("content", "file.any"))
{
BuildAction = BuildAction.Compile,
Path = Path.Combine("content", "file.any"),
PPOutputPath = "something",
}
}
@ -351,7 +343,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests
var rootProjectDescription = new ProjectDescription(
new LibraryRange(),
rootProject,
new LibraryRange[] { },
new ProjectLibraryDependency[] { },
new TargetFrameworkInformation(),
true);

View file

@ -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.IO;
using System.Linq;
using FluentAssertions;
using Xunit;
using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.DotNet.Tools.Test.Utilities;
using NuGet.ProjectModel;
@ -16,83 +14,14 @@ namespace Microsoft.DotNet.ProjectModel.Tests
{
private static string ExportFilesRoot=> Path.Combine(RepoRoot, "TestAssets", "LockFiles", "ExportFiles");
[Fact]
public void TestExportFileIsParsed()
{
var lockFilePath = GetLockFilePath("valid");
var lockFile = LockFileReader.Read(lockFilePath, designTime: false);
var exportFile = lockFile.ExportFile;
exportFile.Should().NotBeNull();
exportFile.Exports.Count.Should().Be(3);
exportFile.Exports.Should().OnlyHaveUniqueItems();
// check export structure
foreach (var export in exportFile.Exports)
{
export.TargetFramework.Should().NotBeNull();
AssertTargetLibrary(export);
}
}
[Fact]
public void TestLockFileIsPatchedWithExportData()
{
var lockFilePath = GetLockFilePath("valid");
var lockFile = LockFileReader.Read(lockFilePath, designTime: false);
// check lock file structure is similar to export structure
foreach (var target in lockFile.Targets)
{
target.Libraries.Count.Should().Be(3);
foreach (var library in target.Libraries)
{
AssertTargetLibrary(library);
}
}
}
[Fact]
public void TestFragmentExistsButNoHolesInLockFile()
{
var lockFilePath = GetLockFilePath("valid_staleFragment");
var lockFile = LockFileReader.Read(lockFilePath, designTime: false);
var exportFile = lockFile.ExportFile;
exportFile.Should().BeNull();
lockFile.Targets.Count.Should().Be(1);
lockFile.Targets[0].Libraries.Count.Should().Be(0);
}
[Fact]
public void TestMissingExportFileThrows()
{
var lockFilePath = GetLockFilePath("invalid_nofragment");
Assert.Throws<FileFormatException>(() => LockFileReader.Read(lockFilePath, designTime: false));
}
[Fact]
public void TestMissingExportUnderDesignTime()
{
var lockFilePath = GetLockFilePath("invalid_nofragment");
// not throw under design time scenario
Assert.NotNull(LockFileReader.Read(lockFilePath, designTime: true));
}
[Fact]
public void TestMissingExportsThrow()
{
var lockFilePath = GetLockFilePath("invalid_missing-exports");
Assert.Throws<FileFormatException>(() => LockFileReader.Read(lockFilePath, designTime: false));
Assert.NotNull(new LockFileFormat().Read(lockFilePath));
}
[Fact]
@ -101,43 +30,35 @@ namespace Microsoft.DotNet.ProjectModel.Tests
var lockFilePath = GetLockFilePath("invalid_missing-exports");
// not throw under design time scenario
Assert.NotNull(LockFileReader.Read(lockFilePath, designTime: true));
Assert.NotNull(new LockFileFormat().Read(lockFilePath));
}
[Fact]
public void TestMissmatchingFileVersionsThrows()
{
var lockFilePath = GetLockFilePath("invalid_missmatching-versions");
Assert.Throws<FileFormatException>(() => LockFileReader.Read(lockFilePath, designTime: false));
}
[Fact]
public void TestMissmatchingFileVersionsUnderDesignTime()
{
var lockFilePath = GetLockFilePath("invalid_missmatching-versions");
Assert.NotNull(LockFileReader.Read(lockFilePath, designTime: true));
Assert.NotNull(new LockFileFormat().Read(lockFilePath));
}
[Fact]
public void TestPackageFoldersLoadCorrectly()
{
var lockFilePath = GetLockFilePath("valid");
var lockFile = LockFileReader.Read(lockFilePath, designTime: false);
var lockFile = new LockFileFormat().Read(lockFilePath);
Assert.Equal(2, lockFile.PackageFolders.Count);
Assert.Equal("/foo/packages", lockFile.PackageFolders[0].Path);
Assert.Equal("/foo/packages2", lockFile.PackageFolders[1].Path);
}
private static int LibraryNumberFromName(Microsoft.DotNet.ProjectModel.Graph.LockFileTargetLibrary library)
private static int LibraryNumberFromName(LockFileTargetLibrary library)
{
var libraryName = library.Name;
return (int)char.GetNumericValue(libraryName[libraryName.Length - 1]);
}
private static void AssertTargetLibrary(Microsoft.DotNet.ProjectModel.Graph.LockFileTargetLibrary library)
private static void AssertTargetLibrary(LockFileTargetLibrary library)
{
var libraryNumber = LibraryNumberFromName(library);

View file

@ -1,120 +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.IO;
using System.Linq;
using System.Text;
using FluentAssertions;
using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.DotNet.Tools.Test.Utilities;
using Xunit;
namespace Microsoft.DotNet.ProjectModel.Tests
{
public class LockFileReaderTests : TestBase
{
[Fact]
public void ReadsAllLibraryPropertiesWhenPathIsPresent()
{
// Arrange
var lockFileJson = @"
{
""libraries"": {
""PackageA/1.0.1-Alpha"": {
""sha512"": ""FAKE-HASH"",
""type"": ""package"",
""serviceable"": true,
""files"": [
""a.txt"",
""foo/b.txt""
],
""path"": ""PackageA/1.0.1-beta-PATH""
},
""ProjectA/1.0.2-Beta"": {
""type"": ""project"",
""path"": ""ProjectA-PATH"",
""msbuildProject"": ""some-msbuild""
}
}
}";
var lockFileStream = new MemoryStream(Encoding.UTF8.GetBytes(lockFileJson));
var lockFileReader = new LockFileReader();
// Act
var lockFile = lockFileReader.ReadLockFile(
lockFilePath: null,
stream: lockFileStream,
designTime: true);
// Assert
lockFile.PackageLibraries.Should().HaveCount(1);
var package = lockFile.PackageLibraries.First();
package.Name.Should().Be("PackageA");
package.Version.ToString().Should().Be("1.0.1-Alpha");
package.Sha512.Should().Be("FAKE-HASH");
package.IsServiceable.Should().BeTrue();
package.Files.Should().HaveCount(2);
package.Files[0].Should().Be("a.txt");
package.Files[1].Should().Be(Path.Combine("foo", "b.txt"));
package.Path.Should().Be("PackageA/1.0.1-beta-PATH");
lockFile.ProjectLibraries.Should().HaveCount(1);
var project = lockFile.ProjectLibraries.First();
project.Name.Should().Be("ProjectA");
project.Version.ToString().Should().Be("1.0.2-Beta");
project.Path.Should().Be("ProjectA-PATH");
}
[Fact]
public void ReadsAllLibraryPropertiesWhenPathIsNotPresent()
{
// Arrange
var lockFileJson = @"
{
""libraries"": {
""PackageA/1.0.1-Alpha"": {
""sha512"": ""FAKE-HASH"",
""type"": ""package"",
""serviceable"": true,
""files"": [
""a.txt"",
""foo/b.txt""
]
},
""ProjectA/1.0.2-Beta"": {
""type"": ""project"",
""msbuildProject"": ""some-msbuild""
}
}
}";
var lockFileStream = new MemoryStream(Encoding.UTF8.GetBytes(lockFileJson));
var lockFileReader = new LockFileReader();
// Act
var lockFile = lockFileReader.ReadLockFile(
lockFilePath: null,
stream: lockFileStream,
designTime: true);
// Assert
lockFile.PackageLibraries.Should().HaveCount(1);
var package = lockFile.PackageLibraries.First();
package.Name.Should().Be("PackageA");
package.Version.ToString().Should().Be("1.0.1-Alpha");
package.Sha512.Should().Be("FAKE-HASH");
package.IsServiceable.Should().BeTrue();
package.Files.Should().HaveCount(2);
package.Files[0].Should().Be("a.txt");
package.Files[1].Should().Be(Path.Combine("foo", "b.txt"));
package.Path.Should().BeNull();
lockFile.ProjectLibraries.Should().HaveCount(1);
var project = lockFile.ProjectLibraries.First();
project.Name.Should().Be("ProjectA");
project.Version.ToString().Should().Be("1.0.2-Beta");
project.Path.Should().BeNull();
}
}
}

View file

@ -2,12 +2,13 @@ using System;
using System.IO;
using System.Linq;
using FluentAssertions;
using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.DotNet.ProjectModel.Resolution;
using Microsoft.DotNet.TestFramework;
using Microsoft.DotNet.Tools.Test.Utilities;
using NuGet.Configuration;
using NuGet.Frameworks;
using NuGet.LibraryModel;
using NuGet.ProjectModel;
using NuGet.Versioning;
using Xunit;
@ -22,7 +23,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests
var provider = new PackageDependencyProvider(
NuGetPathContext.Create("/foo/packages"),
new FrameworkReferenceResolver("/foo/references"));
var package = new LockFilePackageLibrary();
var package = new LockFileLibrary();
package.Name = "Something";
package.Version = NuGetVersion.Parse("1.0.0");
package.Files.Add("lib/dotnet/_._");
@ -51,7 +52,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests
var provider = new PackageDependencyProvider(
NuGetPathContext.Create("/foo/packages"),
new FrameworkReferenceResolver("/foo/references"));
var package = new LockFilePackageLibrary();
var package = new LockFileLibrary();
package.Name = "Something";
package.Version = NuGetVersion.Parse("1.0.0-Beta");
package.Files.Add("lib/dotnet/_._");
@ -80,7 +81,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests
var provider = new PackageDependencyProvider(
NuGetPathContext.Create("/foo/packages"),
new FrameworkReferenceResolver("/foo/references"));
var package = new LockFilePackageLibrary();
var package = new LockFileLibrary();
package.Name = "Something";
package.Version = NuGetVersion.Parse("1.0.0");
package.Files.Add("lib/dotnet/_._");
@ -113,7 +114,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests
var provider = new PackageDependencyProvider(
NuGetPathContext.Create("/foo/packages"),
new FrameworkReferenceResolver("/foo/references"));
var package = new LockFilePackageLibrary();
var package = new LockFileLibrary();
package.Name = "Something";
package.Version = NuGetVersion.Parse("1.0.0");
package.Files.Add("lib/net46/_._");
@ -143,7 +144,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests
var provider = new PackageDependencyProvider(
NuGetPathContext.Create("/foo/packages"),
new FrameworkReferenceResolver("/foo/references"));
var package = new LockFilePackageLibrary();
var package = new LockFileLibrary();
package.Name = "Something";
package.Version = NuGetVersion.Parse("1.0.0");

View file

@ -4,9 +4,9 @@ using System.IO;
using System.Linq;
using System.Reflection;
using FluentAssertions;
using Microsoft.DotNet.ProjectModel.Graph;
using Microsoft.DotNet.Tools.Test.Utilities;
using NuGet.Frameworks;
using NuGet.ProjectModel;
using Xunit;
namespace Microsoft.DotNet.ProjectModel.Tests
@ -36,7 +36,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests
// Initialize a test instance that we're going to clone. Make sure all properties are initialized here.
var initialBuilder = new ProjectContextBuilder()
.WithProject(new Project())
.WithLockFile(new LockFile("abc"))
.WithLockFile(new LockFile())
.WithTargetFramework(FrameworkConstants.CommonFrameworks.NetStandard10)
.WithRuntimeIdentifiers(new[] { "win7-x64", "osx.10.10-x64" })
.WithRootDirectory("C:\\The\\Root")
@ -44,7 +44,7 @@ namespace Microsoft.DotNet.ProjectModel.Tests
.WithPackagesDirectory("D:\\My\\Awesome\\NuGet\\Packages")
.WithReferenceAssembliesPath("/these/are/the/reference/assemblies")
.WithProjectResolver(_ => new Project())
.WithLockFileResolver(_ => new LockFile("def"))
.WithLockFileResolver(_ => new LockFile())
.WithProjectReaderSettings(new ProjectReaderSettings());
// Clone the builder

View file

@ -21,7 +21,8 @@
"target": "project"
},
"xunit": "2.2.0-beta3-build3330",
"dotnet-test-xunit": "1.0.0-rc2-350904-49"
"dotnet-test-xunit": "1.0.0-rc2-350904-49",
"NuGet.ProjectModel": "3.6.0-beta.1.msbuild.15"
},
"frameworks": {
"netcoreapp1.0": {