How to exclude designer.cs from Visual Studio file search

Viewed 16846

Is there a way to exclude a particular type of .cs file when doing a search in Visual Studio 2005/8?

Example: In a refactoring scenario i might search to identify string literals in my code so that i can refactor them into constants or some such. However, *designer.cs files are full of string literals which i don't care to deal with but they show up in my search and pollute the result set.

i usually search for *.cs...

How do i ignore *.designer.cs?

10 Answers

The feature to exclude files matching a pattern has been added to Visual Studio 16.5.x

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

Any path or file type prefixed with the “!” character will be excluded from the search. For instance, you can add “!*\node_modules*” to the file types list to exclude any files in a node_modules folder.

Concerning Visual Studio 2019 16.5 (Preview 1) and above:

I'm very late to the party, but I did want to filter out the designer.vb files from my search recently, and I learned that the VS team updated the "Find and Replace" dialog in late 2019 (the one you get with Ctrl+Shift+F).

You can now filter out some extensions really easily: you just have to add the right string to the file type textbox:

Find and Replace dialog

The filters are separated by semicolon. A filter starting with an "!" is a filter against something. Here I added the following to exclude code from my designer files:

!*.designer.vb

which would translate to "Avoid files starting with 'wildcard' .designer.vb"

A very interesting improvement. Here's the associated blog post for more details. You should read through it.

Related