Using PVS-Studio with huge projects (MSBuild integration)

Andrey Karpov
Articles: 565

If your solution includes a lot of large projects, you may find it uncomfortable to operate the PVS-Studio analyzer when checking it. In this small post we'll explain why it happens and how integrating PVS-Studio into MSBuild's build process will help you to improve the situation.

I want to make it clear right away that the analyzer's operation mode described below should be used only in rare cases when dealing with huge projects. You'll get no benefit from using it for small and medium projects - in fact analysis may even get much slower.

But let's assume your case is just that rare one - your solution includes quite a lot of projects, and the total number of files to be compiled is many thousands.

The PVS-Studio analyzer uses the API functions provided by Visual Studio to gather information about files. It needs to know which files should be checked, which preprocessor definitions are specified for each file, which directories with header files should be used, and so on.

If there are a lot of projects and files, data gathering takes too much time. PVS-Studio meditates for a long time before starting analysis. It is especially noticeable with incremental analysis. It often happens that data gathering is several times longer than the analysis of a few changed files itself.

We can't fix that because we cannot speed up calls of API functions. But there is a workaround: integration into MSBuild's build process.

We won't discuss how to get started with MSBuild in this post. This aspect is described very thoroughly in the documentation, and we find it senseless to copy text from there. Something may change in time, and this blog post will become obsolete. That's why we refer readers to the documentation section for more information: "Direct integration of PVS-Studio into MSBuild's build process. MSBuild integration mode in Visual Studio IDE".

Let's only enumerate advantages and disadvantages of the integration method here.


1) The analyzer doesn't need to gather information about files - MSBuild will provide it with all the necessary data. This will significantly reduce analysis time in projects containing a huge number of files.

2) In case of incremental analysis, MSBuild will run a check only for the files which have been changed and provide you with all the information you need. Therefore, using the incremental analysis mode with large projects becomes quite convenient.

3) You can check projects which are extensions to the standard Visual C++ project model (for example driver projects). Any Visual C++ user can extend the project model to add their own specific build parameters into it. But if the project is being built by MSBuild, you can integrate analysis by PVS-Studio into it, while the common operation mode of PVS-Studio as a plugin doesn't always work correctly in this case, as the extended project model won't be represented in Visual Studio Extensibility API.

4) Since analysis by PVS-Studio is integrated into the build process, you can check a project (while building it) on a system without IDE: for example on the build server during night builds.


1) Since it is MSBuild that launches the analyzer, it also appears to be responsible for parallelization. MSBuild parallelizes the build process at the project level: an individual MSBuild instance is launched for each project, which in its turn calls an individual PVS-Studio instance. The drawback here is that you can't analyze files within the framework of one project in parallel.

2) Integration into MSBuild requires modifying the project file (*.vcxproj).

Use PVS-Studio to search for bugs in C, C++, C# and Java

We offer you to check your project code with PVS-Studio. Just one bug found in the project will show you the benefits of the static code analysis methodology better than a dozen of the articles.

goto PVS-Studio;

Andrey Karpov
Articles: 565

Bugs Found

Checked Projects
Collected Errors
14 526
This website uses cookies and other technology to provide you a more personalized experience. By continuing the view of our web-pages you accept the terms of using these files. If you don't want your personal data to be processed, please, leave this site. Learn More →