-
Notifications
You must be signed in to change notification settings - Fork 701
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 support for AssetTargetFallback #1436
Changes from all commits
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,4 +1,4 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// 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; | ||
|
@@ -295,21 +295,26 @@ private async Task<PackageSpec> GetPackageSpecAsync(ISettings settings) | |
.GetPackageReferencesAsync(targetFramework, CancellationToken.None)) | ||
.ToList(); | ||
|
||
var packageTargetFallback = _vsProjectAdapter.PackageTargetFallback?.Split(new[] { ';' }) | ||
var splitChars = new[] { ';' }; | ||
|
||
var packageTargetFallback = _vsProjectAdapter.PackageTargetFallback?.Split(splitChars) | ||
.Select(NuGetFramework.Parse) | ||
.ToList(); | ||
.ToList() | ||
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. Although it wasn't covered there before, what happens in case of empty or invalid entries in the list? 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. NuGetFramework.Parse returns the Unsupported framework since it isn't unusual for future frameworks to come in. For fallback frameworks there is a check to verify that unsupported isn't passed and it will throw. |
||
?? new List<NuGetFramework>(); | ||
|
||
var assetTargetFallback = _vsProjectAdapter.AssetTargetFallback?.Split(splitChars) | ||
.Select(NuGetFramework.Parse) | ||
.ToList() | ||
?? new List<NuGetFramework>(); | ||
|
||
var projectTfi = new TargetFrameworkInformation | ||
{ | ||
FrameworkName = targetFramework, | ||
Dependencies = packageReferences, | ||
Imports = packageTargetFallback ?? new List<NuGetFramework>() | ||
}; | ||
|
||
if ((projectTfi.Imports?.Count ?? 0) > 0) | ||
{ | ||
projectTfi.FrameworkName = new FallbackFramework(projectTfi.FrameworkName, packageTargetFallback); | ||
} | ||
// Apply fallback settings | ||
AssetTargetFallbackUtility.ApplyFramework(projectTfi, packageTargetFallback, assetTargetFallback); | ||
|
||
// Build up runtime information. | ||
var runtimes = await _vsProjectAdapter.GetRuntimeIdentifiersAsync(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,7 @@ public sealed class VsSolutionRestoreService : IVsSolutionRestoreService, IVsSol | |
private const string RestorePackagesPath = nameof(RestorePackagesPath); | ||
private const string RestoreSources = nameof(RestoreSources); | ||
private const string RestoreFallbackFolders = nameof(RestoreFallbackFolders); | ||
private const string AssetTargetFallback = nameof(AssetTargetFallback); | ||
|
||
|
||
private static readonly Version Version20 = new Version(2, 0, 0, 0); | ||
|
@@ -268,7 +269,7 @@ private static PackageSpec ToPackageSpec(ProjectNames projectNames, IVsProjectRe | |
.ToList(), | ||
}, | ||
RuntimeGraph = GetRuntimeGraph(projectRestoreInfo), | ||
RestoreSettings = new ProjectRestoreSettings() { HideWarningsAndErrors = true } | ||
RestoreSettings = new ProjectRestoreSettings() { HideWarningsAndErrors = true } | ||
}; | ||
|
||
return packageSpec; | ||
|
@@ -313,7 +314,7 @@ private static string[] HandleClear(string[] input) | |
{ | ||
if (input.Any(e => StringComparer.OrdinalIgnoreCase.Equals(Clear, e))) | ||
{ | ||
return new string[] { Clear}; | ||
return new string[] { Clear }; | ||
} | ||
|
||
return input; | ||
|
@@ -372,21 +373,16 @@ private static TargetFrameworkInformation ToTargetFrameworkInformation( | |
FrameworkName = NuGetFramework.Parse(targetFrameworkInfo.TargetFrameworkMoniker) | ||
}; | ||
|
||
var ptf = GetPropertyValueOrNull(targetFrameworkInfo.Properties, PackageTargetFallback); | ||
if (!string.IsNullOrEmpty(ptf)) | ||
{ | ||
var fallbackList = MSBuildStringUtility.Split(ptf) | ||
.Select(NuGetFramework.Parse) | ||
.ToList(); | ||
var ptf = MSBuildStringUtility.Split(GetPropertyValueOrNull(targetFrameworkInfo.Properties, PackageTargetFallback)) | ||
.Select(NuGetFramework.Parse) | ||
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. fix indenting. |
||
.ToList(); | ||
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. The same question here about empty/invalid entries. |
||
|
||
tfi.Imports = fallbackList; | ||
var atf = MSBuildStringUtility.Split(GetPropertyValueOrNull(targetFrameworkInfo.Properties, AssetTargetFallback)) | ||
.Select(NuGetFramework.Parse) | ||
.ToList(); | ||
|
||
// Update the PackageSpec framework to include fallback frameworks | ||
if (tfi.Imports.Count != 0) | ||
{ | ||
tfi.FrameworkName = new FallbackFramework(tfi.FrameworkName, fallbackList); | ||
} | ||
} | ||
// Update TFI with fallback properties | ||
AssetTargetFallbackUtility.ApplyFramework(tfi, ptf, atf); | ||
|
||
if (targetFrameworkInfo.PackageReferences != null) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// 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.Common; | ||
|
||
namespace NuGet.Commands | ||
{ | ||
/// <summary> | ||
/// Holds an <see cref="IRestoreLogMessage"/> and returns the message for the exception. | ||
/// </summary> | ||
public class RestoreCommandException : Exception, ILogMessageException | ||
{ | ||
private readonly IRestoreLogMessage _logMessage; | ||
|
||
public RestoreCommandException(IRestoreLogMessage logMessage) | ||
: base(logMessage?.Message) | ||
{ | ||
_logMessage = logMessage ?? throw new ArgumentNullException(nameof(logMessage)); | ||
} | ||
|
||
public ILogMessage AsLogMessage() | ||
{ | ||
return _logMessage; | ||
} | ||
} | ||
} |
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.
static readonly?
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.
I'm mixed on this. I'm not sure that the benefit of making this static out weighs creating this every time the assembly is loaded.