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 backslashes in solution paths #2963

Merged
merged 3 commits into from
Feb 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/Build.UnitTests/Construction/SolutionFile_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,35 @@ public void ParseFirstProjectLineWhereProjectNameHasSpecialCharacters()
Assert.Equal("Unique name-GUID", proj.ProjectGuid);
}

/// <summary>
/// Test some characters that are valid in a file name but that also could be
/// considered a delimiter by a parser. Does quoting work for special characters?
/// </summary>
[Fact]
public void ParseFirstProjectLineWhereProjectPathHasBackslash()
{
using (var env = TestEnvironment.Create())
{
var solutionFolder = env.CreateFolder(Path.Combine(FileUtilities.GetTemporaryDirectory(), "sln"));
var projectFolder = env.CreateFolder(Path.Combine(solutionFolder.FolderPath, "RelativePath"));

SolutionFile p = new SolutionFile();
p.FullPath = Path.Combine(solutionFolder.FolderPath, "RelativePath", "project file");
p.SolutionFileDirectory = Path.GetFullPath(solutionFolder.FolderPath);
ProjectInSolution proj = new ProjectInSolution(p);

p.ParseFirstProjectLine
(
"Project(\"{Project GUID}\") = \"ProjectInSubdirectory\", \"RelativePath\\project file\" , \"Unique name-GUID\"",
proj
);
Assert.Equal(SolutionProjectType.Unknown, proj.ProjectType);
Assert.Equal("ProjectInSubdirectory", proj.ProjectName);
Assert.Equal(Path.Combine("RelativePath", "project file"), proj.RelativePath);
Assert.Equal("Unique name-GUID", proj.ProjectGuid);
}
}

/// <summary>
/// Helper method to create a SolutionFile object, and call it to parse the SLN file
/// represented by the string contents passed in.
Expand Down
7 changes: 6 additions & 1 deletion src/Build/Construction/Solution/ProjectInSolution.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Security;
using System.Text;
using System.Xml;
using Microsoft.Build.Shared;

using XMakeAttributes = Microsoft.Build.Shared.XMakeAttributes;
using ProjectFileErrorUtilities = Microsoft.Build.Shared.ProjectFileErrorUtilities;
Expand Down Expand Up @@ -155,7 +156,11 @@ public string ProjectName
public string RelativePath
{
get { return _relativePath; }
internal set { _relativePath = value; }
internal set
{
_relativePath = FileUtilities.MaybeAdjustFilePath(value,
baseDirectory:this.ParentSolution.SolutionFileDirectory ?? String.Empty);
}
}

/// <summary>
Expand Down