dotnet / dotnet/msbuild

CanonicalError.cs won't show error code

Open
#4,567 1 comment 0 reactions 0 assignees View on GitHub
triaged
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 13h
Merged PRs (30d)
133

Description

Hi All,

I'm trying to use `CanonicalError.cs` to output custom warning messages to the Error List window for a build tool I'm creating. The function is great, I can see my warnings in the window and double click to be taken right to them, the only thing that isn't showing is the error codes I have for my warnings.

Here's a [repro repository](https://github.com/murray-coueslant/MSBuildErrorCodeRepro) that exhibits the same behaviour, it shows a mimicked version of the object I use to build my messages as well as the exact code used to build them. You might need to change the path in `AppUsingBuildTool.csproj` in order to make it work, I wasn't too sure how to convert the path into a relative one so I've left it as an absolute as it is on my machine.

For a very brief period of time the warning messages did show the codes, and curiously every warning also showed its column to be 1 whilst the error codes were showing. Since then the codes and columns have not appeared again.

This is how I am calling the tool in my .csproj file:

```xml



```

I know that the format of the messages have to be very specific, however I have checked the Regexes in `CanonicalError.cs` against my output using [Regex Storm](regexstorm.net), and they seem to match fine. I can even see the code being shown in the `CODE` named group stemming from the following line in `CanonicalError.cs` when I test the pattern against the messages I create,

```C#
// Match anything starting with a space that's not a colon/space, followed by a colon.
// Error code is optional in which case "error"/"warning" can be followed immediately by a colon.
+ @"( \s*(?[^: ]*))?\s*:"
```

Here is how I construct my error message, using data from another class inside the tool itself

```C#
Console.Out.WriteLine($"{file}({ruleTrigger.LineNumber}, {ruleTrigger.ColumnNumber}): test warning {ruleCode}: {ruleTrigger.RuleDescription} {ruleTrigger.RuleNotes}");
```

and here's what the build output in Visual Studio shows when the tool is run as an after build event in another project,

```output
1>C:\Users\murray.coueslant\Documents\dev\BuildToolTest\BuildToolTest\docs\docs\07 Procedures\05 IT\04 Firewall.md(24, 1) : test warning MD040: Code fence has no language specified. Code fence on line 24 has no language specified. Correct by specifying a language right after the first set of delimiters.
```

I'm using Visual Studio 2017, and have MSBuild version 15.1.0.0.

If there is a better place that I should have asked this question, please let me know!

Thanks.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with CanonicalError.cs and the MSBuildErrorCodeRepro repository, then run the reported after-build command using the sample output format. Check how the CODE group is parsed and propagated to Visual Studio's Error List. Done means the warning displays its MD040-style error code and retains the reported location.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
build-system
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.