19

I've set various C# Code Style rules to generate errors, and while violations show up as errors in the IDE (both in the error list and the text editor), actual builds still succeed.

Can anyone confirm this? I've tested on VisualStudio/15.0.0+26228.9 under both the Community (at home) and Enterprise (at work) editions. And I can't get any build to break due to a code style violation.

I've even tried to use .editorconfig, and builds still go through...

Nate Barbettini
  • 51,256
  • 26
  • 134
  • 147
Xorcist
  • 3,129
  • 3
  • 21
  • 47
  • 1
    I'm also seeing this in VS 2017, will try Update 1 and see if that resolves this – Adam Knights Apr 26 '17 at 14:38
  • Still the same in Update 2. A recent comment by an MS dev suggests they are hoping to deliver it in Update 3: https://developercommunity.visualstudio.com/content/problem/34304/code-style-does-not-affect-build.html. – Ohad Schneider Jun 07 '17 at 22:24
  • as of August 2017 (update 15.3.0) this issue has still not been addressed. – Xorcist Aug 14 '17 at 19:28
  • as of October 2017 (update 15.4.0) this issue has still not been addressed. – Xorcist Oct 13 '17 at 16:03
  • as of December 2017 (update 15.5.0) this issue has still not been addressed. – Xorcist Dec 04 '17 at 21:09
  • as of March 2018 (update 15.6.0) this issue has still not been addressed. – Xorcist Mar 05 '18 at 20:33
  • as of May 2018 (update 15.7.0) this issue has still not been addressed... being a year later at this point, I'm getting the feeling not going to get addressed... talk about false advertising. – Xorcist May 07 '18 at 18:36
  • as of August 2018 (update 15.8.0) this issue has still not been addressed. – Xorcist Aug 15 '18 at 15:45
  • 1
    as of November 2018 (update 15.9.0) this issue has still not been addressed. – Xorcist Nov 26 '18 at 22:55
  • 2
    April 2019, Visual Studio 2019: It is still an open issue. – Ankit Vijay Apr 04 '19 at 23:35
  • as of June 2021, what are the possibilities that this will be at all present and working in Visual Studio 2022? (Since clearly is never worked in VS2017 or VS2019) We're going on four years and three major Visual Studio versions Microsoft... – Xorcist Jun 25 '21 at 23:01
  • Stardate 47634.44... we've encountered a new version of Visual Studio, designation 2022 (version 17.0.0). It appears that Code Style severities still have no affect on build prevention, setting levels to "Error" are futile. Remodulating expectations to nil. Captain, may I suggest a surge of concentrated tachyon particles is in order to dilate the timeline? – Xorcist Nov 09 '21 at 19:15

2 Answers2

14

Update:

This has not been implemented yet. This is now tracked as a project on GitHub at: https://github.com/dotnet/roslyn/projects/18 - check there for updates.

Original response:

I've opened a VS question on this at: https://developercommunity.visualstudio.com/content/problem/48804/editorconfig-with-rules-set-to-error-produces-erro.html that will hopefully provide some answers on why errors coming from the new .editorconfig support in VS2017 do not fail builds.

Adam Knights
  • 2,141
  • 1
  • 25
  • 48
  • 1
    Already [reported here](https://developercommunity.visualstudio.com/content/problem/34304/code-style-does-not-affect-build.html), "under investigation" is happy-speak for "we've got bigger problems and haven't looked at it yet". Vote it up, click Follow to get status update notifications. – Hans Passant Apr 26 '17 at 15:41
  • @HansPassant it's actually not clear how to upvote it. It's closed as a duplicate (so voting is disabled) but I couldn't find any link to the original one to vote on. Same here: https://developercommunity.visualstudio.com/content/problem/34304/code-style-does-not-affect-build.html. – Ohad Schneider Jun 08 '17 at 08:32
  • @Ohad - it is just a bad link, remove the trailing dot. It points to work-in-progress, looks like they are busy adding the necessary infrastructure to make this work. Microsoft's new focus on agile is pretty rough on its customers. Ship the feature first, make it work later is agile. – Hans Passant Jun 08 '17 at 09:36
  • @HansPassant haha very agile! BTW I know about the broken link, I meant I don't see anywhere I can actually upvote... – Ohad Schneider Jun 08 '17 at 11:31
-3

You're looking for the Treat warnings as errors option. You can find it by right-clicking on the project and choosing Properties -> Build:

Treat warnings as errors option

Switch it from None to All to make all code style warnings (and any other warnings) break the build.

If you're working on a .NET Core project, you can edit the csproj file directly and add the TreatWarningsAsErrors property:

<PropertyGroup>
  <!-- ... other stuff -->

  <TreatWarningsAsErrors>true</TreatWarningsAsErrors>
</PropertyGroup>
Nate Barbettini
  • 51,256
  • 26
  • 134
  • 147
  • 2
    Unfortunately this is not the solution. I tried it, but it did not work. Furthermore, these are not warnings, these are outright errors as specified by the advanced Code Style options in Visual Studio 2017. I switched the errors to warnings to double check the "Treat warnings as error" option, but it didn't change anything. – Xorcist Mar 26 '17 at 01:42
  • 3
    In the following Visual Studio 2017 Launch Video [link](https://channel9.msdn.com/Events/Visual-Studio/Visual-Studio-2017-Launch/T102) from 3:34 to 5:37 what I am trying to achieve is covered, however they never actually show a failing build, they only say it will fail... but it clearly does not. – Xorcist Mar 26 '17 at 01:53