Skip to content

Commit

Permalink
Use Process.ArgumentList instead of Arguments
Browse files Browse the repository at this point in the history
This should fix problems with incorrect escaping of
arguments
fixes #1476
  • Loading branch information
exyi committed Jan 18, 2023
1 parent 00d67b4 commit 614e62c
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
7 changes: 5 additions & 2 deletions src/Tools/CommandLine/CompilerCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,12 @@ public static int HandleLint(

var pinfo = new ProcessStartInfo {
FileName = executable,
UseShellExecute = false,
Arguments = string.Join(' ', compilerArgs)
UseShellExecute = false
};
foreach (var a in compilerArgs)
{
pinfo.ArgumentList.Add(a);
}

var process = System.Diagnostics.Process.Start(pinfo);
process.WaitForExit();
Expand Down
34 changes: 19 additions & 15 deletions src/Tools/CommandLine/MSBuild.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using NuGet.Frameworks;
using DotVVM.Framework.Utils;

namespace DotVVM.CommandLine
{
Expand Down Expand Up @@ -42,7 +43,7 @@ public static MSBuild CreateFromSdk()

var startInfo = new ProcessStartInfo
{
Arguments = "-property installationPath",
ArgumentList = { "-property", "installationPath" },
RedirectStandardOutput = true,
FileName = vswhere.FullName,
UseShellExecute = false,
Expand Down Expand Up @@ -116,7 +117,7 @@ public bool TryInvoke(
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
}
logger.LogDebug($"Invoking MSBuild with args: '{startInfo.Arguments}'.");
logger.LogDebug($"Invoking MSBuild with args: '{startInfo.ArgumentList.StringJoin(" ")}'.");
var process = Process.Start(startInfo);
if (!showOutput)
{
Expand All @@ -140,7 +141,7 @@ public bool TryInvoke(
var startInfo = GetProcessStartInfo(project, properties, targets, restore, verbosity);
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
logger.LogDebug($"Invoking MSBuild with args: '{startInfo.Arguments}'.");
logger.LogDebug($"Invoking MSBuild with args: '{startInfo.ArgumentList.StringJoin(" ")}'.");

var process = Process.Start(startInfo);
var stderrTask = Task.Run(() => process.StandardError.ReadToEnd());
Expand Down Expand Up @@ -171,31 +172,34 @@ private ProcessStartInfo GetProcessStartInfo(
bool restore = false,
string verbosity = "minimal")
{
var sb = new StringBuilder();
sb.Append(string.Join(" ", PrefixedArgs));
var p = new ProcessStartInfo
{
FileName = ExecutablePath
};
foreach (var a in PrefixedArgs)
{
p.ArgumentList.Add(a);
}
if (restore)
{
sb.Append(" -restore");
p.ArgumentList.Add("-restore");
}
sb.Append($" -verbosity:{verbosity}");
p.ArgumentList.Add($"-verbosity:{verbosity}");
if (properties is object)
{
foreach(var property in properties)
{
sb.Append($" -property:{property.Key}={property.Value}");
p.ArgumentList.Add($"-property:{property.Key}={property.Value}");
}
}
if (targets is object)
{
sb.Append($" -target:{string.Join(";", targets)}");
p.ArgumentList.Add($"-target:{string.Join(";", targets)}");
}

sb.Append($" {project.FullName}");
return new ProcessStartInfo
{
FileName = ExecutablePath,
Arguments = sb.ToString()
};
p.ArgumentList.Add($"{project.FullName}");

return p;
}
}
}

0 comments on commit 614e62c

Please sign in to comment.