Skip to content

Commit 1b88c97

Browse files
authored
Merge pull request github#3199 from hvitved/csharp/vsvars-unset-platform
C#: Unset `Platform` env variable when invoking `vcvarsall.bat`
2 parents 5af351e + 29e690e commit 1b88c97

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

csharp/autobuilder/Semmle.Autobuild/CommandBuilder.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System.Collections.Generic;
1+
using System.Collections.Generic;
22
using System.Linq;
33
using System.Text;
44

@@ -169,7 +169,7 @@ void NextCommand()
169169
arguments.Append(" &&");
170170
}
171171

172-
public CommandBuilder RunCommand(string exe, string? argumentsOpt = null)
172+
public CommandBuilder RunCommand(string exe, string? argumentsOpt = null, bool quoteExe = true)
173173
{
174174
var (exe0, arg0) =
175175
escapingMode == EscapeMode.Process && exe.EndsWith(".exe", System.StringComparison.Ordinal)
@@ -183,7 +183,10 @@ public CommandBuilder RunCommand(string exe, string? argumentsOpt = null)
183183
}
184184
else
185185
{
186-
QuoteArgument(exe0);
186+
if (quoteExe)
187+
QuoteArgument(exe0);
188+
else
189+
Argument(exe0);
187190
}
188191
Argument(arg0);
189192
Argument(argumentsOpt);

csharp/autobuilder/Semmle.Autobuild/MsBuildRule.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,14 @@ public BuildScript Analyse(Autobuilder builder, bool auto)
5757
var command = new CommandBuilder(builder.Actions);
5858

5959
if (vsTools != null)
60+
{
6061
command.CallBatFile(vsTools.Path);
62+
// `vcvarsall.bat` sets a default Platform environment variable,
63+
// which may not be compatible with the supported platforms of the
64+
// given project/solution. Unsetting it means that the default platform
65+
// of the project/solution is used instead.
66+
command.RunCommand("set Platform=&& type NUL", quoteExe: false);
67+
}
6168

6269
builder.MaybeIndex(command, MsBuild);
6370
command.QuoteArgument(projectOrSolution.FullPath);

0 commit comments

Comments
 (0)