且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从Visual Studio文件搜索中排除designer.cs

更新时间:2023-09-17 17:08:10

我觉得还很晚,但是查看此页面上的投票数和活动数量,我正在发布答案;也许其他人觉得它有用.在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.