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

Support for processing metaproj references from a solution file #1259

Closed
wants to merge 1 commit into from

Conversation

emgarten
Copy link
Member

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

Tracking for the integration tests around this is here: NuGet/Home#4875 (post migration)

{
// Log inputs
var log = new MSBuildLogger(Log);
log.LogDebug($"(in) ProjectReferences '{string.Join(";", ProjectReferences.Select(p => p.ItemSpec))}'");
Copy link
Contributor

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?

Copy link
Member Author

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

Copy link
Contributor

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.

Copy link
Member Author

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

@@ -0,0 +1,74 @@
using System;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we need to decide whether header is needed or not and be consistent about it.

Copy link
Member Author

Choose a reason for hiding this comment

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

We should remove it from all files to reduce the daily overhead of this or automate it. Currently the tool from .NET that can do this doesn't work on PackageReference or project.json projects.


namespace NuGet.Build.Tasks
{
public class GetRestoreSolutionProjectsTask : Task
Copy link
Contributor

Choose a reason for hiding this comment

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

Add xml-doc


// Filter obvious duplicates without considering OS case sensitivity.
// This will be filtered further when creating the spec.
var seen = new HashSet<string>(StringComparer.Ordinal);
Copy link
Contributor

Choose a reason for hiding this comment

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

Case-sensitive on purpose?

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like this can be cleaned up

// Filter obvious duplicates without considering OS case sensitivity.
// This will be filtered further when creating the spec.
var seen = new HashSet<string>(StringComparer.Ordinal);
var parentDirectory = Path.GetDirectoryName(SolutionFilePath);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this fail if invalid string was provided for SolutionFilePath?

Copy link
Contributor

Choose a reason for hiding this comment

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

Can the path be relative?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

It's not guaranteed though the target won't change in future or this task won't be called from within different target. All inputs should be validated regardless.


foreach (var project in ProjectReferences)
{
if (string.IsNullOrEmpty(project.ItemSpec))
Copy link
Contributor

Choose a reason for hiding this comment

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

Should it fail or warn on invalid value?

Copy link
Member Author

@emgarten emgarten Mar 23, 2017

Choose a reason for hiding this comment

The 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.Combine(parentDirectory, project.ItemSpec);
Copy link
Contributor

Choose a reason for hiding this comment

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

Normalize the path in case relative project path provided.

Copy link
Member Author

@emgarten emgarten Mar 23, 2017

Choose a reason for hiding this comment

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

I'll update this, however the consumer of this is MSBuild which handles this fine internally.

Copy link
Contributor

@alpaix alpaix left a comment

Choose a reason for hiding this comment

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

Address the feedback. Add unit-tests for new class.

@emgarten emgarten force-pushed the dev-emgarten-metaproj branch from 5fd3732 to c2d4353 Compare March 23, 2017 18:18
public ITaskItem[] ProjectReferences { get; set; }

/// <summary>
/// Root project path used for resolving the absolute path.
Copy link
Contributor

Choose a reason for hiding this comment

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

root project path? or solution file path?

Copy link
Member Author

Choose a reason for hiding this comment

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

Root metaproj from the solution.. I can make this more clear :)

if (projectPath.EndsWith(MetaProjExtension, StringComparison.OrdinalIgnoreCase))
{
// Remove .metaproj from the path.
projectPath = projectPath.Substring(0, projectPath.Length - MetaProjExtension.Length);
Copy link
Contributor

Choose a reason for hiding this comment

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

can you instead do Path.Combine(Path.GetDirectoryName(file), Path.GetFileNameWithoutExtension(file) )

Copy link
Member Author

Choose a reason for hiding this comment

The 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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Either way would work fine though

Copy link
Contributor

Choose a reason for hiding this comment

The 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)

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
@emgarten emgarten force-pushed the dev-emgarten-metaproj branch from c2d4353 to af6eff5 Compare March 23, 2017 18:28
@emgarten
Copy link
Member Author

@alpaix unit tests are tracked in NuGet/Home#4875

@emgarten emgarten closed this Mar 23, 2017
@emgarten emgarten deleted the dev-emgarten-metaproj branch March 23, 2017 19:26
@natemcmaster
Copy link
Contributor

👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants