views:

103

answers:

3

Today I was actually wondering why I've stuck with it for so many years without actively complaining about it. Doing a "search & replace in all files and folders of a solution" is something I quite regularly need to do, esp. when refactoring tools fail me. Unfortunately, "all folders and files" means "some projects and some other files". Notably, unconnected files in solution folders, complete web sites and csproj/vbproj/sln files are skipped.

Also, just searching often reveals more hits than replacement replaces (for instance, a csproj is only replaced when its project is unloaded).

Ok, enough complaining: anybody aware of a good plugin or a nice valuable trick that can do a real search and replace through all files and folders of a solution? Something I can rely on?

(edit)
PS: after some more thought: having your system under Subversion or other source control system will make a full search only really valuable when the folder-list could contain a filter of exclusions, i.e., exclude all .svn files and dirs. Unfortunately, as far as I know, that's not possible with the supplied solution.

+2  A: 

While it's not a plugin for Visual Studio Notepad++'s find (and replace) in files functionality seems to be solid.

You even get syntax highlighting of your code - though not for aspx files by default. However, this post tells you how to get it working.

UPDATE

You can get a more comprehensive search and replace from within Visual Studio.

Ctrl+Shift+H to go the the dialog up.

Then select the ... button next to the "Look in" drop down to get the "Choose Search Folders" dialog.

Pick your folder and then do your search and replace (or just search even).

ChrisF
Abel
@Abel - I've just remembered there is a trick to get VS to search all files and folders. I'm just looking it up now and will update my answer.
ChrisF
Ah yes, forgot about that. It uses the concept of *folder sets* and if I remember well, it was a nuisance to get it to work, but I might just need to *learn* to use it. If it works and doesn't take the better part of the day to set up, it'd be a good replacement. Note that `*` here searches in the VS installation folder, *not* the current solution or execution folder.
Abel
In a particular use-case scenario it went from 3 matching lines (normal S-). Tx!
Abel
+1  A: 

You could use the VS Command Shell and let Windows do the walking. Even if you don't use it for S&R, it's nice to have.

fatcat1111
+1 for an interesting idea. It might save me quite some back and forth to the Windows shell that I do nowadays (and findstr wins by far from Windows' own search, which I never understood, but that's another story)
Abel
+1  A: 

I agree that it's not the best search tool in the world, but I've never had any of the problems you describe.

You imply that it is not possible to filter the files searched in Visual Studio, and that files on disk that are not referenced in your solution are not searched. Well, that's because you've asked Visual Studio to do that - I think you need to learn how to use the tool better, because it handles these situations perfectly well.

You can set the search to work on a solution, on specific projects, the current project, open documents only, the current document, or search any folder hierarchy on your drive with a list of filename filters to choose precisely what is scanned. These settings can be saved and then used whenever you need them by just choosing the pre-set in a combobox. The user interface for setting this up is pretty awful, but once it's set up it works well. For example, I often use an "entire codebase" to search my drive rather than "Entire Solution" which only searches the files in my solution. Or "All XML files". Or "All Source files but no headers". Etc.

If you have problems with scanning open projects, then don't - just run another instance of VS with no solution loaded in it. The idea of trying to use one instance of VS to handle everything (with all the window layout reconfiguring that is necessary as you swap between tasks) quite frankly baffles me.

Jason Williams
My complaint was about "entire solution" searches, but I didn't realize that when i wrote it. I know of the types of searches (but had forgotten about the arcane method of folder groups). Since I recently work a lot on web sites (not web projects!), the weird thing happens: search "entire solution" replaces less then searching "current project" when the current prj is a web site. My guess is, since a "web site" is not actually a project, it's not correctly searched.
Abel
Quote "quite frankly baffles me.": me too. And it makes it sloooow. Maybe I should more often switch to single-project IDE instances, but I've just gotten used to this...
Abel