Skip to content

Commit

Permalink
Merge pull request #9585 from dotnet/u/fix#9584
Browse files Browse the repository at this point in the history
Replace backward/forward slash in ProjectAndExecutableLaunchHandlerHelpers.GetOutputDirectoryAsync with system default
  • Loading branch information
LittleLittleCloud authored Nov 13, 2024
2 parents d2131d6 + 8f0e73a commit 0602bda
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ public static async Task<string> GetOutputDirectoryAsync(this ConfiguredProject

IProjectProperties properties = configuredProject.Services.ProjectPropertiesProvider.GetCommonProperties();

return await properties.GetEvaluatedPropertyValueAsync(ConfigurationGeneral.OutDirProperty);
var outDir = await properties.GetEvaluatedPropertyValueAsync(ConfigurationGeneral.OutDirProperty);

return ReplaceSlashWithSystemDefault(outDir);
}

/// <summary>
Expand Down Expand Up @@ -213,4 +215,9 @@ public static async Task<string> GetDefaultWorkingDirectoryAsync(ConfiguredProje

return (exeToRun, runArguments, runWorkingDirectory);
}

private static string ReplaceSlashWithSystemDefault(string path)
{
return path.Replace('/', Path.DirectorySeparatorChar).Replace('\\', Path.DirectorySeparatorChar);
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
// Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE.md file in the project root for more information.

using System.Runtime.InteropServices;
using Microsoft.VisualStudio.IO;
using Microsoft.VisualStudio.ProjectSystem.Utilities;

namespace Microsoft.VisualStudio.ProjectSystem.Debug;

public class ProjectAndExecutableLaunchHandlerHelpersTests
{
[Fact]
public async Task GetOutputDirectoryAsync_Returns_OutputDirectory_When_FullPath()
[Theory]
[InlineData("C:\\OutputDirectory", "/C:/OutputDirectory", "C:\\OutputDirectory")] // Windows
[InlineData("\\mnt\\OutputDirectory", "/mnt/OutputDirectory", "/mnt/OutputDirectory")] // Linux
[InlineData("\\mnt\\OutputDirectory", "/mnt/OutputDirectory", "/mnt\\OutputDirectory")] // mixed
public async Task GetOutputDirectoryAsync_Returns_OutputDirectory_When_FullPath(string expectedOutputDirectoryOnWindows, string expectedOutputDirectoryOnLinux, string actualOutputDirectory)
{
// Arrange
var expectedOutputDirectory = @"C:\OutputDirectory";
var expectedOutputDirectory = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? expectedOutputDirectoryOnWindows : expectedOutputDirectoryOnLinux;
var project = CreateConfiguredProject(new() { { "OutDir", expectedOutputDirectory } });

// Act
Expand Down

0 comments on commit 0602bda

Please sign in to comment.