How to exclude designer.cs from Visual Studio file search
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:
- Open Package Manager Console (Tools > NuGet Package Manager > Package Manager Console). Let PowerShell initialize itself.
Enter the following command at PowerShell Prompt:
dir -Recurse | Select-String -pattern "Your Search Word Or Pattern" -exclude "*.designer.cs"
- 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
- 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. - Another good thing about it is that the search pattern supports regular expressions too.
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.
*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