escape semicolons when forwarding RestoreSources to MSBuild

This commit is contained in:
jonsequitur 2017-01-31 16:47:41 -08:00
parent 3e07297525
commit 2ea3af799d
2 changed files with 37 additions and 5 deletions

View file

@ -41,10 +41,12 @@ namespace Microsoft.DotNet.Tools.MSBuild
{ {
Type loggerType = typeof(MSBuildLogger); Type loggerType = typeof(MSBuildLogger);
argsToForward = argsToForward.Concat(new[] argsToForward = argsToForward
{ .Select(Escape)
$"/Logger:{loggerType.FullName},{loggerType.GetTypeInfo().Assembly.Location}" .Concat(new[]
}); {
$"/Logger:{loggerType.FullName},{loggerType.GetTypeInfo().Assembly.Location}"
});
} }
catch (Exception) catch (Exception)
{ {
@ -77,6 +79,11 @@ namespace Microsoft.DotNet.Tools.MSBuild
return app.Option("-v|--verbosity", LocalizableStrings.VerbosityOptionDescription, CommandOptionType.SingleValue); 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() private static string GetMSBuildExePath()
{ {
return Path.Combine( return Path.Combine(

View file

@ -5,6 +5,7 @@ using System;
using System.Linq; using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices;
using FluentAssertions; using FluentAssertions;
using Microsoft.DotNet.Configurer; using Microsoft.DotNet.Configurer;
using Microsoft.DotNet.Tools.MSBuild; using Microsoft.DotNet.Tools.MSBuild;
@ -76,6 +77,30 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests
} }
} }
[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] [Fact]
public void WhenDotnetRunHelpIsInvokedAppArgumentsTextIsIncludedInOutput() public void WhenDotnetRunHelpIsInvokedAppArgumentsTextIsIncludedInOutput()
{ {
@ -85,7 +110,7 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests
var result = new TestCommand("dotnet") var result = new TestCommand("dotnet")
.WithWorkingDirectory(projectDirectory.Path) .WithWorkingDirectory(projectDirectory.Path)
.ExecuteWithCapturedOutput("run --help"); .ExecuteWithCapturedOutput("run --help");
result.ExitCode.Should().Be(0); result.ExitCode.Should().Be(0);
result.StdOut.Should().Contain(AppArgumentsText); result.StdOut.Should().Contain(AppArgumentsText);
} }