Skip to content

Commit

Permalink
Update ProjectInSolution.AbsolutePath to return a normalized path
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffkl committed Dec 10, 2020
1 parent 1ff34e8 commit b018707
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
37 changes: 37 additions & 0 deletions src/Build.UnitTests/Construction/SolutionFile_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2400,5 +2400,42 @@ public void ParseSolutionFileContainingProjectsWithSimilarNames_FourProjects_One

exception.Message.ShouldStartWith(message);
}

/// <summary>
/// A test where paths contain ..\ segments
/// </summary>
[Fact]
public void ParseSolutionWithParentedPaths()
{
string solutionFileContents =
@"
Microsoft Visual Studio Solution File, Format Version 9.00
# Visual Studio 2005
Project('{749ABBD6-B803-4DA5-8209-498127164114}') = 'ProjectA', '..\ProjectA\ProjectA.csproj', '{0ABED153-9451-483C-8140-9E8D7306B216}'
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|AnyCPU = Debug|AnyCPU
Release|AnyCPU = Release|AnyCPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0ABED153-9451-483C-8140-9E8D7306B216}.Debug|AnyCPU.ActiveCfg = Debug|AnyCPU
{0ABED153-9451-483C-8140-9E8D7306B216}.Debug|AnyCPU.Build.0 = Debug|AnyCPU
{0ABED153-9451-483C-8140-9E8D7306B216}.Release|AnyCPU.ActiveCfg = Release|AnyCPU
{0ABED153-9451-483C-8140-9E8D7306B216}.Release|AnyCPU.Build.0 = Release|AnyCPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
";

SolutionFile solution = ParseSolutionHelper(solutionFileContents);
string expectedRelativePath = NativeMethodsShared.IsWindows ? @"..\ProjectA\ProjectA.csproj" : @"../ProjectA/ProjectA.csproj";
Assert.Equal("ProjectA", solution.ProjectsInOrder[0].ProjectName);
Assert.Equal(expectedRelativePath, solution.ProjectsInOrder[0].RelativePath);
Assert.Equal(Path.GetFullPath(Path.Combine(Path.GetDirectoryName(solution.FullPath), expectedRelativePath)), solution.ProjectsInOrder[0].AbsolutePath);
Assert.Equal("{0ABED153-9451-483C-8140-9E8D7306B216}", solution.ProjectsInOrder[0].ProjectGuid);
}
}
}
13 changes: 12 additions & 1 deletion src/Build/Construction/Solution/ProjectInSolution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,18 @@ internal set
/// <summary>
/// Returns the absolute path for this project
/// </summary>
public string AbsolutePath => Path.Combine(ParentSolution.SolutionFileDirectory, RelativePath);
public string AbsolutePath
{
get
{
if (string.IsNullOrWhiteSpace(ParentSolution?.SolutionFileDirectory))
{
return RelativePath;
}

return FileUtilities.NormalizePath(Path.Combine(ParentSolution.SolutionFileDirectory, RelativePath));
}
}

/// <summary>
/// The unique guid associated with this project, in "{XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX}" form
Expand Down
6 changes: 3 additions & 3 deletions src/Build/Graph/GraphBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ private static void AddEdgesFromSolution(IReadOnlyDictionary<ConfigurationMetada
{
newEntryPoints.Add(
new ProjectGraphEntryPoint(
FileUtilities.NormalizePath(project.AbsolutePath),
project.AbsolutePath,
solutionGlobalProperties
.SetItem("Configuration", projectConfiguration.ConfigurationName)
.SetItem("Platform", projectConfiguration.PlatformName)
Expand Down Expand Up @@ -344,7 +344,7 @@ IReadOnlyDictionary<string, IReadOnlyCollection<string>> GetSolutionDependencies

foreach (var projectWithDependencies in solutionFile.ProjectsInOrder.Where(p => p.Dependencies.Count != 0))
{
solutionDependencies[FileUtilities.NormalizePath(projectWithDependencies.AbsolutePath)] = projectWithDependencies.Dependencies.Select(
solutionDependencies[projectWithDependencies.AbsolutePath] = projectWithDependencies.Dependencies.Select(
dependencyGuid =>
{
// code snippet cloned from SolutionProjectGenerator.AddPropertyGroupForSolutionConfiguration
Expand All @@ -365,7 +365,7 @@ IReadOnlyDictionary<string, IReadOnlyCollection<string>> GetSolutionDependencies
// (If a project is not selected for build in the solution configuration, it won't build even if it's depended on by something that IS selected for build)
// .. and only if it's known to be MSBuild format, as projects can't use the information otherwise
return dependencyProject?.ProjectType == SolutionProjectType.KnownToBeMSBuildFormat
? FileUtilities.NormalizePath(dependencyProject.AbsolutePath)
? dependencyProject.AbsolutePath
: null;
})
.Where(p => p != null)
Expand Down

0 comments on commit b018707

Please sign in to comment.