How to Fix a Project With 0 Lines of Code in SonarQube

One of the projects I have got “A” ratings though all metrics in SonarQube. The only problem: it showed a project size with 0 lines of code. How did this happen?

After checking the logs, I noticed a warning indicator on the project page of SonarQube:

Last analysis of this Branch had 1 warning

I clicked on the link and got this notice that my project only contains TEST code:

The warning explains that the project only contains TEST code.

The provided link to the documentation explains the various reasons why this could happen. My project had neither a reference to a test framework nor was it named in such a way that it could be mistaken for a test project. There was also no hint in the log file as to why the mix-up occurred.

Should you run into the same problem, you can add this property group to the *.csproj file for all projects that should be counted:

After the next analysis the code in the project was counted in SonarQube and I got a correct rating for the metrics – and a list of items to fix.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.