在文件中查找:搜索 Team Foundation Server 中的所有代码

发布于 2024-07-04 20:41:01 字数 294 浏览 16 评论 0原文

有没有办法在 TFS 中搜索每个文件的最新版本以查找特定字符串或正则表达式? 这可能是我从 Visual Source Safe 中错过的唯一一件事...

目前,我对整个代码库执行“获取最新”并使用 Windows 搜索,但是对于 75,000 个文件中超过 1GB 的代码,这会变得非常痛苦。

编辑:尝试了提到的强力工具,但“通配符搜索”选项似乎仅搜索文件名而不搜索内容。

更新:我们在现有的 MOSS(搜索服务器)安装中实现了自定义搜索选项。

Is there a way to search the latest version of every file in TFS for a specific string or regex? This is probably the only thing I miss from Visual Source Safe...

Currently I perform a Get Latest on the entire codebase and use Windows Search, but this gets quite painful with over 1GB of code in 75,000 files.

EDIT: Tried the powertools mentioned, but the "Wildcard Search" option appears to only search filenames and not contents.

UPDATE: We have implemented a customised search option in an existing MOSS (Search Server) installation.

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

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

发布评论

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

评论(12

风轻花落早 2024-07-11 20:41:06

此加载项声称具有我相信您寻求的功能:

Team Foundation Sidekicks

This add-in claims to have the functionality that I believe you seek:

Team Foundation Sidekicks

目前还没有办法开箱即用地执行此操作,但有一个用户语音建议添加它:http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2037649-implement-indexed- 。

虽然我怀疑这是否像拨动开关那么简单,但如果每个看过这个问题的人都投票支持它,MS 可能会实施一些措施

更新:只需阅读 Brian Harry 的博客,其中显示此请求已在他们的雷达范围内,并且 Visual Studio 的在线版本对使用 git 作为 vcs 的搜索的支持有限:http: //blogs.msdn.com/b/visualstudioalm/archive/2015/02/13/announcing-limited-preview-for-visual-studio-online-code-search.aspx。 由此看来,我认为可以公平地说这只是时间问题...

更新 2: 现在有一个 Microsoft 提供的扩展,代码搜索,支持在代码和工作项中进行搜索。

There is currently no way to do this out of the box, but there is a User Voice suggestion for adding it: http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2037649-implement-indexed-full-text-search-of-work-items

While I doubt it is as simple as flipping a switch, if everyone that has viewed this question voted for it, MS would probably implement something.

Update: Just read Brian Harry's blog, which shows this request as being on their radar, and the Online version of Visual Studio has limited support for searching where git is used as the vcs: http://blogs.msdn.com/b/visualstudioalm/archive/2015/02/13/announcing-limited-preview-for-visual-studio-online-code-search.aspx. From this I think it's fair to say it is just a matter of time...

Update 2: There is now a Microsoft provided extension,Code Search which enables searching in code as well as in work items.

蹲墙角沉默 2024-07-11 20:41:05

假设您有 Notepad++,一个经常被错过的功能是“在文件中查找”,该功能非常快并附带过滤器、正则表达式、替换和所有 N++ 功能。

Assuming you have Notepad++, an often-missed feature is 'Find in files', which is extremely fast and comes with filters, regular expressions, replace and all the N++ goodies.

风渺 2024-07-11 20:41:05

对文件链接的搜索解释了如何查找文件。我确实必须仔细考虑建议才能使其正常工作。

  1. cd "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE"
  2. tf dir "$/*.sql" /recursive /server:http://mytfsserver:8080/tfs

在cd命令的情况下,我执行cd命令是因为我正在寻找tf.exe文件。 从该目录开始比添加整个路径更容易。 现在我了解了如何进行这项工作,我将在引号中使用绝对路径。

在 tf 搜索的情况下,我从服务器的根目录开始搜索 $/ 并搜索以 sql 结尾的所有文件,即 *.sql< /代码>。 如果您不想从根目录开始,请改用 "$/myproject/*.sql"

哦! 这并不能解决问题的文件搜索部分,但我的谷歌搜索将我带到这里在其他链接中查找文件。

This search for a file link explains how to find a file. I did have to muck around with the advice to make it work.

  1. cd "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE"
  2. tf dir "$/*.sql" /recursive /server:http://mytfsserver:8080/tfs

In the case of the cd command, I performed the cd command because I was looking for the tf.exe file. It was easier to just start from that directory verses adding the whole path. Now that I understand how to make this work, I'd use the absolute path in quotes.

In case of the tf search, I started at the root of the server with $/ and I searched for all files that ended with sql i.e. *.sql. If you don't want to start at the root, then use "$/myproject/*.sql" instead.

Oh! This does not solve the search in file part of the question but my Google search brought me here to find files among other links.

梦冥 2024-07-11 20:41:04

另一种解决方案是使用“ctrl+shift+F”。 您可以将搜索位置更改为本地目录而不是解决方案或项目。 这将取代桌面搜索,您仍然需要获取最新的代码,但它允许您留在 Visual Studio 中进行搜索。

Another solution is to use "ctrl+shift+F". You can change the search location to a local directory rather than a solution or project. This will just take the place of the desktop search and you'll still need to get the latest code, but it will allow you to remain within Visual Studio to do your searching.

空袭的梦i 2024-07-11 20:41:04

从 TFS 2015 开始,现在可以使用 Code Search 插件实现这一点。 https://marketplace.visualstudio.com/items?itemName=ms.vss-code-search< /a>

搜索是通过 Web 界面完成的,不需要您将代码下载到本地计算机,这很好。

This is now possible as of TFS 2015 by using the Code Search plugin. https://marketplace.visualstudio.com/items?itemName=ms.vss-code-search

The search is done via the web interface, and does not require you to download the code to your local machine which is nice.

拧巴小姐 2024-07-11 20:41:04

我们已经为 Team Foundation Server 源代码控制(不是您提到的 SourceSafe)建立了一个解决方案,类似于 Grant 的建议; 预定的 TF Get、Search Server Express。 然而,用于 C# 文件(文本)的 IFilter 没有给出我们想要的结果,因此我们将源文件转换为 .htm 文件。 现在,我们可以向文件添加其他元数据,例如:

  • 作者(我们将其定义为最后签入文件的人)
  • 颜色编码(在我们的待办事项列表中)
  • 指示潜在设计问题的更改数量(在我们的待办事项中)列表)
  • 与 VSTS IDE 集成,如 Koders SmartSearch 功能
  • 等。

但是,我们更喜欢用于 TFS 源代码控制的协议处理程序,以及专用源代码 IFilter 以获得更有针对性的解决方案。

We have set up a solution for Team Foundation Server Source Control (not SourceSafe as you mention) similar to what Grant suggests; scheduled TF Get, Search Server Express. However the IFilter used for C# files (text) was not giving the results we wanted, so we convert source files to .htm files. We can now add additional meta-data to the files such as:

  • Author (we define it as the person that last checked in the file)
  • Color coding (on our todo-list)
  • Number of changes indicating potential design problems (on our todo-list)
  • Integrate with the VSTS IDE like Koders SmartSearch feature
  • etc.

We would however prefer a protocolhandler for TFS Source Control, and a dedicated source code IFilter for a much more targeted solution.

躲猫猫 2024-07-11 20:41:04

好的,

  1. TFS2008 Power Tools 没有在文件中查找功能。 “在源代码管理中查找工具提供了通过项目的状态或使用通配符表达式在源代码管理中查找文件和文件夹的功能。”

  2. CodePlex 上发布了具有此功能的 Windows 程序。 我刚刚安装并测试了它,它运行良好。

Okay,

  1. TFS2008 Power Tools do not have a find-in-files function. "The Find in Source Control tools provide the ability to locate files and folders in source control by the item’s status or with a wildcard expression."

  2. There is a Windows program with this functionality posted on CodePlex. I just installed and tested this and it works well.

何必那么矫情 2024-07-11 20:41:03

如果安装 TFS 2008 PowerTools,您将在团队资源管理器右键菜单中获得“在源代码管理中查找”操作。

TFS2008 电动工具

If you install TFS 2008 PowerTools you will get a "Find in Source Control" action in the Team Explorer right click menu.

TFS2008 Power Tools

温柔戏命师 2024-07-11 20:41:03

就我而言,用 C# 编写一个小实用程序很有帮助。
对我有帮助的链接 -
http://pascallaurin42.blogspot.com /2012/05/tfs-queries-searching-in-all-files-of.html

如何使用 tfs api 列出团队项目的文件?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;
using Microsoft.TeamFoundation.Framework.Client;
using System.IO;

namespace TFSSearch
{
class Program
{
    static string[] textPatterns = new[] { "void main(", "exception", "RegisterScript" };  //Text to search
    static string[] filePatterns = new[] { "*.cs", "*.xml", "*.config", "*.asp", "*.aspx", "*.js", "*.htm", "*.html", 
                                           "*.vb", "*.asax", "*.ashx", "*.asmx", "*.ascx", "*.master", "*.svc"}; //file extensions

    static void Main(string[] args)
    {
        try
        {
            var tfs = TfsTeamProjectCollectionFactory
             .GetTeamProjectCollection(new Uri("http://{tfsserver}:8080/tfs/}")); // one some servers you also need to add collection path (if it not the default collection)

            tfs.EnsureAuthenticated();

            var versionControl = tfs.GetService<VersionControlServer>();


            StreamWriter outputFile = new StreamWriter(@"C:\Find.txt");
            var allProjs = versionControl.GetAllTeamProjects(true);
            foreach (var teamProj in allProjs)
            {
                foreach (var filePattern in filePatterns)
                {
                    var items = versionControl.GetItems(teamProj.ServerItem + "/" + filePattern, RecursionType.Full).Items
                                .Where(i => !i.ServerItem.Contains("_ReSharper"));  //skipping resharper stuff
                    foreach (var item in items)
                    {
                        List<string> lines = SearchInFile(item);
                        if (lines.Count > 0)
                        {
                            outputFile.WriteLine("FILE:" + item.ServerItem);
                            outputFile.WriteLine(lines.Count.ToString() + " occurence(s) found.");
                            outputFile.WriteLine();
                        }
                        foreach (string line in lines)
                        {
                            outputFile.WriteLine(line);
                        }
                        if (lines.Count > 0)
                        {
                            outputFile.WriteLine();
                        }
                    }
                }
                outputFile.Flush();
            }
        }
        catch (Exception e)
        {
            string ex = e.Message;
            Console.WriteLine("!!EXCEPTION: " + e.Message);
            Console.WriteLine("Continuing... ");
        }
        Console.WriteLine("========");
        Console.Read();
    }

    // Define other methods and classes here
    private static List<string> SearchInFile(Item file)
    {
        var result = new List<string>();

        try
        {
            var stream = new StreamReader(file.DownloadFile(), Encoding.Default);

            var line = stream.ReadLine();
            var lineIndex = 0;

            while (!stream.EndOfStream)
            {
                if (textPatterns.Any(p => line.IndexOf(p, StringComparison.OrdinalIgnoreCase) >= 0))
                    result.Add("=== Line " + lineIndex + ": " + line.Trim());

                line = stream.ReadLine();
                lineIndex++;
            }
        }
        catch (Exception e)
        {
            string ex = e.Message;
            Console.WriteLine("!!EXCEPTION: " + e.Message);
            Console.WriteLine("Continuing... ");
        }

        return result;
    }
}
}

In my case, writing a small utility in C# helped.
Links that helped me -
http://pascallaurin42.blogspot.com/2012/05/tfs-queries-searching-in-all-files-of.html

How to list files of a team project using tfs api?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;
using Microsoft.TeamFoundation.Framework.Client;
using System.IO;

namespace TFSSearch
{
class Program
{
    static string[] textPatterns = new[] { "void main(", "exception", "RegisterScript" };  //Text to search
    static string[] filePatterns = new[] { "*.cs", "*.xml", "*.config", "*.asp", "*.aspx", "*.js", "*.htm", "*.html", 
                                           "*.vb", "*.asax", "*.ashx", "*.asmx", "*.ascx", "*.master", "*.svc"}; //file extensions

    static void Main(string[] args)
    {
        try
        {
            var tfs = TfsTeamProjectCollectionFactory
             .GetTeamProjectCollection(new Uri("http://{tfsserver}:8080/tfs/}")); // one some servers you also need to add collection path (if it not the default collection)

            tfs.EnsureAuthenticated();

            var versionControl = tfs.GetService<VersionControlServer>();


            StreamWriter outputFile = new StreamWriter(@"C:\Find.txt");
            var allProjs = versionControl.GetAllTeamProjects(true);
            foreach (var teamProj in allProjs)
            {
                foreach (var filePattern in filePatterns)
                {
                    var items = versionControl.GetItems(teamProj.ServerItem + "/" + filePattern, RecursionType.Full).Items
                                .Where(i => !i.ServerItem.Contains("_ReSharper"));  //skipping resharper stuff
                    foreach (var item in items)
                    {
                        List<string> lines = SearchInFile(item);
                        if (lines.Count > 0)
                        {
                            outputFile.WriteLine("FILE:" + item.ServerItem);
                            outputFile.WriteLine(lines.Count.ToString() + " occurence(s) found.");
                            outputFile.WriteLine();
                        }
                        foreach (string line in lines)
                        {
                            outputFile.WriteLine(line);
                        }
                        if (lines.Count > 0)
                        {
                            outputFile.WriteLine();
                        }
                    }
                }
                outputFile.Flush();
            }
        }
        catch (Exception e)
        {
            string ex = e.Message;
            Console.WriteLine("!!EXCEPTION: " + e.Message);
            Console.WriteLine("Continuing... ");
        }
        Console.WriteLine("========");
        Console.Read();
    }

    // Define other methods and classes here
    private static List<string> SearchInFile(Item file)
    {
        var result = new List<string>();

        try
        {
            var stream = new StreamReader(file.DownloadFile(), Encoding.Default);

            var line = stream.ReadLine();
            var lineIndex = 0;

            while (!stream.EndOfStream)
            {
                if (textPatterns.Any(p => line.IndexOf(p, StringComparison.OrdinalIgnoreCase) >= 0))
                    result.Add("=== Line " + lineIndex + ": " + line.Trim());

                line = stream.ReadLine();
                lineIndex++;
            }
        }
        catch (Exception e)
        {
            string ex = e.Message;
            Console.WriteLine("!!EXCEPTION: " + e.Message);
            Console.WriteLine("Continuing... ");
        }

        return result;
    }
}
}
尐籹人 2024-07-11 20:41:03

还有另一种替代解决方案,它似乎更有吸引力。

  1. 设置搜索服务器 - 可以是任何 Windows 计算机/服务器
  2. 设置 TFS 通知服务*
    (Bissubscribe) 获取、删除、
    每次签入时更新文件
    发生。 所以这是一个网络服务
    充当 TFS 上的侦听器
    服务器,并更新/同步文件
    以及搜索服务器上的文件夹。 - 这将显着提高准确性(实时搜索),并避免定期获取的一次性负载
  3. 设置索引服务/窗口
    搜索服务器上的索引搜索
    为根文件夹
  4. 暴露一个Web服务返回
    搜索结果

现在,完成上述所有设置后,您可以为客户端提供几个选项:

  1. 设置一个网页来调用搜索服务并格式化结果以显示在网页上 - 您还可以将此网页集成到 Visual Studio 中(通过宏)或加载项)
  2. 创建一个 Windows 客户端界面(winforms/wpf)来调用搜索服务并格式化结果并将其显示在 UI 上 - 您还可以通过 VSPackages 或加载项将此客户端工具集成到 Visual Studio 中

更新
我确实走了这条路,而且效果很好。 只是想补充一下。

参考链接:

  1. 使用此工具代替
    bissubscribe.exe
  2. 处理 TFS 事件
  3. 团队系统通知

There is another alternative solution, that seems to be more attractive.

  1. Setup a search server - could be any windows machine/server
  2. Setup a TFS notification service*
    (Bissubscribe) to get, delete,
    update files everytime a checkin
    happens. So this is a web service that
    acts like a listener on the TFS
    server, and updates/syncs the files
    and folders on the Search server. - this will dramatically improve the accuracy (live search), and avoid the one-time load of making periodic gets
  3. Setup an indexing service/windows
    indexed search on the Search server
    for the root folder
  4. Expose a web service to return
    search results

Now with all the above setup, you have a few options for the client:

  1. Setup a web page to call the search service and format the results to show on the webpage - you can also integrate this webpage inside visual studio (through a macro or a add-in)
  2. Create a windows client interface(winforms/wpf) to call the search service and format the results and show them on the UI - you can also integrate this client tool inside visual studio via VSPackages or add-in

Update:
I did go this route, and it has been working nicely. Just wanted to add to this.

Reference links:

  1. Use this tool instead of
    bissubscribe.exe
  2. Handling TFS events
  3. Team System Notifications
哑剧 2024-07-11 20:41:02

Team Foundation Server 2015(本地)和 Visual Studio Team Services(云版本)包含对所有代码和工作项搜索的内置支持。

您可以执行简单的字符串搜索(如 foo)、布尔运算(如 foo OR bar)或更复杂的特定于语言的操作(如 class:WebRequest

代码搜索过滤器语法的屏幕截图

您可以在这里阅读更多相关信息:https://www .visualstudio.com/en-us/docs/search/overview

Team Foundation Server 2015 (on-premises) and Visual Studio Team Services (cloud version) include built-in support for searching across all your code and work items.

You can do simple string searches like foo, boolean operations like foo OR bar or more complex language-specific things like class:WebRequest

screenshot of code search filter syntax

You can read more about it here: https://www.visualstudio.com/en-us/docs/search/overview

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