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.
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”.
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>”
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=