How can I tell Visual Studio to exclude folders from the Find in Files?

Visual Studio

Visual Studio Problem Overview


We use subversion so we have subfolders named _svn in our solution. Doing a Find in Files returns strings from these subfolders. Is there any way to tell Visual Studio to ignore these files?

Visual Studio Solutions


Solution 1 - Visual Studio

From "Find in Files", in "File Types" or "Look at these file types", you can use:

!*\ExcludeFolder\*

Example:

!*\bin\*;!*\obj\*;!*\.*;!*\ExcludeFolder\*

enter image description here

Solution 2 - Visual Studio

What you can do is to setup a set of folders that will be used for searching. In Find and Replace window, on the right hand side of "Look In" input you have a "Choose Search Folders" option where you can setup those sets of folders.
Just remember to turn off "Include sub folders" options if you have added root project folder.
If you don't have hundreds of folders this solution should work.

Solution 3 - Visual Studio

Never had an issue with the global find until we moved to Visual Studio 2017 and started with Angular + .net Core applications... (mostly problems with the HUGE node_modules folder being searched)

I found that using the MSBuild exclusion property DefaultItemExcludes is working fine to exclude from global find in Visual studio 2017..

I now by default open up the project file (.csproj) for a new core project in VS2017 and adjust the property as follows to exclude the node_modules (sometimes I add the wwwroot too):

<DefaultItemExcludes>$(DefaultItemExcludes);node_modules\**</DefaultItemExcludes>

See also https://github.com/dotnet/cli/issues/7525 , there they advise to prepend the folders to exclude and seem to use a forward slash instead of backward slash, like this :

<PropertyGroup>
  <DefaultItemExcludes>node_modules/**;$(DefaultItemExcludes)</DefaultItemExcludes>
</PropertyGroup>

Hope this helps anyone experiencing issues with VS2017 global find / search .

Solution 4 - Visual Studio

I had this problem when moving to Windows 10 using Visual Studio 2015 and TortoiseSVN. Previously the .svn folders were all hidden so did not appear in search results. To solve this I simply went to the folder properties in Windows Explorer and checked the 'Hidden' attribute for the .svn folder. After refreshing the folder view in Visual Studio the .svn folder no longer appeared and is ignored when using Find!

Set .svn folder attribute to hidden

Solution 5 - Visual Studio

I found in Visual Studio 2017 especially when using Angular Cli that the generated javascript files or other build files can be added to your project sometimes unknowingly. This can cause several headaches including adding a bunch of files to the searches and really slowing things down, especially intellisense because it is searching all of the generated files on top of the source files.

The easiest way I have found to correct this is to simply right click on the build folder (i.e. {Project}/dist) and select Exclude from Project. This will remove the folder from the project but the generated contents will still be available for runtime, it is just hidden from the UI.

enter image description here

If you need to still see the files, you can show hidden directories and files by selecting Show all Files or click on the Icon: enter image description here on the top of the Solution Explorer.

Basically you want to exclude all build folders from your project/solution.

Solution 6 - Visual Studio

Instead of searching for files in a directory (your solution's directory, in this case), you could limit your search to the files that are part of the project or the solution. Those in the _svn directories will thus be ignored.

Solution 7 - Visual Studio

I don't think you can set this (after all, you are asking for "Entire Solution" search), but often you can remove the folder from the project / hide the directory in filesystem (for Web Site project type).

Solution 8 - Visual Studio

If you are not using VS2019 or VS Code (for which the solution has already been found in other answers), as a workaround you can use the search in Far Manager, it supports masks to exclude certain files or folders from the search. enter image description here

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBernardView Question on Stackoverflow
Solution 1 - Visual StudioA. MorelView Answer on Stackoverflow
Solution 2 - Visual StudiorafbelView Answer on Stackoverflow
Solution 3 - Visual StudioAardVark71View Answer on Stackoverflow
Solution 4 - Visual StudiobrightfunctionView Answer on Stackoverflow
Solution 5 - Visual StudioAndy BrahamView Answer on Stackoverflow
Solution 6 - Visual StudioXavier NodetView Answer on Stackoverflow
Solution 7 - Visual StudioLukáš LánskýView Answer on Stackoverflow
Solution 8 - Visual StudioevoriosView Answer on Stackoverflow