Technical debt is a natural part of any project. Much like actual debt some is healthy to keep things going but you want to make sure you keep a close eye on your debt and you understand exactly what you’re taking on. My team uses SonarQube for helping to track and measure our debt. You can learn more about SonarQube in Samir Behara’s excellent post! However, we can manage a big source of growing debt with a simple project flag!

Most projects over time accumulate a large number of warnings. They aren’t really addressed because they don’t fail the build and they may not cause any perceived problems in your application but they can be sitting landmines. Many are just waiting to bite you during a framework upgrade or they may be trying to help you and show you a better way to implement a piece of code or remind you to remove some unused code.

Warnings box

One way we can address this is to turn on “Treat warnings as errors.”

  • Right click on the project you want to enable this on.
  • Select the “Build” tab.
  • Change “Treat warnings as errors” to “All”.

Treat warnings as errors

We have this option enabled for all our projects and it has made a significant difference in keeping our projects tidy.

One caveat, there are times you may want to exclude certain types of warning. For example, we exclude “Obsolete” warnings. Many times we will deprecate a property or API call and it will need to stay for a while, we just don’t want new people using it, so we mark is as “[Obsolete].” By default this will generate a warning (there is an overload that will generate an error). We don’t want this to prevent the build and luckily there’s a way to exclude it from the “Treat warnings as errors”. This is not to be confused with “Excluded warning type”, these will still show as warnings, they just won’t cause an error. All we have to do is:

  • Right click on the project and chose “Unload Project.”
  • Right click on the project again and choose “Edit”
  • Add ” <WarningsNotAsErrors>612,618</WarningsNotAsErrors>” above “<TreatWarningsAsErrors>true</TreatWarningsAsErrors>”

612: The compiler warning code for the [Obsolete] tag

618: The compiler warning code for the [Obsolete(“Message”] tag

Now, you must consistently check and make sure your removing calls to obsolete methods or properties on a regular basis but it will be much easier now that we’ve reduced the noise in our “Warnings” window. This is a feature I encourage everyone=

Blake Helms

Blake Helms is a .NET Software Development Manager for EBSCO Industries, a global company with businesses in a range of industries including Information Services, Publishing and Digital Media, Outdoor Products, Real Estate, Manufacturing and Distribution, and Business Services, headquartered in Birmingham, Alabama. There he is responsible for several core business applications and has been a driver for software craftsmanship and creating a culture that promotes mentorship and continuous improvement. He is also the cofounder of the Birmingham .NET Meetup with a mission to promote good development practices and .NET technologies in the Birmingham, Alabama area. Blake is incredibly passionate about technology in all areas from writing code for work, to audio/video production for his church to automating his home.