Skip to content

Commit 9165ec9

Browse files
committed
Report .NET Core & MSBuild failures
1 parent 62b5974 commit 9165ec9

1 file changed

Lines changed: 32 additions & 1 deletion

File tree

csharp/autobuilder/Semmle.Autobuild.CSharp/CSharpAutobuilder.cs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public class CSharpAutobuilder : Autobuilder<CSharpAutobuildOptions>
3333
{
3434
private DotNetRule? dotNetRule;
3535

36+
private MsBuildRule? msBuildRule;
37+
3638
private BuildCommandAutoRule? buildCommandAutoRule;
3739

3840
public CSharpAutobuilder(IBuildActions actions, CSharpAutobuildOptions options) : base(actions, options) { }
@@ -106,13 +108,14 @@ BuildScript IntermediateAttempt(BuildScript s) =>
106108
(attemptExtractorCleanup & BuildScript.Failure);
107109

108110
this.dotNetRule = new DotNetRule();
111+
this.msBuildRule = new MsBuildRule();
109112
this.buildCommandAutoRule = new BuildCommandAutoRule(DotNetRule.WithDotNet);
110113

111114
attempt =
112115
// First try .NET Core
113116
IntermediateAttempt(dotNetRule.Analyse(this, true)) |
114117
// Then MSBuild
115-
(() => IntermediateAttempt(new MsBuildRule().Analyse(this, true))) |
118+
(() => IntermediateAttempt(msBuildRule.Analyse(this, true))) |
116119
// And finally look for a script that might be a build script
117120
(() => this.buildCommandAutoRule.Analyse(this, true) & CheckExtractorRun(true)) |
118121
// All attempts failed: print message
@@ -177,6 +180,34 @@ protected override void AutobuildFailureDiagnostic()
177180

178181
Diagnostic(message);
179182
}
183+
184+
// report any projects that failed to build with .NET Core
185+
if (dotNetRule is not null && dotNetRule.FailedProjectsOrSolutions.Any())
186+
{
187+
var message = MakeDiagnostic("dotnet-build-failure", "Some projects or solutions failed to build using .NET Core");
188+
message.MarkdownMessage =
189+
"CodeQL was unable to build the following projects using .NET Core:\n" +
190+
string.Join('\n', dotNetRule.FailedProjectsOrSolutions.Select(p => $"- `{p.FullPath}`")) +
191+
"\nYou can manually specify a suitable build command for your project to exclude these projects " +
192+
"or to ensure that they can be built successfully.";
193+
message.Severity = DiagnosticMessage.TspSeverity.Error;
194+
195+
Diagnostic(message);
196+
}
197+
198+
// report any projects that failed to build with MSBuild
199+
if (msBuildRule is not null && msBuildRule.FailedProjectsOrSolutions.Any())
200+
{
201+
var message = MakeDiagnostic("msbuild-build-failure", "Some projects or solutions failed to build using MSBuild");
202+
message.MarkdownMessage =
203+
"CodeQL was unable to build the following projects using MSBuild:\n" +
204+
string.Join('\n', msBuildRule.FailedProjectsOrSolutions.Select(p => $"- `{p.FullPath}`")) +
205+
"\nYou can manually specify a suitable build command for your project to exclude these projects " +
206+
"or to ensure that they can be built successfully.";;
207+
message.Severity = DiagnosticMessage.TspSeverity.Error;
208+
209+
Diagnostic(message);
210+
}
180211
}
181212

182213
/// <summary>

0 commit comments

Comments
 (0)