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);
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 @@ namespace Microsoft.DotNet.Tools.MSBuild
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(

View file

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