How to exclude designer.cs from Visual Studio file search
Asked Answered
Y

10

50

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?

Yellowweed answered 20/10, 2009 at 18:4 Comment(2)
Any chance you could post your solution as a answer. The accepted answer is now linking to a 404Quite
We can all vote for the feature in Visual Studio here: visualstudio.uservoice.com/forums/121579-visual-studio-2015/… Doooooo it!Mummify
N
14

I see it's pretty late, but looking at the number of votes and activity on this page, I'm posting my answer; maybe someone else finds it useful. Here's how you can do this in VS2010 and above:

  1. Open Package Manager Console (Tools > NuGet Package Manager > Package Manager Console). Let PowerShell initialize itself.
  2. Enter the following command at PowerShell Prompt:

    dir -Recurse | Select-String -pattern "Your Search Word Or Pattern" -exclude "*.designer.cs"

  3. This will list all the occurrences of the word or pattern you've specified, including file name, line number and the text line where it was found.

Additional Notes

  1. If you want to specify multiple exclude patterns, replace "*.designer.cs" with @("*.designer.cs", "*.designer.vb", "reference.cs") or whatever other files you want to skip.
  2. Another good thing about it is that the search pattern supports regular expressions too.
  3. One downside of this solution is that it doesn't let you double-click a line in the result to open that file in Visual Studio. You can workaround this limitation through command-piping:

    dir -Recurse | Select-String -pattern "Your String Or Pattern" -exclude "*.designer.vb" | sort | Select -ExpandProperty "Path" | get-unique | ForEach-Object { $DTE.ExecuteCommand("File.OpenFile", """$_""") }

This will open all the files where the string or pattern was found in Visual Studio. You can then use Find window in individual files to locate the exact instances.

Another advantage of this solution is that it works in Express versions as well, since Package Manager is included in 2012 and 2013 Express versions; not sure about 2010 though.

Neurosis answered 10/2, 2015 at 8:37 Comment(2)
The latter command throws up a load of windows saying "The operation could not be completed" in Visual Studio 2015 on a VB solution.Courtship
Found the answer - Replace (“File.OpenFile”, $_) with (“File.OpenFile”, """$_""") . This is to wrap the filenames in quotes as the path included spaces. Also consider adding *.VB if searching a whole solution. I got a lot of extraneous files until I did that.Courtship
N
31
*a.cs;*b.cs;*c.cs;*d.cs;*e.cs;*f.cs;*g.cs;*h.cs;*i.cs;*j.cs;*k.cs;*l.cs;*m.cs;*n.cs;*o.cs;*p.cs;*q.cs;*s.cs;*t.cs;*u.cs;*v.cs;*w.cs;*x.cs;*y.cs;*z.cs;*_.cs;*..cs;*ar.cs;*br.cs;*cr.cs;*dr.cs;*fr.cs;*gr.cs;*hr.cs;*ir.cs;*jr.cs;*kr.cs;*lr.cs;*mr.cs;*nr.cs;*or.cs;*pr.cs;*qr.cs;*rr.cs;*sr.cs;*tr.cs;*ur.cs;*vr.cs;*wr.cs;*xr.cs;*yr.cs;*zr.cs;*_r.cs;*.r.cs;*aer.cs;*ber.cs;*cer.cs;*der.cs;*eer.cs;*fer.cs;*ger.cs;*her.cs;*ier.cs;*jer.cs;*ker.cs;*ler.cs;*mer.cs;*oer.cs;*per.cs;*qer.cs;*rer.cs;*ser.cs;*ter.cs;*uer.cs;*ver.cs;*wer.cs;*xer.cs;*yer.cs;*zer.cs;*_er.cs;*.er.cs;*aner.cs;*bner.cs;*cner.cs;*dner.cs;*ener.cs;*fner.cs;*hner.cs;*iner.cs;*jner.cs;*kner.cs;*lner.cs;*mner.cs;*nner.cs;*oner.cs;*pner.cs;*qner.cs;*rner.cs;*sner.cs;*tner.cs;*uner.cs;*vner.cs;*wner.cs;*xner.cs;*yner.cs;*zner.cs;*_ner.cs;*.ner.cs;*agner.cs;*bgner.cs;*cgner.cs;*dgner.cs;*egner.cs;*fgner.cs;*ggner.cs;*hgner.cs;*jgner.cs;*kgner.cs;*lgner.cs;*mgner.cs;*ngner.cs;*ogner.cs;*pgner.cs;*qgner.cs;*rgner.cs;*sgner.cs;*tgner.cs;*ugner.cs;*vgner.cs;*wgner.cs;*xgner.cs;*ygner.cs;*zgner.cs;*_gner.cs;*.gner.cs;*aigner.cs;*bigner.cs;*cigner.cs;*digner.cs;*eigner.cs;*figner.cs;*gigner.cs;*higner.cs;*iigner.cs;*jigner.cs;*kigner.cs;*ligner.cs;*migner.cs;*nigner.cs;*oigner.cs;*pigner.cs;*qigner.cs;*rigner.cs;*tigner.cs;*uigner.cs;*vigner.cs;*wigner.cs;*xigner.cs;*yigner.cs;*zigner.cs;*_igner.cs;*.igner.cs;*asigner.cs;*bsigner.cs;*csigner.cs;*dsigner.cs;*fsigner.cs;*gsigner.cs;*hsigner.cs;*isigner.cs;*jsigner.cs;*ksigner.cs;*lsigner.cs;*msigner.cs;*nsigner.cs;*osigner.cs;*psigner.cs;*qsigner.cs;*rsigner.cs;*ssigner.cs;*tsigner.cs;*usigner.cs;*vsigner.cs;*wsigner.cs;*xsigner.cs;*ysigner.cs;*zsigner.cs;*_signer.cs;*.signer.cs;*aesigner.cs;*besigner.cs;*cesigner.cs;*eesigner.cs;*fesigner.cs;*gesigner.cs;*hesigner.cs;*iesigner.cs;*jesigner.cs;*kesigner.cs;*lesigner.cs;*mesigner.cs;*nesigner.cs;*oesigner.cs;*pesigner.cs;*qesigner.cs;*resigner.cs;*sesigner.cs;*tesigner.cs;*uesigner.cs;*vesigner.cs;*wesigner.cs;*xesigner.cs;*yesigner.cs;*zesigner.cs;*_esigner.cs;*.esigner.cs;*adesigner.cs;*bdesigner.cs;*cdesigner.cs;*ddesigner.cs;*edesigner.cs;*fdesigner.cs;*gdesigner.cs;*hdesigner.cs;*idesigner.cs;*jdesigner.cs;*kdesigner.cs;*ldesigner.cs;*mdesigner.cs;*ndesigner.cs;*odesigner.cs;*pdesigner.cs;*qdesigner.cs;*rdesigner.cs;*sdesigner.cs;*tdesigner.cs;*udesigner.cs;*vdesigner.cs;*wdesigner.cs;*xdesigner.cs;*ydesigner.cs;*zdesigner.cs;*_designer.cs

Hi, just copy and paste the above to "Look at these file types:"

-Steven Chong

Nidanidaros answered 4/6, 2012 at 9:14 Comment(6)
Although this works in that *.designer.cs doesn't display in the search results, white-listing is not the same as blacklisting the criteria. For instance, If I wanted to ignore *.designer.cs and Reference.cs, this white-list fails.Yeorgi
it's a workaround, Visual Studio will save your list. i can post another white-list if you want to ignore both *.designer.cs and reference.cs, which I personally found useful and want to shareNidanidaros
it's so ugly that I like it :-DConsolation
This is bad and you should feel bad! Though VS should feel worse for forcing us to do this, nice work :)Briefcase
This made me snort :)Politic
brute force solutions like this sometimes are needed!Rocket
N
14

I see it's pretty late, but looking at the number of votes and activity on this page, I'm posting my answer; maybe someone else finds it useful. Here's how you can do this in VS2010 and above:

  1. Open Package Manager Console (Tools > NuGet Package Manager > Package Manager Console). Let PowerShell initialize itself.
  2. Enter the following command at PowerShell Prompt:

    dir -Recurse | Select-String -pattern "Your Search Word Or Pattern" -exclude "*.designer.cs"

  3. This will list all the occurrences of the word or pattern you've specified, including file name, line number and the text line where it was found.

Additional Notes

  1. If you want to specify multiple exclude patterns, replace "*.designer.cs" with @("*.designer.cs", "*.designer.vb", "reference.cs") or whatever other files you want to skip.
  2. Another good thing about it is that the search pattern supports regular expressions too.
  3. One downside of this solution is that it doesn't let you double-click a line in the result to open that file in Visual Studio. You can workaround this limitation through command-piping:

    dir -Recurse | Select-String -pattern "Your String Or Pattern" -exclude "*.designer.vb" | sort | Select -ExpandProperty "Path" | get-unique | ForEach-Object { $DTE.ExecuteCommand("File.OpenFile", """$_""") }

This will open all the files where the string or pattern was found in Visual Studio. You can then use Find window in individual files to locate the exact instances.

Another advantage of this solution is that it works in Express versions as well, since Package Manager is included in 2012 and 2013 Express versions; not sure about 2010 though.

Neurosis answered 10/2, 2015 at 8:37 Comment(2)
The latter command throws up a load of windows saying "The operation could not be completed" in Visual Studio 2015 on a VB solution.Courtship
Found the answer - Replace (“File.OpenFile”, $_) with (“File.OpenFile”, """$_""") . This is to wrap the filenames in quotes as the path included spaces. Also consider adding *.VB if searching a whole solution. I got a lot of extraneous files until I did that.Courtship
C
11

For Visual Studio 2010 try the Ultra Find extension. You can explicitly exclude extensions.

Using Ultra Find to search files with cs extension but excluding designer.cs and generated.cs files.

Note that the search speed depends on if you are searching the file system or the project/solution.

Ceramic answered 20/6, 2012 at 1:11 Comment(3)
Unfortunately there is no Regex search in Ultra Find, it reduces some of the Ultraness...Platelet
It's a shame the Ultra Find extension was removed.. Anyone know of anything else?Synectics
@wasatchwizard I'm also looking for something similar. You have any luck finding something (specifically VS2012)?Portulaca
C
6

The Microsoft Connect ticket "Find option to exclude designer generated code" indicates that filtering search by file extension won't be present in VS 2010.

Careful answered 20/10, 2009 at 19:17 Comment(3)
This answer is now invalid, as filtering by file type is possible in VS2010Toneless
@hamlin11 Can you provide a reference for this?Rondeau
Not sure how this helps - you an search by file type, but how do you exclude certain file names?Stupid
T
5

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.

Terricolous answered 6/7, 2020 at 17:53 Comment(0)
P
4

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.

Providence answered 20/5, 2020 at 21:57 Comment(0)
I
1

I just came across this question in my search for an answer to this very problem.

Got frustrated with VS and fell back on my trusty copy of UltraEdit and specified these options in its "Find in Files" tool:

File names/extensions to ignore in search:

    *.pdb;*.dll;*.exe;*designer.vb;*.xsd;*.xml;*.xss;*.resx;
Ingate answered 6/4, 2011 at 15:47 Comment(2)
@sammeric: Thanks for the tip, and welcome to SO. Is there a free version of UltraEdit? I like Notepad++ but it does not seem to have the search ignore feature. (Btw, signatures aren't necessary in SO responses. All of your posts are auto-signed with your name & avatar.)Yellowweed
Unfortunately there is no free version of UltraEdit. I paid for a copy because I've used it for years (originally for its column-edit mode before VS added that feature). It has a ton of powerful features which make it personally worth the outlay. I use the scripting of regex search and replace just to name one feature.Ingate
H
0

A commercial option is the $29 Entrian Source Search add-in that can specify exclusion patterns

Handshake answered 4/8, 2015 at 3:23 Comment(0)
B
0

It really blows for an answer but here's what I did after trying 'Exclude from project' only to find that these files were also searched.

All the files I didn't want included were, fortunately, in a folder off the root called 'Archived' so ... I cut and pasted the file to my desktop.

Maybe that's why Ultra Find Extension disappeared ... developers can group all unwanted files into a a folder off the web root and just remove it while they do searches, LOL.

Berard answered 24/2, 2017 at 13:41 Comment(0)
A
-1

Just search files types: *.aspx.vb

enter image description here

Altazimuth answered 28/12, 2017 at 20:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.