To get a trial key
fill out the form below
Team License (a basic version)
Enterprise License (extended version)
* By clicking this button you agree to our Privacy Policy statement

Request our prices
New License
License Renewal
--Select currency--
* By clicking this button you agree to our Privacy Policy statement

Free PVS-Studio license for Microsoft MVP specialists
* By clicking this button you agree to our Privacy Policy statement

To get the licence for your open-source project, please fill out this form
* By clicking this button you agree to our Privacy Policy statement

I am interested to try it on the platforms:
* By clicking this button you agree to our Privacy Policy statement

Message submitted.

Your message has been sent. We will email you at

If you haven't received our response, please do the following:
check your Spam/Junk folder and click the "Not Spam" button for our message.
This way, you won't miss messages from our team in the future.

How to unite several separate projects …

How to unite several separate projects into one general Visual Studio solution (.sln file)

Apr 26 2013

For the purpose of testing our C/C++ analyzer PVS-Studio, we often check various open-source projects and publish reports about bugs we have found. It is obvious that we seek projects of large sizes (hundreds of thousands of code lines), as there is little to be tested and caught in just a few dozens of files. We already had opportunities to test large collections consisting of hundreds of small open-source projects, for example sets of test samples for various SDKs and Frameworks. We are especially interested in checking such collections to see how the analyzer supports various specific code constructs, Visual C++ project subtypes, and so on.

But projects of this kind have one disadvantage which is not obvious at first sight: they lack a general project solution file. Each project in these sets is usually independent and has its own solution. Checking 4 or 5 hundred sln files is certainly not a fascinating employment, considering that handling hundreds of reports thus obtained will be pretty hard too.

Logic tells us that we could create one independent sln file (One Solution to Rule Them All) for all the project files to unite all the projects we need. But this simple task appears to be not as trivial in case of Visual Studio because the Add Project dialog allows you to choose only one project at a time! So even if you are lucky enough to have all the projects lying in one directory, the process of adding them will be painful all the same.

A quick search revealed at once that we were not alone who had faced this problem. But what do people usually suggest in this case? Well, they suggest "manually" generating a new solution, open it as a text file, and add the necessary code lines for each project. What is tricky about this method? You see, besides having to search through each project to find out its identifiers and configurations, you risk getting a conflict of dependencies or those very GUIDs of projects (even if only 2 of them). In that case you would have to manually investigate the whole solution to locate the problem! And writing a program that would take this all into account yet would be needed just a couple of times, is very burdensome.

After all, all this functionality can be found in Visual Studio itself - it is that very Add Existing Project that provides it. If only we could automate the process of calling this command and receiving the list of files... Well, we can do that. What's more, we can do it by adding just 4 code lines:

EnvDTE.DTE dte = Package.GetService(typeof(EnvDTE._DTE)) 
    as EnvDTE.DTE;
m_dte = (EnvDTE80.DTE2)dte;
foreach (string file in Directory.GetFiles(ProjectRoot, "*.vcxproj",
    m_dte.Solution.AddFromFile(file, false);

As you can see, the object of the EnvDTE80.DTE2 type allows the program to add a project into the current solution by the file name. And it is quite what we need! Besides, the AddFromFile method also allows you to manage projects being added by returning references to each of them. Wrapping this code into a try...catch block will allow you to eliminate all the possible conflicts between separate projects.

What is after all EnvDTE80.DTE2 and how to get it? The DTE (development environment) object is the top-level object of the Visual Studio Extensibility API which allows you to automate the process of working in IDE and even extend its capabilities. There are several different ways to get access to DTE, both from an external process and by creating an extension package or a plugin for the Visual Studio environment. We have a series of articles on our website on the basics of development of such plugins, where you can find simple instructions on how to create such a plugin right now!

Popular related articles
Characteristics of PVS-Studio Analyzer by the Example of EFL Core Libraries, 10-15% of False Positives

Date: Jul 31 2017

Author: Andrey Karpov

After I wrote quite a big article about the analysis of the Tizen OS code, I received a large number of questions concerning the percentage of false positives and the density of errors (how many erro…
How PVS-Studio Proved to Be More Attentive Than Three and a Half Programmers

Date: Oct 22 2018

Author: Andrey Karpov

Just like other static analyzers, PVS-Studio often produces false positives. What you are about to read is a short story where I'll tell you how PVS-Studio proved, just one more time, to be more atte…
Free PVS-Studio for those who develops open source projects

Date: Dec 22 2018

Author: Andrey Karpov

On the New 2019 year's eve, a PVS-Studio team decided to make a nice gift for all contributors of open-source projects hosted on GitHub, GitLab or Bitbucket. They are given free usage of PVS-Studio s…
PVS-Studio ROI

Date: Jan 30 2019

Author: Andrey Karpov

Occasionally, we're asked a question, what monetary value the company will receive from using PVS-Studio. We decided to draw up a response in the form of an article and provide tables, which will sho…
Technologies used in the PVS-Studio code analyzer for finding bugs and potential vulnerabilities

Date: Nov 21 2018

Author: Andrey Karpov

A brief description of technologies used in the PVS-Studio tool, which let us effectively detect a large number of error patterns and potential vulnerabilities. The article describes the implementati…
Appreciate Static Code Analysis!

Date: Oct 16 2017

Author: Andrey Karpov

I am really astonished by the capabilities of static code analysis even though I am one of the developers of PVS-Studio analyzer myself. The tool surprised me the other day as it turned out to be sma…
The Last Line Effect

Date: May 31 2014

Author: Andrey Karpov

I have studied many errors caused by the use of the Copy-Paste method, and can assure you that programmers most often tend to make mistakes in the last fragment of a homogeneous code block. I have ne…
Static analysis as part of the development process in Unreal Engine

Date: Jun 27 2017

Author: Andrey Karpov

Unreal Engine continues to develop as new code is added and previously written code is changed. What is the inevitable consequence of ongoing development in a project? The emergence of new bugs in th…
PVS-Studio for Java

Date: Jan 17 2019

Author: Andrey Karpov

In the seventh version of the PVS-Studio static analyzer, we added support of the Java language. It's time for a brief story of how we've started making support of the Java language, how far we've co…
The Ultimate Question of Programming, Refactoring, and Everything

Date: Apr 14 2016

Author: Andrey Karpov

Yes, you've guessed correctly - the answer is "42". In this article you will find 42 recommendations about coding in C++ that can help a programmer avoid a lot of errors, save time and effort. The au…

Comments (0)

Next comments
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 →