Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed /restore and /graph conjunction error on exit code #9461

Merged
merged 9 commits into from
Dec 8, 2023
30 changes: 30 additions & 0 deletions src/MSBuild.UnitTests/XMake_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -697,6 +697,36 @@ public void ExecuteAppWithGetPropertyItemAndTargetResult(
results.ShouldNotContain(ResourceUtilities.GetResourceString("BuildFailedWithPropertiesItemsOrTargetResultsRequested"));
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public void BuildFailsWithCompileErrorAndRestore(bool isGraphBuild)
{
using TestEnvironment env = TestEnvironment.Create();
TransientTestFile project = env.CreateFile("testProject.csproj", @"
<Project>
<ItemGroup>
<CSFile Include=""Program.cs""/>
</ItemGroup>

<Target Name=""Build"">
<Csc Sources=""@(CSFile)"" />
</Target>
</Project>
");
TransientTestFile wrongSyntaxFile = env.CreateFile("Program.cs", @"
Console.WriteLine(""Hello, World!"")
A Line here for this to not compile right");

string graph = isGraphBuild ? "--graph" : "";
string result = RunnerUtilities.ExecMSBuild($" {project.Path} /restore {graph}", out bool success);

success.ShouldBeFalse();
result.ShouldContain("Program.cs(2,47): error CS1002: ; expected");
result.ShouldContain("Program.cs(3,20): error CS1003: Syntax error, ','");
result.ShouldContain("Program.cs(3,54): error CS1002: ; expected");
}

/// <summary>
/// Regression test for bug where the MSBuild.exe command-line app
/// would sometimes set the UI culture to just "en" which is considered a "neutral" UI
Expand Down
15 changes: 6 additions & 9 deletions src/MSBuild/XMake.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1544,6 +1544,10 @@ internal static bool BuildProject(
{
return false;
}
else
{
success = result.OverallResult == BuildResultCode.Success;
}
}

if (!restoreOnly)
Expand All @@ -1568,21 +1572,14 @@ internal static bool BuildProject(
entryValue.Equals(propertyKvp.Value)))
.Value;
}
else
{
success = graphResult.OverallResult == BuildResultCode.Success;
}
success = graphResult.OverallResult == BuildResultCode.Success;
}
else
{
result = ExecuteBuild(buildManager, buildRequest);
success = result.OverallResult == BuildResultCode.Success;
}
}

if (result != null && result.Exception == null)
{
success = result.OverallResult == BuildResultCode.Success;
}
}
finally
{
Expand Down