Skip to content

Commit

Permalink
Get full path before obtaining path root
Browse files Browse the repository at this point in the history
  • Loading branch information
mruxmohan4 committed Mar 7, 2024
1 parent eb10dd6 commit cd17041
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
16 changes: 12 additions & 4 deletions src/Microsoft.VisualStudio.SlnGen.UnitTests/SlnFileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1240,19 +1240,27 @@ public void EmitWarningForProjectsOnMultipleDrives()
TestLogger logger = new ();
SlnFile slnFile = new ();
SlnProject[] projects = new[] { projectA, projectB };
string solutionFilePath = @$"X:\{Path.GetRandomFileName()}";
string solutionFilePath = isWindowsPlatform ? @$"X:\{Path.GetRandomFileName()}" : $"/mnt/{Path.GetRandomFileName()}";
StringBuilderTextWriter writer = new (new StringBuilder(), new List<string>());

slnFile.AddProjects(projects);
slnFile.Save(solutionFilePath, writer, useFolders: true, logger);

logger.Errors.Count.ShouldBe(0);
logger.Warnings.Count.ShouldBe(1);
logger.Warnings.FirstOrDefault().Message.ShouldContain("Detected folder on a different drive from the root solution path");

if (isWindowsPlatform)
{
logger.Warnings.Count.ShouldBe(1);
logger.Warnings.FirstOrDefault().Message.ShouldContain("Detected folder on a different drive from the root solution path");
}
else
{
logger.Warnings.Count.ShouldBe(0);
}
}

[Fact]
public void DoNotEmitWarningForEmptyRootPathDrive()
public void DoNotEmitWarningForRootPathWithoutPathRoot()
{
TestLogger logger = new ();
SlnFile slnFile = new ();
Expand Down
5 changes: 3 additions & 2 deletions src/Microsoft.VisualStudio.SlnGen/SlnFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -483,14 +483,15 @@ internal void Save(string rootPath, TextWriter writer, bool useFolders, ISlnGenL
if (hierarchy != null)
{
bool logDriveWarning = false;
string rootPathDrive = Path.GetPathRoot(rootPath);
string rootPathDrive = Path.GetPathRoot(Path.GetFullPath(rootPath));
foreach (SlnFolder folder in hierarchy.Folders)
{
bool useSeparateDrive = false;
bool hasFullPath = !string.IsNullOrEmpty(folder.FullPath);
if (hasFullPath)
{
string folderPathDrive = Path.GetPathRoot(folder.FullPath);
string folderPathDrive = Path.GetPathRoot(Path.GetFullPath(folder.FullPath));
// Only emit warning when root path has root directory information
if (!string.IsNullOrEmpty(rootPathDrive) && !string.Equals(rootPathDrive, folderPathDrive, StringComparison.OrdinalIgnoreCase))
{
useSeparateDrive = true;
Expand Down

0 comments on commit cd17041

Please sign in to comment.