5

Kinda stumped on this one. I'm using a library from GitHub and it's throwing tons of warnings, so I went into the project's build settings, chose 'All Configurations' and chose 0 for the warning level under 'Errors and Warnings'. This added the following to the project file:

<WarningLevel>0</WarningLevel>

Rebuilding and all the warnings went away.

Then on the next build, they came right back! Huh?

Went back into the UI and saw it was set back to 5! I checked the project file and it was still at 0 as expected.

To test, I changed the level 2 in the UI, and as expected, the project file updated to this instantly:

<WarningLevel>2</WarningLevel>

But then, a few seconds later, the UI again snapped back to 5! WTF?!?!

I looked around to see if there was any global overrides but didn't find anything, although I'm not really sure what I'm looking for.

Anyone know what's going on? It's really @$#!@ annoying!

Here's my fork of the project if anyone else wants to take a look:

https://github.com/MarqueIV/WpfExtendedToolkit
(Forked from here: https://github.com/dotnetprojects/WpfExtendedToolkit)

Update

I checked out the project on a completely separate Win10 install where I also installed VS 2019 Community for the first time, and the same thing happened... it keeps 'resetting' the warning level, so it's something somewhere in the project itself I would think.

Mark A. Donohoe
  • 28,442
  • 25
  • 137
  • 286
  • Maybe it builds a buildtask that runs on every build and set that warninglevel. Any unexpected imports in that project file? – rene Dec 05 '20 at 08:28
  • Not that I can tell. I added a link to the project if you wanna take a look. It's a popular one that I forked. – Mark A. Donohoe Dec 05 '20 at 08:34
  • Nothing in those projects that jump out at me. Strange. – rene Dec 05 '20 at 08:49
  • First eliminate any extensions - have you confirmed the same happens with no extensions enabled? – Damien_The_Unbeliever Dec 05 '20 at 09:20
  • To disable the warnings for a project, you could add this to your project `#pragma warning disable`. Optionally specify the warning numbers to be ignored. ( [docs](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/preprocessor-directives/preprocessor-pragma-warning) ) – Luuk Dec 05 '20 at 10:14
  • 1
    https://github.com/dotnet/sdk/issues/14490 – Hans Passant Dec 06 '20 at 01:08
  • Awesome find! Post that in an answer and I'll mark it as such. – Mark A. Donohoe Dec 06 '20 at 01:10
  • 1
    "[Automatically find latent bugs in your code with .NET 5](https://devblogs.microsoft.com/dotnet/automatically-find-latent-bugs-in-your-code-with-net-5/)" says that you should set `AnalysisLevel` to 0 to disable all warnings. – Luuk Dec 06 '20 at 10:17
  • 3
    I don't want to support such an answer, the agile hack they used is too fugly to be treated in a neutral tone. Just upvote the comment so users can see it and the question avoids the roomba. – Hans Passant Dec 06 '20 at 13:55
  • "...avoids the Roomba!" Thanks for that laugh today. :) Done as you wished. – Mark A. Donohoe Dec 06 '20 at 21:21

1 Answers1

3

Ok, this isn't an 'answer' per se, but here's a workaround, at least for now to shut up the warnings.

In addition to WarningLevel, you have to also set the AnalysisLevel and RunAnalyzersDuringBuild by adding the following to your project.

<WarningLevel>0</WarningLevel>
<AnalysisLevel>none</AnalysisLevel>
<RunAnalyzersDuringBuild>false</RunAnalyzersDuringBuild>

That stops the warnings.

Still, there shouldn't be a case where something overrides WarningLevel which is why I'm posting this, but not marking it as the accepted answer. It isn't. It's a temporary, 'blunt-hammer' fix until they restore the behavior to the pre-.NET 5.0 way of it working. Let's hope that was an oversight and not an intentional change.

Mark A. Donohoe
  • 28,442
  • 25
  • 137
  • 286
  • As a reference, a link to the blog from microsoft: [Automatically find latent bugs in your code with .NET 5](https://devblogs.microsoft.com/dotnet/automatically-find-latent-bugs-in-your-code-with-net-5/) – Luuk Dec 07 '20 at 07:18