-
Notifications
You must be signed in to change notification settings - Fork 697
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for processing metaproj references from a solution file
This change adds a task to modify project references coming from a solution file. When project build order is used the solution file read by restore contains links to .metaproj files instead of the actual projects. The actual project can be found by removing the metaproj extension. Cleaning up _SplitProjectReferencesByFileExistence, the outputs from this are not used since ProjectReference is used direcetly. There is no reason to depend on this external target. Fixes NuGet/Home#4869 Fixes NuGet/Home#4578
- Loading branch information
Showing
7 changed files
with
113 additions
and
17 deletions.
There are no files selected for viewing
5 changes: 4 additions & 1 deletion
5
src/NuGet.Core/NuGet.Build.Tasks/GetRestoreDotnetCliToolsTask.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
src/NuGet.Core/NuGet.Build.Tasks/GetRestorePackageReferencesTask.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
src/NuGet.Core/NuGet.Build.Tasks/GetRestoreProjectJsonPathTask.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
src/NuGet.Core/NuGet.Build.Tasks/GetRestoreProjectReferencesTask.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
src/NuGet.Core/NuGet.Build.Tasks/GetRestoreSolutionProjectsTask.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
{ | ||
/// <summary> | ||
/// Convert .metaproj paths to project paths. | ||
/// </summary> | ||
public class GetRestoreSolutionProjectsTask : Task | ||
{ | ||
private const string MetaProjExtension = ".metaproj"; | ||
|
||
/// <summary> | ||
/// Solution project references. | ||
/// </summary> | ||
[Required] | ||
public ITaskItem[] ProjectReferences { get; set; } | ||
|
||
/// <summary> | ||
/// Root path used for resolving the absolute project paths. | ||
/// </summary> | ||
[Required] | ||
public string SolutionFilePath { get; set; } | ||
|
||
/// <summary> | ||
/// Output items | ||
/// </summary> | ||
[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<ITaskItem>(); | ||
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters