visual-studio 如何从 Visual Studio 文件搜索中排除 Designer.cs
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1596337/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to exclude designer.cs from Visual Studio file search
提问by Paul Sasik
Is there a way to exclude a particular type of .cs file when doing a search in Visual Studio 2005/8?
在 Visual Studio 2005/8 中进行搜索时,是否可以排除特定类型的 .cs 文件?
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.
示例:在重构场景中,我可能会搜索以识别代码中的字符串文字,以便我可以将它们重构为常量或类似内容。然而,*designer.cs 文件充满了我不想处理的字符串文字,但它们会出现在我的搜索中并污染结果集。
i usually search for *.cs...
我通常搜索 *.cs ...
How do i ignore *.designer.cs?
我如何忽略 *.designer.cs?
采纳答案by dotNET
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:
我发现已经很晚了,但是查看此页面上的投票数和活动,我正在发布我的答案;也许其他人觉得它很有用。以下是在 VS2010 及更高版本中执行此操作的方法:
- 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.
- 打开包管理器控制台(工具 > NuGet 包管理器 > 包管理器控制台)。让 PowerShell 自行初始化。
在 PowerShell 提示符处输入以下命令:
dir -Recurse | Select-String -pattern "Your Search Word Or Pattern" -exclude "*.designer.cs"- 这将列出您指定的单词或模式的所有出现次数,包括文件名、行号和找到它的文本行。
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", """$_""") }
- 如果要指定多个排除模式,请替换
"*.designer.cs"为@("*.designer.cs", "*.designer.vb", "reference.cs")或要跳过的任何其他文件。 - 另一个好处是搜索模式也支持正则表达式。
此解决方案的一个缺点是它不允许您双击结果中的一行以在 Visual Studio 中打开该文件。您可以通过命令管道解决此限制:
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 Findwindow in individual files to locate the exact instances.
这将打开在 Visual Studio 中找到字符串或模式的所有文件。然后,您可以在单个文件中使用“查找”窗口来定位确切的实例。
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.
此解决方案的另一个优点是它也适用于 Express 版本,因为 Package Manager 包含在 2012 和 2013 Express 版本中;虽然不确定2010年。
回答by Steven Chong
*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
-史蒂文钟
回答by Daniel Ballinger
For Visual Studio 2010 try the Ultra Findextension. You can explicitly exclude extensions.
对于 Visual Studio 2010,请尝试Ultra Find扩展。您可以明确排除扩展名。


Note that the search speed depends on if you are searching the file system or the project/solution.
请注意,搜索速度取决于您是搜索文件系统还是项目/解决方案。
回答by Ben Gribaudo
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.
Microsoft Connect 票证“查找排除设计器生成代码的选项”表示 VS 2010 中将不存在按文件扩展名过滤搜索。
回答by samneric
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:
对 VS 感到沮丧并回到我可信赖的 UltraEdit 副本并在其“在文件中查找”工具中指定了这些选项:
File names/extensions to ignore in search:
*.pdb;*.dll;*.exe;*designer.vb;*.xsd;*.xml;*.xss;*.resx;
回答by Kobus Smit
A commercial option is the $29 Entrian Source Search add-in that can specify exclusion patterns
一个商业选项是 29 美元的 Entrian Source Search 插件,它可以指定排除模式
回答by Mike Durthaler
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.
幸运的是,所有我不想包含的文件都在一个名为“Archived”的文件夹中,所以......我将文件剪切并粘贴到我的桌面上。
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.
也许这就是 Ultra Find Extension 消失的原因……开发人员可以将所有不需要的文件分组到 Web 根目录下的文件夹中,然后在搜索时将其删除,哈哈。
回答by Craig A
The feature to exclude files matching a pattern has been added to Visual Studio 16.5.x
排除与模式匹配的文件的功能已添加到 Visual Studio 16.5.x
https://devblogs.microsoft.com/visualstudio/modernizing-find-in-files/
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.
以“!”为前缀的任何路径或文件类型 字符将从搜索中排除。例如,您可以将“!*\node_modules*”添加到文件类型列表中以排除 node_modules 文件夹中的任何文件。

