How to exclude designer.cs from Visual Studio file search
search, visual-studio
Solution
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.
Problem
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?