Skip to content

Commit

Permalink
Correct success for /preprocess /targets builds (dotnet#8908)
Browse files Browse the repository at this point in the history
* Correct success

This is not yet a problem but only because neither /preprocess nor /targets are supported for solution files.

The root of the problem is if someone chooses to specify both /preprocess and /targets. If /preprocess fails but /targets succeeds, it currently will erroneously display success. This fixes that.

As I said, that scenario doesn't currently exist but only because /targets cannot succeed unless /preprocess succeeded, but that is not guaranteed going forward. Notably, if /preprocess is extended to support solution files before /targets is, this will become an issue.

* Make isTargets not run if !success

---------

Co-authored-by: Forgind <Forgind@users.noreply.github.com>
  • Loading branch information
Forgind and Forgind authored Oct 10, 2023
1 parent db511c6 commit 0fb77f8
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/MSBuild/XMake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1255,7 +1255,7 @@ internal static bool BuildProject(
InitializationException.Throw(ResourceUtilities.FormatResourceStringStripCodeAndKeyword("ProjectUpgradeNeededToVcxProj", projectFile), null);
}

bool success = false;
bool success = true;

ProjectCollection projectCollection = null;
bool onlyLogCriticalEvents = false;
Expand Down Expand Up @@ -1371,11 +1371,12 @@ internal static bool BuildProject(

if (isPreprocess)
{
success = false;

// TODO: Support /preprocess for solution files. https://github.com/dotnet/msbuild/issues/7697
if (isSolution)
{
Console.WriteLine(ResourceUtilities.GetResourceString("UnsupportedSwitchForSolutionFiles"), CommandLineSwitches.ParameterizedSwitch.Preprocess);
success = false;
}
else
{
Expand All @@ -1389,13 +1390,14 @@ internal static bool BuildProject(
}
}

if (isTargets)
if (isTargets && success)
{
success = false;

// TODO: Support /targets for solution files. https://github.com/dotnet/msbuild/issues/7697
if (isSolution)
{
Console.WriteLine(ResourceUtilities.GetResourceString("UnsupportedSwitchForSolutionFiles"), CommandLineSwitches.ParameterizedSwitch.Targets);
success = false;
}
else
{
Expand All @@ -1405,6 +1407,7 @@ internal static bool BuildProject(

if (!isPreprocess && !isTargets)
{
success = false;
BuildParameters parameters = new BuildParameters(projectCollection);

// By default we log synchronously to the console for compatibility with previous versions,
Expand Down

0 comments on commit 0fb77f8

Please sign in to comment.