Vagif Abilov's blog on .NET


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:\Projects\Lfx /s C:\Projects\Lfx\Test.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:\Projects\Lfx /s C:\Projects\Lfx\Test.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:\Projects\Lfx /s C:\Projects\Lfx\Test.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:\Projects\Lfx /s C:\Projects\Lfx\Test.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.

Comments

Omar Faruk said:

Great tool.

# August 5, 2009 9:57 AM

DotNetShoutout said:

Thank you for submitting this cool story - Trackback from DotNetShoutout

# August 7, 2009 4:25 AM

Vagif Abilov's blog on .NET said:

If somebody wants more from the program you wrote, it’s a good sign. It means that at last you did something

# December 3, 2009 11:10 AM

Niranjan said:

Is it possible to extend this code for VC++ projects?

I get the following errors when compiling

error CS0246: The type or namespace name 'var' could not be found (are you missing a using directive or an assembly reference?)

error CS0029: Cannot implicitly convert type 'var' to 'string'

# December 5, 2010 9:22 PM

Vagif Abilov said:

Niranjan,

Sorry for late reply. Can you be more specific about where you are getting this error? Do you compile the solution yourlself? If so, using what version of .NET? The error seems to indicate that you are using it with old .NET version.

# January 30, 2011 8:08 PM

Ravi Pasumarthy said:

Hi, This utility very useful as large projects generally tend to have lots of solution files. To speed up the build atleast we need another master build solution file.

Please contribute this tool either on codeplex or google code or github.

Thanks

# March 18, 2011 6:47 AM

Rune Rystad said:

Brilliant, Vagif! Just the utility I needed to make a "super solution" to feed into a dependency analyzer. I used this to get a brief overview: devio.wordpress.com/.../analyzing-files-and-directories-used-in-visual-studio-solution

# October 12, 2011 8:42 AM

Vagif Abilov said:

Thanks Rune! Good to know it was helpful.

# October 13, 2011 12:10 PM
Leave a Comment

(required) 

(required) 

(optional)

(required) 


Please add 2 and 2 and type the answer here: