How to exclude designer.cs from Visual Studio file

2019-01-10 22:24发布

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?

9条回答
三岁会撩人
2楼-- · 2019-01-10 22:33

Just search files types: *.aspx.vb

enter image description here

查看更多
劫难
3楼-- · 2019-01-10 22:37

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 patter supports regular expressions as well.
  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.

查看更多
Luminary・发光体
4楼-- · 2019-01-10 22:45

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.

查看更多
Evening l夕情丶
5楼-- · 2019-01-10 22:47

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.

查看更多
放荡不羁爱自由
6楼-- · 2019-01-10 22:51

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

查看更多
三岁会撩人
7楼-- · 2019-01-10 22:55

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;
查看更多
登录 后发表回答