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

查看:24
本文介绍了如何从 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" |排序 |选择-ExpandProperty路径"|获得独特|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 版本,因为 Package Manager 包含在 2012 和 2013 Express 版本中;不过不确定 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天全站免登陆