Visual Studio 不可靠的搜索和替换的正确替代方案?

发布于 2024-08-20 11:39:32 字数 462 浏览 4 评论 0原文

今天我其实很想知道为什么我坚持了这么多年却没有主动抱怨它。 “在解决方案的所有文件和文件夹中搜索和替换”是我经常需要做的事情,尤其是。当重构工具让我失败时。不幸的是,“所有文件夹和文件”意味着“一些项目和其他文件”。值得注意的是,解决方案文件夹中未连接的文件、完整网站和 csproj/vbproj/sln 文件将被跳过。

此外,仅搜索通常会发现比替换替换更多的命中(例如,csproj 仅在其项目卸载时才被替换)。

好吧,抱怨够了:有人知道一个好的插件或一个有价值的技巧可以对解决方案的所有文件和文件夹进行真正的搜索和替换吗?有什么我可以依靠的吗?

(编辑)
PS:经过更多思考:只有当文件夹列表可以包含排除过滤器(即排除所有 .svn 文件和目录)时,将系统置于 Subversion 或其他源代码控制系统下才会进行完整搜索,这才真正有价值。不幸的是,据我所知,提供的解决方案不可能做到这一点。

Today I was actually wondering why I've stuck with it for so many years without actively complaining about it. Doing a "search & replace in all files and folders of a solution" is something I quite regularly need to do, esp. when refactoring tools fail me. Unfortunately, "all folders and files" means "some projects and some other files". Notably, unconnected files in solution folders, complete web sites and csproj/vbproj/sln files are skipped.

Also, just searching often reveals more hits than replacement replaces (for instance, a csproj is only replaced when its project is unloaded).

Ok, enough complaining: anybody aware of a good plugin or a nice valuable trick that can do a real search and replace through all files and folders of a solution? Something I can rely on?

(edit)
PS: after some more thought: having your system under Subversion or other source control system will make a full search only really valuable when the folder-list could contain a filter of exclusions, i.e., exclude all .svn files and dirs. Unfortunately, as far as I know, that's not possible with the supplied solution.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

宫墨修音 2024-08-27 11:39:33

我对“整个解决方案”有同样的问题。
事实上,它实际上并不是“完整的”,这就是重点。
我不需要学习如何使用该工具。有适合我的工具还是我适合工具?
它是如此简单 - “整个”对我来说意味着“整个”,但对功能开发人员来说则不然。

目前我不使用“整个解决方案”,但每次都会用路径替换它。它并不完美,因为它可能会搜索解决方案之外的目录中的其他文件,但它更可靠。

I have the same issues with "Entire Solution".
In fact it is not effectively "entire" and that's the point.
I shouldn't need to learn how to use the tool. Is there a tool for me or am I for the tool?
It is so simple - "entire" means "entire" for me but not for the feature developers.

For now I don't use "Entire Solution" but I replace it with a path every time. It's not perfect because it may search other files in the directory that are outside the solution but it's more reliable.

夏天碎花小短裙 2024-08-27 11:39:33

您可以使用 VS Command Shell 并让 Windows 执行此操作。即使您不将其用于 S&R,拥有它也很好。

You could use the VS Command Shell and let Windows do the walking. Even if you don't use it for S&R, it's nice to have.

半透明的墙 2024-08-27 11:39:33

我同意它不是世界上最好的搜索工具,但我从未遇到过您描述的任何问题。

您暗示无法过滤在 Visual Studio 中搜索的文件,并且不会搜索解决方案中未引用的磁盘上的文件。嗯,那是因为您已经要求 Visual Studio 这样做 - 我认为您需要学习如何更好地使用该工具,因为它可以很好地处理这些情况。

您可以将搜索设置为针对解决方案、特定项目、当前项目、仅打开文档、当前文档,或者使用文件名过滤器列表搜索驱动器上的任何文件夹层次结构,以精确选择扫描的内容。只需在组合框中选择预设即可保存这些设置,然后在需要时使用它们。用于设置此功能的用户界面非常糟糕,但一旦设置完毕,它就可以很好地工作。例如,我经常使用“整个代码库”来搜索我的驱动器,而不是“整个解决方案”,后者仅搜索我的解决方案中的文件。或“所有 XML 文件”。或“所有源文件,但没有标题”。等等。

如果您在扫描打开的项目时遇到问题,那就不要这样做——只需运行另一个没有加载解决方案的 VS 实例即可。坦率地说,尝试使用 VS 的一个实例来处理所有事情(在任务之间切换时需要重新配置所有窗口布局)的想法让我感到困惑。

I agree that it's not the best search tool in the world, but I've never had any of the problems you describe.

You imply that it is not possible to filter the files searched in Visual Studio, and that files on disk that are not referenced in your solution are not searched. Well, that's because you've asked Visual Studio to do that - I think you need to learn how to use the tool better, because it handles these situations perfectly well.

You can set the search to work on a solution, on specific projects, the current project, open documents only, the current document, or search any folder hierarchy on your drive with a list of filename filters to choose precisely what is scanned. These settings can be saved and then used whenever you need them by just choosing the pre-set in a combobox. The user interface for setting this up is pretty awful, but once it's set up it works well. For example, I often use an "entire codebase" to search my drive rather than "Entire Solution" which only searches the files in my solution. Or "All XML files". Or "All Source files but no headers". Etc.

If you have problems with scanning open projects, then don't - just run another instance of VS with no solution loaded in it. The idea of trying to use one instance of VS to handle everything (with all the window layout reconfiguring that is necessary as you swap between tasks) quite frankly baffles me.

故人爱我别走 2024-08-27 11:39:32

虽然它不是 Visual Studio Notepad++ 查找(和替换)的插件在文件中的功能似乎很可靠。

您甚至可以突出显示代码的语法 - 尽管默认情况下不会突出显示 aspx 文件。但是,这篇文章告诉您如何让它发挥作用。

更新

您可以在 Visual Studio 中进行更全面的搜索和替换。

Ctrl+Shift+H 向上打开对话框。

然后选择“查找范围”下拉列表旁边的 ... 按钮以打开“选择搜索文件夹”对话框。

选择您的文件夹,然后进行搜索和替换(或者只是搜索)。

While it's not a plugin for Visual Studio Notepad++'s find (and replace) in files functionality seems to be solid.

You even get syntax highlighting of your code - though not for aspx files by default. However, this post tells you how to get it working.

UPDATE

You can get a more comprehensive search and replace from within Visual Studio.

Ctrl+Shift+H to go the the dialog up.

Then select the ... button next to the "Look in" drop down to get the "Choose Search Folders" dialog.

Pick your folder and then do your search and replace (or just search even).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文