-
Notifications
You must be signed in to change notification settings - Fork 695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add restore support for C++/CLI .NET Core projects #4076
Changes from all commits
b092f4c
cccd323
ca734cc
cafa4e3
4858ff5
c0f7f15
63aba61
9d1dd87
dcfc4b1
bf21e3e
f59de62
6b3eb77
89d6b55
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
NuGet.Commands.SignArgs.PackagePaths.get -> System.Collections.Generic.IReadOnlyList<string> | ||
NuGet.Commands.SignArgs.PackagePaths.set -> void | ||
static NuGet.Commands.MSBuildProjectFrameworkUtility.GetProjectFramework(string projectFilePath, string targetFrameworkMoniker, string targetPlatformMoniker, string targetPlatformMinVersion, string clrSupport) -> NuGet.Frameworks.NuGetFramework | ||
zivkan marked this conversation as resolved.
Show resolved
Hide resolved
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
NuGet.Commands.SignArgs.PackagePaths.get -> System.Collections.Generic.IReadOnlyList<string> | ||
NuGet.Commands.SignArgs.PackagePaths.set -> void | ||
static NuGet.Commands.MSBuildProjectFrameworkUtility.GetProjectFramework(string projectFilePath, string targetFrameworkMoniker, string targetPlatformMoniker, string targetPlatformMinVersion, string clrSupport) -> NuGet.Frameworks.NuGetFramework |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
NuGet.Commands.SignArgs.PackagePaths.get -> System.Collections.Generic.IReadOnlyList<string> | ||
NuGet.Commands.SignArgs.PackagePaths.set -> void | ||
static NuGet.Commands.MSBuildProjectFrameworkUtility.GetProjectFramework(string projectFilePath, string targetFrameworkMoniker, string targetPlatformMoniker, string targetPlatformMinVersion, string clrSupport) -> NuGet.Frameworks.NuGetFramework |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -465,6 +465,11 @@ private IEnumerable<LibraryDependency> GetDependencies( | |
targetFramework, | ||
item => item.TargetFramework); | ||
|
||
if (dependencyGroup == null && DeconstructFallbackFrameworks(targetFramework) is DualCompatibilityFramework dualCompatibilityFramework) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This handles the dependencies selection with dual compat framework. |
||
{ | ||
dependencyGroup = NuGetFrameworkUtility.GetNearest(packageInfo.DependencyGroups, dualCompatibilityFramework.SecondaryFramework, item => item.TargetFramework); | ||
} | ||
|
||
if (dependencyGroup != null) | ||
{ | ||
return dependencyGroup.Packages.Select(PackagingUtility.GetLibraryDependencyFromNuspec).ToArray(); | ||
|
@@ -473,6 +478,21 @@ private IEnumerable<LibraryDependency> GetDependencies( | |
return Enumerable.Empty<LibraryDependency>(); | ||
} | ||
|
||
private static NuGetFramework DeconstructFallbackFrameworks(NuGetFramework nuGetFramework) | ||
{ | ||
if (nuGetFramework is AssetTargetFallbackFramework assetTargetFallbackFramework) | ||
{ | ||
return assetTargetFallbackFramework.RootFramework; | ||
} | ||
|
||
if (nuGetFramework is FallbackFramework fallbackFramework) | ||
{ | ||
return fallbackFramework; | ||
} | ||
|
||
return nuGetFramework; | ||
} | ||
|
||
private async Task EnsureResource() | ||
{ | ||
if (_findPackagesByIdResource == null) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,7 +142,7 @@ internal static List<List<SelectionCriteria>> CreateOrderedCriteriaSets(RestoreT | |
// Create an ordered list of selection criteria. Each will be applied, if the result is empty | ||
// fallback frameworks from "imports" will be tried. | ||
// These are only used for framework/RID combinations where content model handles everything. | ||
// AssetTargetFallback frameworks will provide multiple criteria since all assets need to be | ||
// AssetTargetFallback and DualCompatbiility frameworks will provide multiple criteria since all assets need to be | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo, DualCompatbiility |
||
// evaluated before selecting the TFM to use. | ||
var orderedCriteriaSets = new List<List<SelectionCriteria>>(1); | ||
|
||
|
@@ -152,6 +152,11 @@ internal static List<List<SelectionCriteria>> CreateOrderedCriteriaSets(RestoreT | |
{ | ||
// Add the root project framework first. | ||
orderedCriteriaSets.Add(CreateCriteria(targetGraph, assetTargetFallback.RootFramework)); | ||
// Add the secondary framework if dual compatibility framework. | ||
if (assetTargetFallback.RootFramework is DualCompatibilityFramework dualCompatibilityFramework) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This ensures the package assets are selected with dual compatibility in mind. |
||
{ | ||
orderedCriteriaSets.Add(CreateCriteria(targetGraph, dualCompatibilityFramework.SecondaryFramework)); | ||
} | ||
|
||
// Add all fallbacks in order. | ||
orderedCriteriaSets.AddRange(assetTargetFallback.Fallback.Select(e => CreateCriteria(targetGraph, e))); | ||
|
@@ -160,6 +165,11 @@ internal static List<List<SelectionCriteria>> CreateOrderedCriteriaSets(RestoreT | |
{ | ||
// Add the current framework. | ||
orderedCriteriaSets.Add(CreateCriteria(targetGraph, framework)); | ||
|
||
if (framework is DualCompatibilityFramework dualCompatibilityFramework) | ||
{ | ||
orderedCriteriaSets.Add(CreateCriteria(targetGraph, dualCompatibilityFramework.SecondaryFramework)); | ||
} | ||
} | ||
|
||
return orderedCriteriaSets; | ||
|
@@ -458,9 +468,17 @@ private static void AddDependencies(IEnumerable<LibraryDependency> dependencies, | |
{ | ||
if (dependencies == null) | ||
{ | ||
// AssetFallbackFramework does not apply to dependencies. | ||
// DualCompatibilityFramework & AssetFallbackFramework does not apply to dependencies. | ||
// Convert it to a fallback framework if needed. | ||
var currentFramework = (framework as AssetTargetFallbackFramework)?.AsFallbackFramework() ?? framework; | ||
NuGetFramework currentFramework = framework; | ||
if (framework is AssetTargetFallbackFramework atf) | ||
{ | ||
currentFramework = atf.AsFallbackFramework(); | ||
} | ||
else if (framework is DualCompatibilityFramework mcf) | ||
{ | ||
currentFramework = mcf.AsFallbackFramework(); | ||
} | ||
|
||
var dependencySet = nuspec | ||
.GetDependencyGroups() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// 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 NuGet.Shared; | ||
|
||
namespace NuGet.Frameworks | ||
{ | ||
/// <summary> | ||
/// Represents a framework that behaves as 2 potentially independent frameworks. | ||
/// Ex. C++/CLI can support both .NET 5.0 and native. | ||
/// This type is immutable. | ||
/// </summary> | ||
public class DualCompatibilityFramework : NuGetFramework | ||
{ | ||
/// <summary> | ||
/// The root framework. Any compatibility checks should be performed against this framework first. | ||
/// </summary> | ||
public NuGetFramework RootFramework { get; } | ||
|
||
/// <summary> | ||
/// The secondary framework. If the root framework compatibility checks fail, then the compat checks should be performed against this framework next. | ||
/// </summary> | ||
public NuGetFramework SecondaryFramework { get; } | ||
|
||
private int? _hashCode; | ||
private FallbackFramework _fallbackFramework; | ||
|
||
/// <summary> | ||
/// Multiple compatbility | ||
/// </summary> | ||
/// <param name="framework">Root framework. Never <see langword="null"/>. </param> | ||
/// <param name="secondaryFramework">Secondary framework. Never <see langword="null"/>. </param> | ||
/// <exception cref="ArgumentNullException">if either <paramref name="framework"/> or <paramref name="secondaryFramework"/> are <see langword="null"/>.</exception> | ||
public DualCompatibilityFramework(NuGetFramework framework, NuGetFramework secondaryFramework) | ||
: base(ValidateFrameworkArgument(framework)) | ||
{ | ||
if (secondaryFramework == null) | ||
{ | ||
throw new ArgumentNullException(nameof(secondaryFramework)); | ||
} | ||
|
||
SecondaryFramework = secondaryFramework; | ||
nkolev92 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
RootFramework = framework; | ||
} | ||
|
||
/// <summary> | ||
/// Create a FallbackFramework from the current DualCompatibilityFramework. | ||
/// </summary> | ||
public FallbackFramework AsFallbackFramework() | ||
{ | ||
if (_fallbackFramework == null) | ||
{ | ||
_fallbackFramework = new FallbackFramework(RootFramework, new NuGetFramework[] { SecondaryFramework }); | ||
} | ||
|
||
return _fallbackFramework; | ||
} | ||
|
||
private static NuGetFramework ValidateFrameworkArgument(NuGetFramework framework) | ||
{ | ||
if (framework == null) | ||
{ | ||
throw new ArgumentNullException(nameof(framework)); | ||
} | ||
return framework; | ||
} | ||
|
||
public override bool Equals(object obj) | ||
{ | ||
return Equals(obj as DualCompatibilityFramework); | ||
} | ||
|
||
public bool Equals(DualCompatibilityFramework other) | ||
{ | ||
if (other == null) | ||
{ | ||
return false; | ||
} | ||
|
||
if (ReferenceEquals(this, other)) | ||
{ | ||
return true; | ||
} | ||
|
||
return Comparer.Equals(RootFramework, other.RootFramework) | ||
&& Comparer.Equals(SecondaryFramework, other.SecondaryFramework); | ||
} | ||
|
||
public override int GetHashCode() | ||
{ | ||
if (_hashCode == null) | ||
{ | ||
var combiner = new HashCodeCombiner(); | ||
// Ensure that this is different from AssetTargetFallback & FallbackFramework; | ||
combiner.AddStringIgnoreCase(nameof(DualCompatibilityFramework)); | ||
combiner.AddObject(Comparer.GetHashCode(RootFramework)); | ||
combiner.AddObject(Comparer.GetHashCode(SecondaryFramework)); | ||
_hashCode = combiner.CombinedHash; | ||
} | ||
|
||
return _hashCode.Value; | ||
} | ||
|
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is nomination code that handles the VS side.