Skip to content

Commit

Permalink
Fix handling of relative paths when using graph builds with implicit …
Browse files Browse the repository at this point in the history
…restore (#7361)

Fixes #5898

Context
Executing projects changes the cwd, which makes relative paths behave unexpectedly. So when an implicit restore happens (/restore), then the cwd is different than what it was originally. For non-graph builds, this isn't a problem as the BuildRequestData gets the full path of the project file before the implicit restore, so there effectively are no relative paths to deal with. However, this was not the case for GraphBuildRequestData, so doing a build with /retore, /graph, and a relative path to a project file was erroring incorrectly.

Changes Made
The ProjectGraphEntryPoint constructor will now get the full path of the project file, similar to what BuildRequestData does today.

I also followed all uses of ProjectGraphEntryPoint.ProjectFile and removed any normalization since it's now always done already.

Testing
I tested this change calling msbuild on a relative path with graph on/off and restore on/off. It now behaves as expected.
  • Loading branch information
dfederm committed Feb 15, 2022
1 parent 4d3997c commit ea58158
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/Build/Graph/GraphBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ private static void AddEdgesFromSolution(IReadOnlyDictionary<ConfigurationMetada
valueComparer: StringComparer.OrdinalIgnoreCase,
items: solutionEntryPoint.GlobalProperties ?? ImmutableDictionary<string, string>.Empty);

var solution = SolutionFile.Parse(FileUtilities.NormalizePath(solutionEntryPoint.ProjectFile));
var solution = SolutionFile.Parse(solutionEntryPoint.ProjectFile);

if (solution.SolutionParserWarnings.Count != 0 || solution.SolutionParserErrorCodes.Count != 0)
{
Expand Down Expand Up @@ -410,7 +410,7 @@ private static List<ConfigurationMetadata> AddGraphBuildPropertyToEntryPoints(IE

AddGraphBuildGlobalVariable(globalPropertyDictionary);

var configurationMetadata = new ConfigurationMetadata(FileUtilities.NormalizePath(entryPoint.ProjectFile), globalPropertyDictionary);
var configurationMetadata = new ConfigurationMetadata(entryPoint.ProjectFile, globalPropertyDictionary);
entryPointConfigurationMetadata.Add(configurationMetadata);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Build/Graph/ProjectGraphEntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ public ProjectGraphEntryPoint(string projectFile, IDictionary<string, string> gl
{
ErrorUtilities.VerifyThrowArgumentLength(projectFile, nameof(projectFile));

ProjectFile = projectFile;
ProjectFile = FileUtilities.NormalizePath(projectFile);
GlobalProperties = globalProperties;
}

/// <summary>
/// Gets the project file to use for this entry point.
/// Gets the full path to the project file to use for this entry point.
/// </summary>
public string ProjectFile { get; }

Expand Down

0 comments on commit ea58158

Please sign in to comment.