如何从Visual Studio文件搜索中排除designer.cs [英] How to exclude designer.cs from Visual Studio file search

查看:110
本文介绍了如何从Visual Studio文件搜索中排除designer.cs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Visual Studio 2005/8中进行搜索时,是否可以排除特定类型的.cs文件?

Is there a way to exclude a particular type of .cs file when doing a search in Visual Studio 2005/8?

示例:在重构场景中,我可能会搜索以标识代码中的字符串文字,以便可以将它们重构为常量或类似的东西.但是,* designer.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.

我通常会搜索* .cs ...

i usually search for *.cs...

我如何忽略* .designer.cs?

How do i ignore *.designer.cs?

推荐答案

我觉得还很晚,但是查看此页面上的投票数和活动数量,我正在发布答案;也许其他人觉得它有用.在VS2010及更高版本中,您可以按照以下方法进行操作:

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. 打开程序包管理器控制台(工具> NuGet程序包管理器>程序包管理器控制台).让PowerShell初始化自身.
  2. 在PowerShell提示符处输入以下命令:

  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"

附加说明

  1. 如果要指定多个排除模式,请将"*.designer.cs"替换为@("*.designer.cs", "*.designer.vb", "reference.cs")或要跳过的其他文件.
  2. 关于它的另一个好处是,搜索模式也支持正则表达式.
  3. 该解决方案的一个缺点是,它不允许您双击结果中的一行以在Visual Studio中打开该文件.您可以通过命令管道解决此限制:

  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", """$_""") }

这将打开在Visual Studio中找到字符串或模式的所有文件.然后,您可以在各个文件中使用查找窗口来查找确切的实例.

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.

此解决方案的另一个优势是,它也可以在Express版本中使用,因为2012和2013 Express版本中都包含Package Manager;虽然不确定2010年.

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.

这篇关于如何从Visual Studio文件搜索中排除designer.cs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆