-
Notifications
You must be signed in to change notification settings - Fork 693
/
PackageSpecExtensions.cs
47 lines (40 loc) · 1.86 KB
/
PackageSpecExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Linq;
using NuGet.Frameworks;
namespace NuGet.ProjectModel
{
public static class PackageSpecExtensions
{
/// <summary>
/// Get the nearest framework available in the project.
/// </summary>
public static TargetFrameworkInformation GetTargetFramework(this PackageSpec project, NuGetFramework targetFramework)
{
var frameworkInfo = project.TargetFrameworks.FirstOrDefault(f => NuGetFramework.Comparer.Equals(targetFramework, f.FrameworkName));
if (frameworkInfo == null)
{
frameworkInfo = NuGetFrameworkUtility.GetNearest(project.TargetFrameworks,
targetFramework,
item => item.FrameworkName);
}
return frameworkInfo ?? new TargetFrameworkInformation();
}
/// <summary>
/// Get restore metadata framework. This is based on the project's target frameworks, then an
/// exact match is found under restore metadata.
/// </summary>
public static ProjectRestoreMetadataFrameworkInfo GetRestoreMetadataFramework(this PackageSpec project, NuGetFramework targetFramework)
{
ProjectRestoreMetadataFrameworkInfo frameworkInfo = null;
var projectFrameworkInfo = GetTargetFramework(project, targetFramework);
if (projectFrameworkInfo.FrameworkName != null)
{
frameworkInfo = project.RestoreMetadata?.TargetFrameworks
.FirstOrDefault(f => f.FrameworkName.Equals(projectFrameworkInfo.FrameworkName));
}
return frameworkInfo ?? new ProjectRestoreMetadataFrameworkInfo();
}
}
}