Skip to content

Commit ece10fb

Browse files
authored
Add more examples for MsBuild issue provider (#988)
1 parent e347b28 commit ece10fb

File tree

5 files changed

+89
-5
lines changed

5 files changed

+89
-5
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
title: Examples
3+
description: Examples for using the Cake.Issues.MsBuild addin.
4+
icon: material/test-tube
5+
---
6+
7+
<div class="grid cards" markdown>
8+
9+
- :material-test-tube: [Read binary log file](read-binary-log.md)
10+
- :material-test-tube: [Use custom URL resolver](use-custom-url-resolver.md)
11+
12+
</div>

docs/input/documentation/issue-providers/msbuild/examples.md renamed to docs/input/documentation/issue-providers/msbuild/examples/read-binary-log.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
---
2-
title: Examples
3-
description: Examples for using the Cake.Issues.MsBuild addin.
2+
title: Read MsBuild binary log file
3+
description: Examples for reading a binary logfile using the Cake.Issues.MsBuild addin.
44
icon: material/test-tube
55
---
66

7-
To read issues from MsBuild log files you need to import the MsBuild issue provider needs to be imported:
7+
To read issues from MsBuild log files the MsBuild issue provider needs to be imported:
88

99
=== "Cake .NET Tool"
1010

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
title: Use custom URL resolver for MsBuild issues
3+
description: Examples for using custom URL resolver for MsBuild issues.
4+
icon: material/test-tube
5+
---
6+
7+
!!! note
8+
9+
This example builds on top of the [Read binary log file](read-binary-log.md) example.
10+
11+
The following example shows how URL schema for custom Roslyn analyzers can be defined.
12+
13+
Before reading the issues a custom rule URL resolver can be registered to have all issues starting with `CUS` linking to an internal URL:
14+
15+
=== "Cake .NET Tool"
16+
17+
```csharp title="build.cake"
18+
Task("Read-Issues")
19+
.IsDependentOn("Build-Solution")
20+
.Does(() =>
21+
{
22+
// Define custom URL resolver adding URL for all rules starting with FOO.
23+
MsBuildAddRuleUrlResolver(x =>
24+
x.Category.ToUpperInvariant() == "CUS" ?
25+
new Uri("https://myIntranet/rules/" + x.Rule) :
26+
null);
27+
28+
// Read issues.
29+
var issues =
30+
ReadIssues(
31+
MsBuildIssuesFromFilePath(
32+
logPath,
33+
MsBuildBinaryLogFileFormat),
34+
repoRootPath);
35+
36+
Information("{0} issues are found.", issues.Count());
37+
});
38+
```
39+
40+
=== "Cake Frosting"
41+
42+
```csharp title="Program.cs"
43+
using Cake.Common.Diagnostics;
44+
using Cake.Frosting;
45+
46+
[TaskName("Read-Issues")]
47+
[IsDependentOn(typeof(BuildSolutionTask))]
48+
public sealed class ReadIssuesTask : FrostingTask<BuildContext>
49+
{
50+
public override void Run(BuildContext context)
51+
{
52+
// Define custom URL resolver adding URL for all rules starting with FOO.
53+
context.MsBuildAddRuleUrlResolver(x =>
54+
x.Category.ToUpperInvariant() == "CUS" ?
55+
new Uri("https://myIntranet/rules/" + x.Rule) :
56+
null);
57+
58+
// Read issues.
59+
var issues =
60+
context.ReadIssues(
61+
context.MsBuildIssuesFromFilePath(
62+
context.LogPath,
63+
context.MsBuildBinaryLogFileFormat()),
64+
context.RepoRootPath);
65+
66+
context.Information("{0} issues are found.", issues.Count());
67+
}
68+
}
69+
```

docs/input/documentation/issue-providers/msbuild/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Support for reading warnings reported by MsBuild is implemented in the
99
<div class="grid cards" markdown>
1010

1111
- :material-creation-outline: [Features](features.md)
12-
- :material-test-tube: [Examples](examples.md)
12+
- :material-test-tube: [Examples](examples/index.md)
1313
- :material-api: [API](https://cakebuild.net/extensions/cake-issues-msbuild){target="_blank"}
1414

1515
</div>

docs/mkdocs.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,10 @@ nav:
201201
- MsBuild:
202202
- documentation/issue-providers/msbuild/index.md
203203
- Features: documentation/issue-providers/msbuild/features.md
204-
- Examples: documentation/issue-providers/msbuild/examples.md
204+
- Examples:
205+
- documentation/issue-providers/msbuild/examples/index.md
206+
- Read binary log file: documentation/issue-providers/msbuild/examples/read-binary-log.md
207+
- Use custom URL resolver: documentation/issue-providers/msbuild/examples/use-custom-url-resolver.md
205208
- API: https://cakebuild.net/extensions/cake-issues-msbuild" target="_blank
206209
- Sarif:
207210
- documentation/issue-providers/sarif/index.md

0 commit comments

Comments
 (0)