Skip to content
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

Fix https://github.com/NuGet/Home/issues/1468 #12

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/NuGet.Core/NuGet.Commands/NuGet.Commands.xproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<ProduceOutputsOnBuild>True</ProduceOutputsOnBuild>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
115 changes: 79 additions & 36 deletions src/NuGet.Core/NuGet.Commands/RestoreCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,13 +220,14 @@ private async Task<IEnumerable<RestoreTargetGraph>> ExecuteRestoreAsync(NuGetv3L
localRepository,
remoteWalker,
context,
allGraphs,
writeToLockFile: true,
token: token);

var success = result.Item1;
var runtimes = result.Item3;
var success = result.Success;
var runtimes = result.RuntimeGraph;

allGraphs.AddRange(result.Item2);
allGraphs.AddRange(result.RestoreTargetGraph);

_success = success;

Expand Down Expand Up @@ -256,29 +257,31 @@ private async Task<IEnumerable<RestoreTargetGraph>> ExecuteRestoreAsync(NuGetv3L
// Walk additional runtime graphs for supports checks
if (_success && _request.CompatibilityProfiles.Any())
{
var compatibiliyResult = await TryRestore(projectRange,
var compatibilityResult = await TryRestore(projectRange,
_request.CompatibilityProfiles,
allInstalledPackages,
localRepository,
remoteWalker,
context,
allGraphs,
writeToLockFile: false,
token: token);

_success = compatibiliyResult.Item1;
_success = compatibilityResult.Success;

allGraphs.AddRange(compatibiliyResult.Item2);
allGraphs.AddRange(compatibilityResult.RestoreTargetGraph);
}

return allGraphs;
}

private async Task<Tuple<bool, List<RestoreTargetGraph>, RuntimeGraph>> TryRestore(LibraryRange projectRange,
private async Task<RestorePrivateResult> TryRestore(LibraryRange projectRange,
IEnumerable<FrameworkRuntimePair> frameworkRuntimePairs,
HashSet<LibraryIdentity> allInstalledPackages,
NuGetv3LocalRepository localRepository,
RemoteDependencyWalker remoteWalker,
RemoteWalkContext context,
IList<RestoreTargetGraph> existingGraphs,
bool writeToLockFile,
CancellationToken token)
{
Expand All @@ -289,14 +292,18 @@ private async Task<Tuple<bool, List<RestoreTargetGraph>, RuntimeGraph>> TryResto

foreach (var pair in runtimesByFramework)
{
_log.LogVerbose(Strings.FormatLog_RestoringPackages(pair.Key.DotNetFrameworkName));
// Remove duplicate pairs
if (existingGraphs.Any(g => string.IsNullOrEmpty(g.RuntimeIdentifier) && g.Framework == pair.Key))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this again, this looks wrong

{
_log.LogVerbose(Strings.FormatLog_RestoringPackages(pair.Key.DotNetFrameworkName));

frameworkTasks.Add(WalkDependenciesAsync(projectRange,
pair.Key,
remoteWalker,
context,
writeToLockFile: writeToLockFile,
token: token));
frameworkTasks.Add(WalkDependenciesAsync(projectRange,
pair.Key,
remoteWalker,
context,
writeToLockFile: writeToLockFile,
token: token));
}
}

var frameworkGraphs = await Task.WhenAll(frameworkTasks);
Expand All @@ -305,7 +312,12 @@ private async Task<Tuple<bool, List<RestoreTargetGraph>, RuntimeGraph>> TryResto

if (!ResolutionSucceeded(frameworkGraphs))
{
return Tuple.Create(false, graphs, allRuntimes);
return new RestorePrivateResult()
{
Success = false,
RestoreTargetGraph = graphs,
RuntimeGraph = allRuntimes,
};
}

await InstallPackagesAsync(graphs,
Expand All @@ -321,22 +333,27 @@ await InstallPackagesAsync(graphs,
var runtimeTasks = new List<Task<RestoreTargetGraph[]>>();
foreach (var graph in graphs)
{
// Get the runtime graph for this specific tfm graph
var runtimeGraph = GetRuntimeGraph(graph, localRepository);
var runtimeIds = runtimesByFramework[graph.Framework];

// Merge all runtimes for the output
allRuntimes = RuntimeGraph.Merge(allRuntimes, runtimeGraph);

runtimeTasks.Add(WalkRuntimeDependenciesAsync(projectRange,
graph,
runtimeIds.Where(rid => !string.IsNullOrEmpty(rid)),
remoteWalker,
context,
localRepository,
runtimeGraph,
writeToLockFile: writeToLockFile,
token: token));
// Remove duplicate pairs
if (existingGraphs.Any(g => string.Equals(g.RuntimeIdentifier, graph.RuntimeIdentifier, StringComparison.Ordinal) &&
g.Framework == graph.Framework))
{
// Get the runtime graph for this specific tfm graph
var runtimeGraph = GetRuntimeGraph(graph, localRepository);
var runtimeIds = runtimesByFramework[graph.Framework];

// Merge all runtimes for the output
allRuntimes = RuntimeGraph.Merge(allRuntimes, runtimeGraph);

runtimeTasks.Add(WalkRuntimeDependenciesAsync(projectRange,
graph,
runtimeIds.Where(rid => !string.IsNullOrEmpty(rid)),
remoteWalker,
context,
localRepository,
runtimeGraph,
writeToLockFile: writeToLockFile,
token: token));
}
}

foreach (var runtimeSpecificGraph in (await Task.WhenAll(runtimeTasks)).SelectMany(g => g))
Expand All @@ -348,7 +365,12 @@ await InstallPackagesAsync(graphs,

if (!ResolutionSucceeded(runtimeGraphs))
{
return Tuple.Create(false, graphs, allRuntimes);
return new RestorePrivateResult()
{
Success = false,
RestoreTargetGraph = graphs,
RuntimeGraph = allRuntimes,
};
}

// Install runtime-specific packages
Expand All @@ -359,7 +381,12 @@ await InstallPackagesAsync(runtimeGraphs,
token);
}

return Tuple.Create(true, graphs, allRuntimes);
return new RestorePrivateResult()
{
Success = true,
RestoreTargetGraph = graphs,
RuntimeGraph = allRuntimes,
};
}

private bool ResolutionSucceeded(IEnumerable<RestoreTargetGraph> graphs)
Expand All @@ -371,16 +398,19 @@ private bool ResolutionSucceeded(IEnumerable<RestoreTargetGraph> graphs)
{
success = false;
_log.LogError(Strings.FormatLog_FailedToResolveConflicts(graph.Name));

foreach (var conflict in graph.Conflicts)
{
_log.LogError(Strings.FormatLog_ResolverConflict(
conflict.Name,
string.Join(", ", conflict.Requests)));
}
}

if (graph.Unresolved.Any())
{
success = false;

foreach (var unresolved in graph.Unresolved)
{
_log.LogError(Strings.FormatLog_UnresolvedDependency(unresolved.Name,
Expand All @@ -405,8 +435,10 @@ private MSBuildRestoreResult RestoreMSBuildFiles(PackageSpec project,
return new MSBuildRestoreResult(project.Name, project.BaseDirectory);
}

var graph = targetGraphs
.Single(g => g.Framework.Equals(projectFrameworks[0]) && string.IsNullOrEmpty(g.RuntimeIdentifier));
var graphs = targetGraphs
.Where(g => g.Framework.Equals(projectFrameworks[0]) && string.IsNullOrEmpty(g.RuntimeIdentifier));

var graph = graphs.Single();

var pathResolver = new VersionFolderPathResolver(repository.RepositoryRoot);

Expand Down Expand Up @@ -457,7 +489,11 @@ private MSBuildRestoreResult RestoreMSBuildFiles(PackageSpec project,
}
}

return new MSBuildRestoreResult(project.Name, project.BaseDirectory, repository.RepositoryRoot, props, targets);
return new MSBuildRestoreResult(project.Name,
project.BaseDirectory,
repository.RepositoryRoot,
props,
targets);
}

private LockFile CreateLockFile(
Expand Down Expand Up @@ -875,5 +911,12 @@ private IRemoteDependencyProvider CreateProviderFromSource(PackageSource source,
var nugetRepository = Repository.Factory.GetCoreV3(source.Source);
return new SourceRepositoryDependencyProvider(nugetRepository, _log, cacheContext);
}

private class RestorePrivateResult
{
public bool Success { get; set; }
public List<RestoreTargetGraph> RestoreTargetGraph { get; set; }
public RuntimeGraph RuntimeGraph { get; set; }
}
}
}
2 changes: 2 additions & 0 deletions src/NuGet.Core/NuGet.Commands/RestoreGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;
using NuGet.Client;
using NuGet.DependencyResolver;
using NuGet.Frameworks;
Expand All @@ -13,6 +14,7 @@

namespace NuGet.Commands
{
[DebuggerDisplay("{Name}: {RuntimeIdentifier}, {Framework}")]
public class RestoreTargetGraph
{
/// <summary>
Expand Down