Visual Studio 宏:查找项目中未包含的文件?
我想编写一个宏来爬行项目目录中的文件并查找项目中未包含的文件。
在使用 DTE 对象时,我发现 Project
对象具有 ProjectItems
;如果 ProjectItem
代表一个目录,则它有自己的 ProjectItems
集合。这为我提供了项目中包含的所有文件。
因此,我可以递归地爬行每个 ProjectItems 集合,并且对于作为目录的每个 ProjectItem,检查文件系统中是否存在没有相应 ProjectItem 的文件。但这似乎很笨拙。
有什么更简单的方法来解决这个问题吗?
I'd like to write a macro to crawl through the files in my project directory and find files that aren't included in the project.
In playing around with the DTE object, I see that the Project
object has ProjectItems
; if a ProjectItem
represents a directory, then it has its own ProjectItems
collection. This gives me all files that are included in the project.
So I could crawl recursively through each ProjectItems collection, and for each ProjectItem that's a directory, check to see if there are files in the file system that don't have a corresponding ProjectItem. This seems clumsy, though.
Any ideas of a simpler way to approach this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是代码的 C# 版本:
Here is the C# version of your code:
感谢@JaredPar 和@lpthnc 为我指明了正确的方向。我最终使用了一种与上面@JaredPar 概述的方法非常相似的方法。这是我的工作宏 FWIW。
Thanks to @JaredPar and @lpthnc for pointing me in the right direction. I ended up using an approach very similar to what @JaredPar outlines above. Here's my working macro FWIW.
我将采取的方法是
这是一些示例代码
The approach I would take is to
Here is a quick bit of sample code
我会选择 PowerShell。我的另一篇文章中的 PowerShell 脚本将为您完成此操作。该脚本将从项目文件中获取包含文件的列表,并将其与磁盘上的文件进行比较。您将获得磁盘上但未包含在项目中的一组文件。您可以删除它们,也可以将它们作为 TFS 的删除挂起。
https://stackoverflow.com/a/23420956/846428
I'd go with PowerShell. The PowerShell script in my other post will do this for you. The script will get the list of included files from the project file and compare that against the files on disk. You will get the set of files that are on disk but not included in the project. You can either delete them or pend them as deletes for TFS.
https://stackoverflow.com/a/23420956/846428