Update ProjectModel server
1. Rebase on new LibraryExporter 2. Update dependency name to "fx/<name>" for reference assembly 3. Update framework friendly name 4. Fix dependency message regression 5. Update tests
This commit is contained in:
parent
03885e876f
commit
ce3e719a06
9 changed files with 92 additions and 40 deletions
|
@ -0,0 +1,21 @@
|
|||
// 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}";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -14,7 +14,7 @@ namespace Microsoft.DotNet.ProjectModel.Server.Models
|
|||
{
|
||||
ShortName = framework.GetShortFolderName(),
|
||||
FrameworkName = framework.DotNetFrameworkName,
|
||||
FriendlyName = framework.Framework,
|
||||
FriendlyName = FrameworkReferenceResolver.Default.GetFriendlyFrameworkName(framework),
|
||||
RedistListPath = FrameworkReferenceResolver.Default.GetFrameworkRedistListPath(framework)
|
||||
};
|
||||
}
|
||||
|
|
|
@ -31,24 +31,29 @@ namespace Microsoft.DotNet.ProjectModel.Server
|
|||
|
||||
var diagnosticsLookup = allDependencyDiagnostics.ToLookup(d => d.Source);
|
||||
|
||||
var allExports = context.CreateExporter(configuration)
|
||||
.GetAllExports()
|
||||
.ToDictionary(export => export.Library.GetUniqueName());
|
||||
var allSourceFiles = new List<string>(context.ProjectFile.Files.SourceFiles);
|
||||
var allFileReferences = new List<string>();
|
||||
var allProjectReferences = new List<ProjectReferenceDescription>();
|
||||
var allDependencies = new Dictionary<string, DependencyDescription>();
|
||||
|
||||
foreach (var export in context.CreateExporter(configuration).GetDependencies())
|
||||
// All exports are returned. When the same library name have a ReferenceAssembly type export and a Package type export
|
||||
// both will be listed as dependencies. Prefix "fx/" will be added to ReferenceAssembly type dependency.
|
||||
foreach (var pair in allExports)
|
||||
{
|
||||
var export = pair.Value;
|
||||
|
||||
allSourceFiles.AddRange(export.SourceReferences);
|
||||
allFileReferences.AddRange(export.CompilationAssemblies.Select(asset => asset.ResolvedPath));
|
||||
|
||||
var library = export.Library;
|
||||
var diagnostics = diagnosticsLookup[library].ToList();
|
||||
var description = DependencyDescription.Create(library, diagnostics);
|
||||
var diagnostics = diagnosticsLookup[export.Library].ToList();
|
||||
var description = DependencyDescription.Create(export.Library, diagnostics, allExports);
|
||||
allDependencies[description.Name] = description;
|
||||
|
||||
var projectDescription = library as ProjectDescription;
|
||||
|
||||
if (projectDescription != null)
|
||||
var projectDescription = export.Library as ProjectDescription;
|
||||
if (projectDescription != null && projectDescription.Identity.Name != context.ProjectFile.Name)
|
||||
{
|
||||
allProjectReferences.Add(ProjectReferenceDescription.Create(projectDescription));
|
||||
}
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.DotNet.ProjectModel.Graph;
|
||||
using Microsoft.DotNet.ProjectModel.Compilation;
|
||||
using Microsoft.DotNet.ProjectModel.Server.Helpers;
|
||||
|
||||
namespace Microsoft.DotNet.ProjectModel.Server.Models
|
||||
{
|
||||
|
@ -51,20 +52,23 @@ namespace Microsoft.DotNet.ProjectModel.Server.Models
|
|||
return base.GetHashCode();
|
||||
}
|
||||
|
||||
public static DependencyDescription Create(LibraryDescription library, IEnumerable<DiagnosticMessage> diagnostics)
|
||||
public static DependencyDescription Create(LibraryDescription library,
|
||||
List<DiagnosticMessage> diagnostics,
|
||||
Dictionary<string, LibraryExport> allExports)
|
||||
{
|
||||
var name = library.GetUniqueName();
|
||||
return new DependencyDescription
|
||||
{
|
||||
Name = library.Identity.Name,
|
||||
DisplayName = GetLibraryDisplayName(library),
|
||||
Version = library.Identity.Version?.ToString(),
|
||||
Name = name,
|
||||
DisplayName = library.Identity.Name,
|
||||
Version = library.Identity.Version?.ToNormalizedString(),
|
||||
Type = library.Identity.Type.Value,
|
||||
Resolved = library.Resolved,
|
||||
Path = library.Path,
|
||||
Dependencies = library.Dependencies.Select(dependency => new DependencyItem
|
||||
{
|
||||
Name = dependency.Name,
|
||||
Version = dependency.VersionRange?.ToString() // TODO: review
|
||||
Name = dependency.GetUniqueName(),
|
||||
Version = allExports[dependency.GetUniqueName()].Library.Identity.Version?.ToNormalizedString()
|
||||
}),
|
||||
Errors = diagnostics.Where(d => d.Severity == DiagnosticMessageSeverity.Error)
|
||||
.Select(d => new DiagnosticMessageView(d)),
|
||||
|
@ -72,16 +76,5 @@ namespace Microsoft.DotNet.ProjectModel.Server.Models
|
|||
.Select(d => new DiagnosticMessageView(d))
|
||||
};
|
||||
}
|
||||
|
||||
private static string GetLibraryDisplayName(LibraryDescription library)
|
||||
{
|
||||
var name = library.Identity.Name;
|
||||
if (library.Identity.Type == LibraryType.ReferenceAssembly && name.StartsWith("fx/"))
|
||||
{
|
||||
name = name.Substring(3);
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
// 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.Diagnostics;
|
||||
using System.Linq;
|
||||
|
||||
namespace Microsoft.DotNet.ProjectModel.Compilation
|
||||
{
|
||||
|
@ -45,12 +43,6 @@ namespace Microsoft.DotNet.ProjectModel.Compilation
|
|||
NativeLibraries = nativeLibraries;
|
||||
}
|
||||
|
||||
private string DebuggerDisplay
|
||||
{
|
||||
get
|
||||
{
|
||||
return Library.Identity.ToString();
|
||||
}
|
||||
}
|
||||
private string DebuggerDisplay => Library.Identity.ToString();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
// 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
|
||||
{
|
||||
internal static class Constants
|
||||
{
|
||||
public static readonly string DefaultOutputDirectory = "bin";
|
||||
public static readonly string DefaultConfiguration = "Debug";
|
||||
|
||||
public static readonly Version Version50 = new Version(5, 0);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -142,6 +142,38 @@ namespace Microsoft.DotNet.ProjectModel.Resolution
|
|||
|
||||
return information.RedistListPath;
|
||||
}
|
||||
|
||||
public string GetFriendlyFrameworkName(NuGetFramework targetFramework)
|
||||
{
|
||||
var frameworkName = new FrameworkName(targetFramework.DotNetFrameworkName);
|
||||
|
||||
// We don't have a friendly name for this anywhere on the machine so hard code it
|
||||
if (string.Equals(frameworkName.Identifier, VersionUtility.DnxCoreFrameworkIdentifier, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return "DNX Core 5.0";
|
||||
}
|
||||
else if (string.Equals(frameworkName.Identifier, VersionUtility.DnxFrameworkIdentifier, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return "DNX " + targetFramework.Version.ToString();
|
||||
}
|
||||
else if (string.Equals(frameworkName.Identifier, VersionUtility.NetPlatformFrameworkIdentifier, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var version = targetFramework.Version > Constants.Version50 ?
|
||||
(" " + targetFramework.Version.ToString()) :
|
||||
string.Empty;
|
||||
return ".NET Platform" + version;
|
||||
}
|
||||
|
||||
var information = _cache.GetOrAdd(targetFramework, GetFrameworkInformation);
|
||||
|
||||
if (information == null)
|
||||
{
|
||||
return SynthesizeFrameworkFriendlyName(targetFramework);
|
||||
}
|
||||
|
||||
return information.Name;
|
||||
}
|
||||
|
||||
private FrameworkInformation GetFrameworkInformation(NuGetFramework targetFramework)
|
||||
{
|
||||
string referenceAssembliesPath = ReferenceAssembliesPath;
|
||||
|
|
|
@ -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.Runtime.Loader;
|
||||
using System.Text;
|
||||
using NuGet.Versioning;
|
||||
|
@ -10,10 +9,16 @@ namespace Microsoft.DotNet.ProjectModel.Utilities
|
|||
{
|
||||
public static class VersionUtility
|
||||
{
|
||||
public static readonly string DnxCoreFrameworkIdentifier = "DNXCore";
|
||||
public static readonly string DnxFrameworkIdentifier = "DNX";
|
||||
public static readonly string NetPlatformFrameworkIdentifier = ".NETPlatform";
|
||||
public static readonly string NetFrameworkIdentifier = ".NETFramework";
|
||||
|
||||
internal static NuGetVersion GetAssemblyVersion(string path)
|
||||
{
|
||||
return new NuGetVersion(AssemblyLoadContext.GetAssemblyName(path).Version);
|
||||
}
|
||||
|
||||
public static string RenderVersion(VersionRange range)
|
||||
{
|
||||
if (range == null)
|
||||
|
|
|
@ -68,7 +68,7 @@ namespace Microsoft.DotNet.ProjectModel.Server.Tests
|
|||
}
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[Fact]
|
||||
public void DthStartup_ProtocolNegotiation_ZeroIsNoAllowed()
|
||||
{
|
||||
using (var server = new DthTestServer(_testHelper.LoggerFactory))
|
||||
|
|
Loading…
Reference in a new issue