Fixing issues small issues found during build and tests.
This commit is contained in:
parent
6527cbc592
commit
f0a50c92ac
18 changed files with 122 additions and 293 deletions
|
@ -14,7 +14,7 @@
|
|||
"Microsoft.DotNet.Files": {
|
||||
"target": "project"
|
||||
},
|
||||
"NuGet.ProjectModel": "3.6.0-beta.1.msbuild.9"
|
||||
"NuGet.ProjectModel": "3.6.0-beta.1.msbuild.15"
|
||||
},
|
||||
"frameworks": {
|
||||
"net451": {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -29,6 +29,7 @@ namespace Microsoft.DotNet.ProjectModel.Graph
|
|||
// The lock file should contain dependencies for each framework plus dependencies shared by all frameworks
|
||||
if (lockFile.ProjectFileDependencyGroups.Count != actualTargetFrameworks.Count() + 1)
|
||||
{
|
||||
Console.WriteLine($"Different count; {lockFile.ProjectFileDependencyGroups.Count} != {actualTargetFrameworks.Count() + 1}");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -38,7 +39,7 @@ namespace Microsoft.DotNet.ProjectModel.Graph
|
|||
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.LibraryRange.ToLockFileDependencyGroupString())
|
||||
|
@ -47,7 +48,7 @@ namespace Microsoft.DotNet.ProjectModel.Graph
|
|||
else
|
||||
{
|
||||
var framework = actualTargetFrameworks
|
||||
.FirstOrDefault(f => Equals(f.FrameworkName, group.FrameworkName));
|
||||
.FirstOrDefault(f => Equals(f.FrameworkName.DotNetFrameworkName, group.FrameworkName));
|
||||
if (framework == null)
|
||||
{
|
||||
return false;
|
||||
|
@ -60,6 +61,7 @@ namespace Microsoft.DotNet.ProjectModel.Graph
|
|||
|
||||
if (!actualDependencies.SequenceEqual(expectedDependencies))
|
||||
{
|
||||
Console.WriteLine($"ActualDependencies don't match");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
// Copyright (c) .NET Foundation and contributors. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.DotNet.PlatformAbstractions;
|
||||
using NuGet.Frameworks;
|
||||
using NuGet.LibraryModel;
|
||||
|
||||
|
@ -33,7 +35,8 @@ namespace Microsoft.DotNet.ProjectModel
|
|||
|
||||
public LibraryIdentity Identity { get; }
|
||||
public string Hash { get; }
|
||||
public HashSet<ProjectLibraryDependency> RequestedRanges { get; } = new HashSet<ProjectLibraryDependency>();
|
||||
public HashSet<ProjectLibraryDependency> RequestedRanges { get; } =
|
||||
new HashSet<ProjectLibraryDependency>(new LibraryRangeEqualityComparer());
|
||||
public List<LibraryDescription> Parents { get; } = new List<LibraryDescription>();
|
||||
public string Path { get; }
|
||||
public IEnumerable<ProjectLibraryDependency> Dependencies { get; }
|
||||
|
@ -46,5 +49,29 @@ 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<ProjectLibraryDependency>
|
||||
{
|
||||
public bool Equals(ProjectLibraryDependency x, ProjectLibraryDependency y)
|
||||
{
|
||||
return x.Equals(y) &&
|
||||
x.SourceColumn == y.SourceColumn &&
|
||||
x.SourceLine == y.SourceLine &&
|
||||
string.Equals(x.SourceFilePath, y.SourceFilePath, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -278,7 +278,7 @@ namespace Microsoft.DotNet.ProjectModel
|
|||
|
||||
var dependencyValue = dependency.Value;
|
||||
var dependencyTypeValue = LibraryDependencyType.Default;
|
||||
var target = isGacOrFrameworkReference ? LibraryDependencyTarget.Reference: LibraryDependencyTarget.None;
|
||||
var target = isGacOrFrameworkReference ? LibraryDependencyTarget.Reference : LibraryDependencyTarget.All;
|
||||
string dependencyVersionAsString = null;
|
||||
|
||||
if (dependencyValue.Type == JTokenType.Object)
|
||||
|
@ -334,7 +334,10 @@ namespace Microsoft.DotNet.ProjectModel
|
|||
dependency.Key,
|
||||
dependencyVersionRange,
|
||||
target),
|
||||
Type = dependencyTypeValue
|
||||
Type = dependencyTypeValue,
|
||||
SourceFilePath = projectPath,
|
||||
SourceLine = lineInfo.LineNumber,
|
||||
SourceColumn = lineInfo.LinePosition
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ namespace Microsoft.DotNet.ProjectModel.Resolution
|
|||
if (!dependencies.Any(dep => string.Equals(dep.Name, dependencyName, StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
dependencies.Add(new ProjectLibraryDependency {
|
||||
LibraryRange = new LibraryRange(dependencyName, LibraryDependencyTarget.All)
|
||||
LibraryRange = new LibraryRange(dependencyName, LibraryDependencyTarget.Reference)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
@ -318,7 +322,8 @@ namespace Microsoft.DotNet.Tools.Compiler
|
|||
|
||||
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()}");
|
||||
}
|
||||
|
|
|
@ -54,10 +54,10 @@ namespace Microsoft.DotNet.ProjectModel.Server.Helpers
|
|||
return new DiagnosticMessage(
|
||||
ErrorCodes.NU1010,
|
||||
$"The type of dependency {library.Identity.Name} was changed.",
|
||||
string.Empty,
|
||||
libraryRange.SourceFilePath,
|
||||
DiagnosticMessageSeverity.Error,
|
||||
0,
|
||||
0,
|
||||
libraryRange.SourceLine,
|
||||
libraryRange.SourceColumn,
|
||||
library);
|
||||
}
|
||||
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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"
|
||||
},
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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");
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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": {
|
||||
|
|
Loading…
Reference in a new issue