Excluding specific files from Visual Studio search

Visual StudioSearchVisual Studio-2012

Visual Studio Problem Overview


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

Visual Studio Solutions


Solution 1 - Visual Studio

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.

Solution 2 - Visual Studio

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/

Solution 3 - Visual Studio

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.

Solution 4 - Visual Studio

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).

Solution 5 - Visual Studio

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)

Solution 6 - Visual Studio

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.

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
QuestionpajicsView Question on Stackoverflow
Solution 1 - Visual StudioWilson AlbertoView Answer on Stackoverflow
Solution 2 - Visual StudiorecView Answer on Stackoverflow
Solution 3 - Visual StudioCosminView Answer on Stackoverflow
Solution 4 - Visual StudiosavehanssonView Answer on Stackoverflow
Solution 5 - Visual StudiodrzausView Answer on Stackoverflow
Solution 6 - Visual StudiorobyawView Answer on Stackoverflow