Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions src/Build.UnitTests/Utilities_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,9 @@ public void CommentsInPreprocessing()

env.SetEnvironmentVariable("MSBUILDLOADALLFILESASWRITEABLE", "1");

#if FEATURE_GET_COMMANDLINE
MSBuildApp.Execute(@"c:\bin\msbuild.exe """ + inputFile.Path +
(NativeMethodsShared.IsUnixLike ? @""" -pp:""" : @""" /pp:""") + outputFile.Path + @"""")
.ShouldBe(MSBuildApp.ExitType.Success);
#else
Assert.Equal(
MSBuildApp.ExitType.Success,
MSBuildApp.Execute(
new[] { @"c:\bin\msbuild.exe", '"' + inputFile.Path + '"',
'"' + (NativeMethodsShared.IsUnixLike ? "-pp:" : "/pp:") + outputFile.Path + '"'}));
#endif
MSBuildApp.Execute([ @"c:\bin\msbuild.exe", '"' + inputFile.Path + '"', '"' + (NativeMethodsShared.IsUnixLike ? "-pp:" : "/pp:") + outputFile.Path + '"']));

bool foundDoNotModify = false;
foreach (string line in File.ReadLines(outputFile.Path))
Expand Down
19 changes: 2 additions & 17 deletions src/Build/BackEnd/Client/MSBuildClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,7 @@ public sealed class MSBuildClient
/// The command line to process.
/// The first argument on the command line is assumed to be the name/path of the executable, and is ignored.
/// </summary>
#if FEATURE_GET_COMMANDLINE
private readonly string _commandLine;
#else
private readonly string[] _commandLine;
#endif

/// <summary>
/// The MSBuild client execution result.
Expand Down Expand Up @@ -112,13 +108,7 @@ public sealed class MSBuildClient
/// on the command line is assumed to be the name/path of the executable, and is ignored</param>
/// <param name="msbuildLocation"> Full path to current MSBuild.exe if executable is MSBuild.exe,
/// or to version of MSBuild.dll found to be associated with the current process.</param>
public MSBuildClient(
#if FEATURE_GET_COMMANDLINE
string commandLine,
#else
string[] commandLine,
#endif
string msbuildLocation)
public MSBuildClient(string[] commandLine, string msbuildLocation)
{
_serverEnvironmentVariables = new();
_exitResult = new();
Expand Down Expand Up @@ -162,12 +152,7 @@ private void CreateNodePipeStream()
public MSBuildClientExitResult Execute(CancellationToken cancellationToken)
{
// Command line in one string used only in human readable content.
string descriptiveCommandLine =
#if FEATURE_GET_COMMANDLINE
_commandLine;
#else
string.Join(" ", _commandLine);
#endif
string descriptiveCommandLine = string.Join(" ", _commandLine);

CommunicationsUtilities.Trace("Executing build with command line '{0}'", descriptiveCommandLine);

Expand Down
7 changes: 1 addition & 6 deletions src/Build/BackEnd/Node/OutOfProcServerNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ public sealed class OutOfProcServerNode : INode, INodePacketFactory, INodePacket
/// <summary>
/// A callback used to execute command line build.
/// </summary>
public delegate (int exitCode, string exitType) BuildCallback(
#if FEATURE_GET_COMMANDLINE
string commandLine);
#else
string[] commandLine);
#endif
public delegate (int exitCode, string exitType) BuildCallback(string[] commandLine);

private readonly BuildCallback _buildFunction;

Expand Down
12 changes: 0 additions & 12 deletions src/Build/BackEnd/Node/ServerNodeBuildCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ namespace Microsoft.Build.BackEnd
/// </summary>
internal sealed class ServerNodeBuildCommand : INodePacket
{
#if FEATURE_GET_COMMANDLINE
private string _commandLine = default!;
#else
private string[] _commandLine = default!;
#endif
private string _startupDirectory = default!;
private Dictionary<string, string> _buildProcessEnvironment = default!;
private CultureInfo _culture = default!;
Expand All @@ -34,11 +30,7 @@ internal sealed class ServerNodeBuildCommand : INodePacket
/// <summary>
/// Command line including arguments
/// </summary>
#if FEATURE_GET_COMMANDLINE
public string CommandLine => _commandLine;
#else
public string[] CommandLine => _commandLine;
#endif

/// <summary>
/// The startup directory
Expand Down Expand Up @@ -79,11 +71,7 @@ private ServerNodeBuildCommand()
}

public ServerNodeBuildCommand(
#if FEATURE_GET_COMMANDLINE
string commandLine,
#else
string[] commandLine,
#endif
string startupDirectory,
Dictionary<string, string> buildProcessEnvironment,
CultureInfo culture, CultureInfo uiCulture,
Expand Down
47 changes: 46 additions & 1 deletion src/Build/CompatibilitySuppressions.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- https://learn.microsoft.com/dotnet/fundamentals/package-validation/diagnostic-ids -->
<Suppressions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" />
<Suppressions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<!-- MSBuildClient is in experimental namespace and not used outside the MSBuild -->
<!-- OutOfProcServerNode.BuildCallback is in experimental namespace and not used outside the MSBuild -->
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Microsoft.Build.Experimental.MSBuildClient.#ctor(System.String,System.String)</Target>
<Left>lib/net472/Microsoft.Build.dll</Left>
<Right>lib/net472/Microsoft.Build.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Microsoft.Build.Experimental.OutOfProcServerNode.BuildCallback.BeginInvoke(System.String,System.AsyncCallback,System.Object)</Target>
<Left>lib/net472/Microsoft.Build.dll</Left>
<Right>lib/net472/Microsoft.Build.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Microsoft.Build.Experimental.OutOfProcServerNode.BuildCallback.Invoke(System.String)</Target>
<Left>lib/net472/Microsoft.Build.dll</Left>
<Right>lib/net472/Microsoft.Build.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Microsoft.Build.Experimental.MSBuildClient.#ctor(System.String,System.String)</Target>
<Left>ref/net472/Microsoft.Build.dll</Left>
<Right>ref/net472/Microsoft.Build.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Microsoft.Build.Experimental.OutOfProcServerNode.BuildCallback.BeginInvoke(System.String,System.AsyncCallback,System.Object)</Target>
<Left>ref/net472/Microsoft.Build.dll</Left>
<Right>ref/net472/Microsoft.Build.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
<Suppression>
<DiagnosticId>CP0002</DiagnosticId>
<Target>M:Microsoft.Build.Experimental.OutOfProcServerNode.BuildCallback.Invoke(System.String)</Target>
<Left>ref/net472/Microsoft.Build.dll</Left>
<Right>ref/net472/Microsoft.Build.dll</Right>
<IsBaselineSuppression>true</IsBaselineSuppression>
</Suppression>
</Suppressions>
1 change: 0 additions & 1 deletion src/Directory.BeforeCommon.targets
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
<DefineConstants>$(DefineConstants);FEATURE_ENVIRONMENT_SYSTEMDIRECTORY</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_FILE_TRACKER</DefineConstants>
<DefineConstants Condition="'$(MachineIndependentBuild)' != 'true'">$(DefineConstants);FEATURE_GAC</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_GET_COMMANDLINE</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_HANDLEPROCESSCORRUPTEDSTATEEXCEPTIONS</DefineConstants>
<DefineConstants>$(DefineConstants);FEATURE_HTTP_LISTENER</DefineConstants>
<DefineConstants Condition="'$(MachineIndependentBuild)' != 'true'">$(DefineConstants);FEATURE_INSTALLED_MSBUILD</DefineConstants>
Expand Down
6 changes: 1 addition & 5 deletions src/MSBuild.UnitTests/CommandLineSwitches_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1548,11 +1548,7 @@ public void ProcessInvalidTargetSwitch()
using TestEnvironment testEnvironment = TestEnvironment.Create();
string project = testEnvironment.CreateTestProjectWithFiles("project.proj", projectContent).ProjectFile;

#if FEATURE_GET_COMMANDLINE
MSBuildApp.Execute(@"msbuild.exe " + project + " /t:foo.bar").ShouldBe(MSBuildApp.ExitType.SwitchError);
#else
MSBuildApp.Execute(new[] { @"msbuild.exe", project, "/t:foo.bar" }).ShouldBe(MSBuildApp.ExitType.SwitchError);
#endif
MSBuildApp.Execute([@"msbuild.exe", project, "/t:foo.bar"]).ShouldBe(MSBuildApp.ExitType.SwitchError);
}

/// <summary>
Expand Down
10 changes: 5 additions & 5 deletions src/MSBuild.UnitTests/ProjectSchemaValidationHandler_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void VerifyInvalidProjectSchema()
");
string quotedProjectFilename = "\"" + projectFilename + "\"";

Assert.Equal(MSBuildApp.ExitType.InitializationError, MSBuildApp.Execute(@"c:\foo\msbuild.exe " + quotedProjectFilename + " /validate:\"" + msbuildTempXsdFilenames[0] + "\""));
Assert.Equal(MSBuildApp.ExitType.InitializationError, MSBuildApp.Execute([@"c:\foo\msbuild.exe", quotedProjectFilename, $"/validate:\"{msbuildTempXsdFilenames[0]}\""]));
}
finally
{
Expand Down Expand Up @@ -95,7 +95,7 @@ public void VerifyInvalidSchemaItself1()
");
string quotedProjectFile = "\"" + projectFilename + "\"";

Assert.Equal(MSBuildApp.ExitType.InitializationError, MSBuildApp.Execute(@"c:\foo\msbuild.exe " + quotedProjectFile + " /validate:\"" + invalidSchemaFile + "\""));
Assert.Equal(MSBuildApp.ExitType.InitializationError, MSBuildApp.Execute([@"c:\foo\msbuild.exe", quotedProjectFile, $"/validate:\"{invalidSchemaFile}\""]));
}
finally
{
Expand Down Expand Up @@ -155,7 +155,7 @@ public void VerifyInvalidSchemaItself2()

string quotedProjectFile = "\"" + projectFilename + "\"";

Assert.Equal(MSBuildApp.ExitType.InitializationError, MSBuildApp.Execute(@"c:\foo\msbuild.exe " + quotedProjectFile + " /validate:\"" + invalidSchemaFile + "\""));
Assert.Equal(MSBuildApp.ExitType.InitializationError, MSBuildApp.Execute([@"c:\foo\msbuild.exe", quotedProjectFile, $"/validate:\"{invalidSchemaFile}\""]));
}
finally
{
Expand Down Expand Up @@ -203,7 +203,7 @@ public void VerifyValidProjectSchema()
msbuildTempXsdFilenames = PrepareSchemaFiles();
string quotedProjectFile = "\"" + projectFilename + "\"";

Assert.Equal(MSBuildApp.ExitType.Success, MSBuildApp.Execute(@"c:\foo\msbuild.exe " + quotedProjectFile + " /validate:\"" + msbuildTempXsdFilenames[0] + "\""));
Assert.Equal(MSBuildApp.ExitType.Success, MSBuildApp.Execute([@"c:\foo\msbuild.exe", quotedProjectFile, $"/validate:\"{msbuildTempXsdFilenames[0]}\""]));

// ProjectSchemaValidationHandler.VerifyProjectSchema
// (
Expand Down Expand Up @@ -256,7 +256,7 @@ public void VerifyInvalidImportNotCaughtBySchema()
msbuildTempXsdFilenames = PrepareSchemaFiles();
string quotedProjectFile = "\"" + projectFilename + "\"";

Assert.Equal(MSBuildApp.ExitType.Success, MSBuildApp.Execute(@"c:\foo\msbuild.exe " + quotedProjectFile + " /validate:\"" + msbuildTempXsdFilenames[0] + "\""));
Assert.Equal(MSBuildApp.ExitType.Success, MSBuildApp.Execute([@"c:\foo\msbuild.exe", quotedProjectFile, "/validate:\"{msbuildTempXsdFilenames[0]}\""]));

// ProjectSchemaValidationHandler.VerifyProjectSchema
// (
Expand Down
49 changes: 11 additions & 38 deletions src/MSBuild.UnitTests/XMake_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -562,12 +562,7 @@ public void GetLengthOfSwitchIndicatorTest()
[InlineData(@"/h")]
public void Help(string indicator)
{
MSBuildApp.Execute(
#if FEATURE_GET_COMMANDLINE
@$"c:\bin\msbuild.exe {indicator} ")
#else
new[] { @"c:\bin\msbuild.exe", indicator })
#endif
MSBuildApp.Execute([@"c:\bin\msbuild.exe", indicator])
.ShouldBe(MSBuildApp.ExitType.Success);
}

Expand Down Expand Up @@ -660,19 +655,11 @@ public void VersionSwitchDisableChangeWave()
public void ErrorCommandLine()
{
string oldValueForMSBuildLoadMicrosoftTargetsReadOnly = Environment.GetEnvironmentVariable("MSBuildLoadMicrosoftTargetsReadOnly");
#if FEATURE_GET_COMMANDLINE
MSBuildApp.Execute(@"c:\bin\msbuild.exe -junk").ShouldBe(MSBuildApp.ExitType.SwitchError);

MSBuildApp.Execute(@"msbuild.exe -t").ShouldBe(MSBuildApp.ExitType.SwitchError);

MSBuildApp.Execute(@"msbuild.exe @bogus.rsp").ShouldBe(MSBuildApp.ExitType.InitializationError);
#else
MSBuildApp.Execute(new[] { @"c:\bin\msbuild.exe", "-junk" }).ShouldBe(MSBuildApp.ExitType.SwitchError);

MSBuildApp.Execute(new[] { @"msbuild.exe", "-t" }).ShouldBe(MSBuildApp.ExitType.SwitchError);
MSBuildApp.Execute([@"c:\bin\msbuild.exe", "-junk"]).ShouldBe(MSBuildApp.ExitType.SwitchError);
MSBuildApp.Execute([@"msbuild.exe", "-t"]).ShouldBe(MSBuildApp.ExitType.SwitchError);
MSBuildApp.Execute([@"msbuild.exe", "@bogus.rsp"]).ShouldBe(MSBuildApp.ExitType.InitializationError);

MSBuildApp.Execute(new[] { @"msbuild.exe", "@bogus.rsp" }).ShouldBe(MSBuildApp.ExitType.InitializationError);
#endif
Environment.SetEnvironmentVariable("MSBuildLoadMicrosoftTargetsReadOnly", oldValueForMSBuildLoadMicrosoftTargetsReadOnly);
}

Expand Down Expand Up @@ -1153,11 +1140,7 @@ public void TestEnvironmentTest()
sw.WriteLine(projectString);
}
// Should pass
#if FEATURE_GET_COMMANDLINE
MSBuildApp.Execute(@"c:\bin\msbuild.exe " + quotedProjectFileName).ShouldBe(MSBuildApp.ExitType.Success);
#else
MSBuildApp.Execute(new[] { @"c:\bin\msbuild.exe", quotedProjectFileName }).ShouldBe(MSBuildApp.ExitType.Success);
#endif
MSBuildApp.Execute([@"c:\bin\msbuild.exe", quotedProjectFileName]).ShouldBe(MSBuildApp.ExitType.Success);
}
finally
{
Expand Down Expand Up @@ -1190,21 +1173,15 @@ public void MSBuildEngineLogger()
{
sw.WriteLine(projectString);
}
#if FEATURE_GET_COMMANDLINE
// Should pass
MSBuildApp.Execute(@$"c:\bin\msbuild.exe /logger:FileLogger,""Microsoft.Build, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"";""LogFile={logFile}"" /verbosity:detailed " + quotedProjectFileName).ShouldBe(MSBuildApp.ExitType.Success);

#else
// Should pass
MSBuildApp.Execute(
new[]
{
MSBuildApp
.Execute([
NativeMethodsShared.IsWindows ? @"c:\bin\msbuild.exe" : "/msbuild.exe",
@$"/logger:FileLogger,""Microsoft.Build, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"";""LogFile={logFile}""",
"/verbosity:detailed",
quotedProjectFileName
}).ShouldBe(MSBuildApp.ExitType.Success);
#endif
quotedProjectFileName])
.ShouldBe(MSBuildApp.ExitType.Success);

File.Exists(logFile).ShouldBeTrue();

var logFileContents = File.ReadAllText(logFile);
Expand Down Expand Up @@ -2946,11 +2923,7 @@ public void ThrowsWhenMaxCpuCountTooLargeForMultiThreadedAndForceAllTasksOutOfPr
testEnvironment.SetEnvironmentVariable("MSBUILDFORCEALLTASKSOUTOFPROC", "1");
string project = testEnvironment.CreateTestProjectWithFiles("project.proj", projectContent).ProjectFile;

#if FEATURE_GET_COMMANDLINE
MSBuildApp.Execute(@"c:\bin\msbuild.exe " + project + " / m:257 /mt").ShouldBe(MSBuildApp.ExitType.SwitchError);
#else
MSBuildApp.Execute(new[] { @"c:\bin\msbuild.exe", project, "/m:257 /mt" }).ShouldBe(MSBuildApp.ExitType.SwitchError);
#endif
MSBuildApp.Execute([@"c:\bin\msbuild.exe", project, "/m:257 /mt"]).ShouldBe(MSBuildApp.ExitType.SwitchError);
}

private string CopyMSBuild()
Expand Down
25 changes: 6 additions & 19 deletions src/MSBuild/MSBuildClientApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,43 +34,30 @@ internal static class MSBuildClientApp
/// <remarks>
/// The locations of msbuild exe/dll and dotnet.exe would be automatically detected if called from dotnet or msbuild cli. Calling this function from other executables might not work.
/// </remarks>
public static MSBuildApp.ExitType Execute(
#if FEATURE_GET_COMMANDLINE
string commandLine,
#else
string[] commandLine,
#endif
CancellationToken cancellationToken)
public static MSBuildApp.ExitType Execute(string[] commandLineArgs, CancellationToken cancellationToken)
{
string msbuildLocation = BuildEnvironmentHelper.Instance.CurrentMSBuildExePath;

return Execute(
commandLine,
commandLineArgs,
msbuildLocation,
cancellationToken);
}

/// <summary>
/// This is the entry point for the MSBuild client.
/// </summary>
/// <param name="commandLine">The command line to process. The first argument
/// <param name="commandLineArgs">The command line to process. The first argument
/// on the command line is assumed to be the name/path of the executable, and
/// is ignored.</param>
/// <param name="msbuildLocation"> Full path to current MSBuild.exe if executable is MSBuild.exe,
/// or to version of MSBuild.dll found to be associated with the current process.</param>
/// <param name="cancellationToken">Cancellation token.</param>
/// <returns>A value of type <see cref="MSBuildApp.ExitType"/> that indicates whether the build succeeded,
/// or the manner in which it failed.</returns>
public static MSBuildApp.ExitType Execute(
#if FEATURE_GET_COMMANDLINE
string commandLine,
#else
string[] commandLine,
#endif
string msbuildLocation,
CancellationToken cancellationToken)
public static MSBuildApp.ExitType Execute(string[] commandLineArgs, string msbuildLocation, CancellationToken cancellationToken)
{
MSBuildClient msbuildClient = new MSBuildClient(commandLine, msbuildLocation);
MSBuildClient msbuildClient = new MSBuildClient(commandLineArgs, msbuildLocation);
MSBuildClientExitResult exitResult = msbuildClient.Execute(cancellationToken);

if (exitResult.MSBuildClientExitType == MSBuildClientExitType.ServerBusy ||
Expand All @@ -84,7 +71,7 @@ public static MSBuildApp.ExitType Execute(
}

// Server is busy, fallback to old behavior.
return MSBuildApp.Execute(commandLine);
return MSBuildApp.Execute(commandLineArgs);
}

if (exitResult.MSBuildClientExitType == MSBuildClientExitType.Success &&
Expand Down
Loading
Loading