-
Notifications
You must be signed in to change notification settings - Fork 694
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
Support for processing metaproj references from a solution file #1259
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 |
---|---|---|
@@ -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)) | ||
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. Should it fail or warn on invalid value? 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. It should not be, but if it is the error/warning would be very unhelpful since it would not refer to anything. This protects against that. |
||
{ | ||
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); | ||
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. can you instead do Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) ) 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. I did that initially but simplified to this. We know here exactly what needs to happen, an extra helper isn't needed. 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. Either way would work fine though 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. i'd prefer being more verbose and call the helpers but your call. In reply to: 107747427 [](ancestors = 107747427) |
||
} | ||
|
||
// Clone items using the modified path | ||
var newEntry = new TaskItem(projectPath, project.CloneCustomMetadata()); | ||
entries.Add(newEntry); | ||
} | ||
|
||
OutputProjectReferences = entries.ToArray(); | ||
|
||
return true; | ||
} | ||
} | ||
} |
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.
Can
ItemSpec
be null or empty?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.
It can't be null
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.
Then it's inconsistent with line 50 where you check the same value for null.
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.
It checks for empty also