diff --git a/src/dotnet/commands/dotnet-msbuild/MSBuildForwardingApp.cs b/src/dotnet/commands/dotnet-msbuild/MSBuildForwardingApp.cs index 5b5e682329d..177f344ebb4 100644 --- a/src/dotnet/commands/dotnet-msbuild/MSBuildForwardingApp.cs +++ b/src/dotnet/commands/dotnet-msbuild/MSBuildForwardingApp.cs @@ -41,10 +41,12 @@ public MSBuildForwardingApp(IEnumerable argsToForward) { Type loggerType = typeof(MSBuildLogger); - argsToForward = argsToForward.Concat(new[] - { - $"/Logger:{loggerType.FullName},{loggerType.GetTypeInfo().Assembly.Location}" - }); + argsToForward = argsToForward + .Select(Escape) + .Concat(new[] + { + $"/Logger:{loggerType.FullName},{loggerType.GetTypeInfo().Assembly.Location}" + }); } catch (Exception) { @@ -77,6 +79,11 @@ internal static CommandOption AddVerbosityOption(CommandLineApplication app) return app.Option("-v|--verbosity", LocalizableStrings.VerbosityOptionDescription, CommandOptionType.SingleValue); } + private static string Escape(string arg) => + (arg.StartsWith("/p:RestoreSources=", StringComparison.OrdinalIgnoreCase)) ? + arg.Replace(";", "%3B") : // <-- this is a workaround for https://github.com/Microsoft/msbuild/issues/1622 + arg; + private static string GetMSBuildExePath() { return Path.Combine( diff --git a/test/dotnet-msbuild.Tests/GivenDotnetMSBuildBuildsProjects.cs b/test/dotnet-msbuild.Tests/GivenDotnetMSBuildBuildsProjects.cs index dde27668c61..2c00d40c92c 100644 --- a/test/dotnet-msbuild.Tests/GivenDotnetMSBuildBuildsProjects.cs +++ b/test/dotnet-msbuild.Tests/GivenDotnetMSBuildBuildsProjects.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Linq.Expressions; using System.Reflection; +using System.Runtime.InteropServices; using FluentAssertions; using Microsoft.DotNet.Configurer; using Microsoft.DotNet.Tools.MSBuild; @@ -76,6 +77,30 @@ public void When_help_is_invoked_Then_MSBuild_extra_options_text_is_included_in_ } } + [Fact] + public void WhenRestoreSourcesStartsWithUnixPathThenHttpsSourceIsParsedCorrectly() + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + return; + } + + // this is a workaround for https://github.com/Microsoft/msbuild/issues/1622 + var testInstance = TestAssets.Get("MSBuildTestApp") + .CreateInstance() + .WithSourceFiles() + .WithRestoreFiles(); + + var root = testInstance.Root; + var somePathThatExists = "/usr/local/bin"; + + var result = new DotnetCommand() + .WithWorkingDirectory(root) + .Execute($"msbuild /p:RestoreSources={somePathThatExists};https://api.nuget.org/v3/index.json /t:restore MSBuildTestApp.csproj"); + + result.Should().Pass(); + } + [Fact] public void WhenDotnetRunHelpIsInvokedAppArgumentsTextIsIncludedInOutput() { @@ -85,7 +110,7 @@ public void WhenDotnetRunHelpIsInvokedAppArgumentsTextIsIncludedInOutput() var result = new TestCommand("dotnet") .WithWorkingDirectory(projectDirectory.Path) .ExecuteWithCapturedOutput("run --help"); - + result.ExitCode.Should().Be(0); result.StdOut.Should().Contain(AppArgumentsText); }