Skip to content

Commit

Permalink
Create a dummy target for every tfm/rid combo when a project being re…
Browse files Browse the repository at this point in the history
…stored is inconsistent in locked mode (#4524)
  • Loading branch information
nkolev92 authored Mar 31, 2022
1 parent 79e32a7 commit 972895d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,10 @@ public async Task<RestoreResult> ExecuteAsync(CancellationToken token)
// caller of RestoreCommand to have provided at least one AdditionalMessage in RestoreArgs.
// The other scenario is when the lock file is not up to date and we're running locked mode.
// In that case we want to write a `target` for each target framework to avoid missing target errors from the SDK build tasks.
graphs = _request.Project.TargetFrameworks.Select(e =>
var frameworkRuntimePair = CreateFrameworkRuntimePairs(_request.Project, RequestRuntimeUtility.GetRestoreRuntimes(_request));
graphs = frameworkRuntimePair.Select(e =>
{
return RestoreTargetGraph.Create(_request.Project.RuntimeGraph, Enumerable.Empty<GraphNode<RemoteResolveResult>>(), contextForProject, _logger, e.FrameworkName, null);
return RestoreTargetGraph.Create(_request.Project.RuntimeGraph, Enumerable.Empty<GraphNode<RemoteResolveResult>>(), contextForProject, _logger, e.Framework, e.RuntimeIdentifier);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using NuGet.ProjectModel;

namespace NuGet.Commands
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,7 @@ public async Task Restore_WithLockedModeAndNoObjFolder_RestoreFailsAndWritesOutR
"a",
pathContext.SolutionRoot,
net461);
projectA.Properties.Add("RuntimeIdentifier", "win");

var packageX = new SimpleTestPackageContext()
{
Expand Down Expand Up @@ -931,10 +932,14 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(

// Assert
Assert.Contains("NU1004:", result.Errors);
var logCodes = projectA.AssetsFile.LogMessages.Select(e => e.Code);
var assetsFile = projectA.AssetsFile;
var logCodes = assetsFile.LogMessages.Select(e => e.Code);
Assert.Contains(NuGetLogCode.NU1004, logCodes);
var ridlessMainTarget = projectA.AssetsFile.Targets.FirstOrDefault(e => string.IsNullOrEmpty(e.RuntimeIdentifier));
Assert.Equal(2, assetsFile.Targets.Count);
var ridlessMainTarget = assetsFile.Targets.FirstOrDefault(e => string.IsNullOrEmpty(e.RuntimeIdentifier));
Assert.Equal(net461, ridlessMainTarget.TargetFramework);
var ridMainTarget = assetsFile.Targets.FirstOrDefault(e => "win".Equals(e.RuntimeIdentifier));
Assert.Equal("win", ridMainTarget.RuntimeIdentifier);
Assert.True(File.Exists(projectA.PropsOutput));
Assert.True(File.Exists(projectA.TargetsOutput));
Assert.True(File.Exists(projectA.CacheFileOutputPath));
Expand Down

0 comments on commit 972895d

Please sign in to comment.