views:

50

answers:

5

I am exploring a structure of folders with C# projects such as the following:

  • Projects
    • ProjectA
    • ProjectB
    • ProjectC
    • ProjectD

Scattered around in the same folders as the .csproj files, there are several solution (.sln) files. Is there a fast way to find all the solutions that contain ProjectD.csproj? I can open them one by one and see what they contain, but I would like a feature such as "find all the solutions containing this project".

+1  A: 

I don't think it's possible since VS open one solution at a time. But it shouldn't be difficult to create a simple script that searches within .sln files (better than nothing).

mamoo
+1  A: 

Install Cygwin and run grep over the solution files. You'll never look back...

David M
+1  A: 

Just do a Find in Files search in all files with the extension .sln and look for any row beginning with the word "Project".

I like TextPad so I use that to search with but there are plenty of other tools including many free ones.

ho1
grepWin and WinGrep, for instance, can deliver just those lines with the files they're in.
reinierpost
+1  A: 

Both the above two solutions (David M's and ho1's) will work.

Personally, I find the grep solution faster than trying to use the MS File Search utility, but the second one works well enough, especially if you don't want to install extra software to do what you want to do.

pdwalker
A: 

I wrote a Perl script to do it (using libxml2 to parse the files when possible, so it's slightly more sophisticated than grepping). It's not perfect, but I keep improving it with every code base I use it on. I'm not publishing the script at this time.

A more fundamental improvement would be to program against the Visual Studio API instead.

The cruder approach of grepping for filenames inside files is implemented within another Perl script of mine, xref. Unfortunately, it can get tricky to use it correctly, so you may prefer to just use find and grep manually.

reinierpost