diff --git a/src/NuGet.Core/NuGet.Build.Tasks/GetRestoreDotnetCliToolsTask.cs b/src/NuGet.Core/NuGet.Build.Tasks/GetRestoreDotnetCliToolsTask.cs
index 897d3b52067..5f985c9fa94 100644
--- a/src/NuGet.Core/NuGet.Build.Tasks/GetRestoreDotnetCliToolsTask.cs
+++ b/src/NuGet.Core/NuGet.Build.Tasks/GetRestoreDotnetCliToolsTask.cs
@@ -1,4 +1,7 @@
-using System;
+// 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.Collections.Generic;
using System.IO;
using System.Linq;
diff --git a/src/NuGet.Core/NuGet.Build.Tasks/GetRestorePackageReferencesTask.cs b/src/NuGet.Core/NuGet.Build.Tasks/GetRestorePackageReferencesTask.cs
index 113a2e05b50..ec6e7b7e276 100644
--- a/src/NuGet.Core/NuGet.Build.Tasks/GetRestorePackageReferencesTask.cs
+++ b/src/NuGet.Core/NuGet.Build.Tasks/GetRestorePackageReferencesTask.cs
@@ -1,4 +1,7 @@
-using System;
+// 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.Collections.Generic;
using System.Linq;
using Microsoft.Build.Framework;
diff --git a/src/NuGet.Core/NuGet.Build.Tasks/GetRestoreProjectJsonPathTask.cs b/src/NuGet.Core/NuGet.Build.Tasks/GetRestoreProjectJsonPathTask.cs
index 72320e47116..4910b102dd5 100644
--- a/src/NuGet.Core/NuGet.Build.Tasks/GetRestoreProjectJsonPathTask.cs
+++ b/src/NuGet.Core/NuGet.Build.Tasks/GetRestoreProjectJsonPathTask.cs
@@ -1,4 +1,7 @@
-using System.IO;
+// 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.IO;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using Newtonsoft.Json;
diff --git a/src/NuGet.Core/NuGet.Build.Tasks/GetRestoreProjectReferencesTask.cs b/src/NuGet.Core/NuGet.Build.Tasks/GetRestoreProjectReferencesTask.cs
index 0dc0b2d9e1f..2ecb83ae61c 100644
--- a/src/NuGet.Core/NuGet.Build.Tasks/GetRestoreProjectReferencesTask.cs
+++ b/src/NuGet.Core/NuGet.Build.Tasks/GetRestoreProjectReferencesTask.cs
@@ -1,4 +1,7 @@
-using System;
+// 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.Collections.Generic;
using System.IO;
using System.Linq;
diff --git a/src/NuGet.Core/NuGet.Build.Tasks/GetRestoreSolutionProjectsTask.cs b/src/NuGet.Core/NuGet.Build.Tasks/GetRestoreSolutionProjectsTask.cs
new file mode 100644
index 00000000000..5e859eff985
--- /dev/null
+++ b/src/NuGet.Core/NuGet.Build.Tasks/GetRestoreSolutionProjectsTask.cs
@@ -0,0 +1,76 @@
+// 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.Collections.Generic;
+using System.IO;
+using System.Linq;
+using Microsoft.Build.Framework;
+using Microsoft.Build.Utilities;
+
+namespace NuGet.Build.Tasks
+{
+ ///
+ /// Convert .metaproj paths to project paths.
+ ///
+ public class GetRestoreSolutionProjectsTask : Task
+ {
+ private const string MetaProjExtension = ".metaproj";
+
+ ///
+ /// Solution project references.
+ ///
+ [Required]
+ public ITaskItem[] ProjectReferences { get; set; }
+
+ ///
+ /// Root path used for resolving the absolute project paths.
+ ///
+ [Required]
+ public string SolutionFilePath { get; set; }
+
+ ///
+ /// Output items
+ ///
+ [Output]
+ public ITaskItem[] OutputProjectReferences { get; set; }
+
+ public override bool Execute()
+ {
+ // Log inputs
+ var log = new MSBuildLogger(Log);
+ log.LogDebug($"(in) ProjectReferences '{string.Join(";", ProjectReferences.Select(p => p.ItemSpec))}'");
+ log.LogDebug($"(in) SolutionFilePath '{SolutionFilePath}'");
+
+ var entries = new List();
+ var parentDirectory = Path.GetDirectoryName(SolutionFilePath);
+
+ foreach (var project in ProjectReferences)
+ {
+ if (string.IsNullOrEmpty(project.ItemSpec))
+ {
+ continue;
+ }
+
+ var projectPath = Path.GetFullPath(Path.Combine(parentDirectory, project.ItemSpec));
+
+ // Check for the metaproj extension, this is auto generated by solutions instead of
+ // the actual project path when build order is set. For the purpose of restore
+ // the order is not important so we remove the extension to get the real project path.
+ if (projectPath.EndsWith(MetaProjExtension, StringComparison.OrdinalIgnoreCase))
+ {
+ // Remove .metaproj from the path.
+ projectPath = projectPath.Substring(0, projectPath.Length - MetaProjExtension.Length);
+ }
+
+ // Clone items using the modified path
+ var newEntry = new TaskItem(projectPath, project.CloneCustomMetadata());
+ entries.Add(newEntry);
+ }
+
+ OutputProjectReferences = entries.ToArray();
+
+ return true;
+ }
+ }
+}
diff --git a/src/NuGet.Core/NuGet.Build.Tasks/NuGet.targets b/src/NuGet.Core/NuGet.Build.Tasks/NuGet.targets
index 6cebcec8855..99c8c31cb77 100644
--- a/src/NuGet.Core/NuGet.Build.Tasks/NuGet.targets
+++ b/src/NuGet.Core/NuGet.Build.Tasks/NuGet.targets
@@ -76,6 +76,7 @@ Copyright (c) .NET Foundation. All rights reserved.
+
-
-
-
-
+
+
+
+
+
<_FilteredRestoreGraphProjectInputItemsTmp
@@ -210,7 +216,7 @@ Copyright (c) .NET Foundation. All rights reserved.
Entry point for creating the project to project restore graph.
============================================================
-->
-
@@ -321,7 +327,7 @@ Copyright (c) .NET Foundation. All rights reserved.
Returns="$(_CurrentProjectJsonPath)">
-
@@ -452,12 +458,12 @@ Copyright (c) .NET Foundation. All rights reserved.
<_RestoreCrossTargeting>true
-
+
<_RestoreSkipContentFileWrite Condition=" '$(TargetFrameworks)' == '' AND '$(TargetFramework)' == '' ">true
-
+
<_RestoreGraphEntry Include="$([System.Guid]::NewGuid())">
@@ -607,7 +613,6 @@ Copyright (c) .NET Foundation. All rights reserved.
============================================================
-->
diff --git a/src/NuGet.Core/NuGet.Build.Tasks/WriteRestoreGraphTask.cs b/src/NuGet.Core/NuGet.Build.Tasks/WriteRestoreGraphTask.cs
index 94406ef0df1..87d3948977e 100644
--- a/src/NuGet.Core/NuGet.Build.Tasks/WriteRestoreGraphTask.cs
+++ b/src/NuGet.Core/NuGet.Build.Tasks/WriteRestoreGraphTask.cs
@@ -1,4 +1,7 @@
-using System.IO;
+// 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.IO;
using System.Linq;
using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;