Utility to generate Visual Studio solution file for a group of projects

I wanted to analyze our company projects with NDepend and ran NDepend on a couple of our solutions. While it produced very interesting reports (I will try to cover results of NDepend analysis in one of my following posts), I’ve found that the solution contents were not optimal for such analysis. When analyzing project dependencies, you want to be specific about what projects are used as input. In our case every solution contains unit/integration test projects – actually nearly half of our projects are test projects, and inclusion of test projects in dependency analysis can give wrong impression about code usage: for example, some obsolete code may be reported as code in use, even though it is only called from tests. So I wanted to limit the projects being analyzed gathering all projects used in production and only them. I didn’t have a solution that would satisfy me, so I decided that the easiest would be to find a utility that generates a Visual Studio solution file by scanning all projects within the specified root. Expecting to find such program on the net, I searched the Web with search pattern "generate visual studio solution". Nothing useful. I’ve extended the pattern with "utility", but still no luck. I still refuse to believe that nobody wrote and published such simple thing, I must have failed with good search pattern. Anyway, now I have such utility – I had to write it myself. It’s very simple and does the following:

  • Generates a solution file (.sln) that can be opened with Visual Studio 2008 (sorry, no VS 2005 support, but it’s a matter of changing two lines in the source);
  • Includes in a solution file references to all C# projects (sorry, no VB) that reside in subfolders of a given root;
  • Inclusion and exclusion filters can be specified in a command line.

The application and its source code can be downloaded from here. Here are examples of usage:

GenerateSolutionFile.exe
Usage: GenerateSolutionFile /p <path> /s <solution> [/i includeFilter] [/e excludeFilter]

GenerateSolutionFile.exe /p C:ProjectsLfx /s C:ProjectsLfxTest.sln
Added project Lfx.ConfigReader.csproj
Added project Lfx.Core.csproj
Added project Lfx.Core.TestAssemblyConfig.csproj
Added project Lfx.Core.TestConfiguration.csproj
Added project Lfx.Core.Tests.csproj
Added project Lfx.Data.csproj
Added project Lfx.Data.Tests.csproj
Added project Lfx.Global.csproj
Added project Lfx.Global.Tests.csproj
Added project Lfx.Msmq.csproj
Added project Lfx.Msmq.Tests.csproj
Added project Lfx.Services.csproj
Added project Lfx.Services.Tests.csproj
Added project Lfx.TestUtils.csproj
Solution is generated, 14 projects added

GenerateSolutionFile.exe /p C:ProjectsLfx /s C:ProjectsLfxTest.sln /i Core*
Skipped project Lfx.ConfigReader.csproj
Added project Lfx.Core.csproj
Added project Lfx.Core.TestAssemblyConfig.csproj
Added project Lfx.Core.TestConfiguration.csproj
Added project Lfx.Core.Tests.csproj
Skipped project Lfx.Data.csproj
Skipped project Lfx.Data.Tests.csproj
Skipped project Lfx.Global.csproj
Skipped project Lfx.Global.Tests.csproj
Skipped project Lfx.Msmq.csproj
Skipped project Lfx.Msmq.Tests.csproj
Skipped project Lfx.Services.csproj
Skipped project Lfx.Services.Tests.csproj
Skipped project Lfx.TestUtils.csproj
Solution is generated, 4 projects added

GenerateSolutionFile.exe /p C:ProjectsLfx /s C:ProjectsLfxTest.sln /e Core*
Added project Lfx.ConfigReader.csproj
Skipped project Lfx.Core.csproj
Skipped project Lfx.Core.TestAssemblyConfig.csproj
Skipped project Lfx.Core.TestConfiguration.csproj
Skipped project Lfx.Core.Tests.csproj
Added project Lfx.Data.csproj
Added project Lfx.Data.Tests.csproj
Added project Lfx.Global.csproj
Added project Lfx.Global.Tests.csproj
Added project Lfx.Msmq.csproj
Added project Lfx.Msmq.Tests.csproj
Added project Lfx.Services.csproj
Added project Lfx.Services.Tests.csproj
Added project Lfx.TestUtils.csproj
Solution is generated, 10 projects added

GenerateSolutionFile.exe /p C:ProjectsLfx /s C:ProjectsLfxTest.sln /e Core* /e *.Tests
Added project Lfx.ConfigReader.csproj
Skipped project Lfx.Core.csproj
Skipped project Lfx.Core.TestAssemblyConfig.csproj
Skipped project Lfx.Core.TestConfiguration.csproj
Skipped project Lfx.Core.Tests.csproj
Added project Lfx.Data.csproj
Skipped project Lfx.Data.Tests.csproj
Added project Lfx.Global.csproj
Skipped project Lfx.Global.Tests.csproj
Added project Lfx.Msmq.csproj
Skipped project Lfx.Msmq.Tests.csproj
Added project Lfx.Services.csproj
Skipped project Lfx.Services.Tests.csproj
Added project Lfx.TestUtils.csproj
Solution is generated, 6 projects added

UPDATE. I have extended the utility to create solution folders. See this blog post.

One thought on “Utility to generate Visual Studio solution file for a group of projects”

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>