100

Is it possible to exclude certain files from search in Visual Studio.

For example jquery.js is almost always polluting my search results with half result coming from that file.

I know you can white-list specific types, but when I want to search in .js extension is there solution for that?

Vote here for feature: https://developercommunity.visualstudio.com/idea/405990/code-search-exclude-files-from-search.html?inRegister=true

pajics
  • 2,938
  • 3
  • 23
  • 27
  • 5
    Maybe this questions can help you: http://stackoverflow.com/questions/1749837/exclude-file-types-from-search-in-visual-studio http://stackoverflow.com/questions/1596337/how-to-exclude-designer-cs-from-visual-studio-file-search – Andrea May 03 '13 at 12:36
  • 2
    That vote is now closed. Here's the current item. Please go vote here: https://developercommunity.visualstudio.com/idea/405990/code-search-exclude-files-from-search.html – ygoe Apr 08 '19 at 08:19

6 Answers6

34

Altough it does not solve your problem it may help out a bit

Ctrl + Shift + F should trigger the Find and Replace window.

From there, click Result Options and select "Display file names only".

It won't have all the info you need but might make it easier to recognize the files.

Saurav Sahu
  • 13,038
  • 6
  • 64
  • 79
Wilson Alberto
  • 516
  • 1
  • 4
  • 10
29

In Visual Studio 2019 they modernized the "find in files" feature, now you can exclude files, file extensions and directories using an exclamation mark before the items to be excluded in the "File types" textbox, like this:

*.*;!jquery.js

another example: !*\bin\*;!*\obj\*;!*\.*;!*.xml

More info: https://devblogs.microsoft.com/visualstudio/modernizing-find-in-files/

Dai
  • 141,631
  • 28
  • 261
  • 374
LLucasAlday
  • 2,349
  • 11
  • 34
  • 41
8

In Visual Studio 2017 there is a workaround: you can right-click a search result and then click Delete. I use it to eliminate the big minified files from the Find Results window.

Cosmin
  • 2,365
  • 2
  • 23
  • 29
7

I've got the same problem with unwanted .js files polluting the search result. Especially the minified versions (e.g. jquery.min.js) are really annoying since they consist of only one (1) single very very long line. All of that line is displayed line-wrapped in search result. Not ideal!

Possible solutions:

  • Since .js files are (normally) just static content, you should be able to name them as you like. Rename it to jquery.min.js.nosearch and include the file with <script type="text/javascript" src="jquery.min.js.nosearch"></script> in HTML.

  • Get these files from an CDN and delete your local files.

  • Exclude these files from the VS project, provided that you can handle the inclusion of them in an other way when needed, e.g. when deploying (and provided that you scope your search to solution/project, not folder).

savehansson
  • 453
  • 7
  • 14
  • Great idea!. also, you can add a `ren /folder/jquery.min.js.nosearch /folder/jquery.min.js` command in your post-build events :-) – itsho Dec 10 '17 at 09:52
3

From this answer there was an UltraFind extension, which unfortunately doesn't exist for newer than 2010 (but see thread for hack to "update" it to 2012)

Community
  • 1
  • 1
drzaus
  • 24,171
  • 16
  • 142
  • 201
3

It's not particularly elegant - I'd be reluctant to call it a solution to the question - but if you can have Visual Studio Code running side-by-side with VS201x, its Find and Replace feature is pretty sophisticated. If you're using Git for source control, it will exclude any files or folders found in .gitignore from its search results - this is great when used in conjunction with tools like LibMan. Failing that, you can always manually add files / folders to its "files to exclude" option when searching.

robyaw
  • 2,274
  • 2
  • 22
  • 29
  • using `.gitignore` for this is a PITA too: 1. if you want to search in files that are not in git, you have to temporarily edit your .gitignore file 2. adding a `.gitigore` is not enough, you have to add the folder to git as well – bert bruynooghe Jul 29 '22 at 09:24