热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

在文件中查找:在TeamFoundationServer中搜索所有代码-FindinFiles:SearchallcodeinTeamFoundationServer

IsthereawaytosearchthelatestversionofeveryfileinTFSforaspecificstringorregex?Thi

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...

有没有办法在TFS中搜索特定字符串或正则表达式的每个文件的最新版本?这可能是我唯一想念的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.

目前我在整个代码库上执行Get Latest并使用Windows Search,但是在75,000个文件中超过1GB的代码会非常痛苦。

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

编辑:尝试了提到的powertools,但“通配符搜索”选项似乎只搜索文件名而不是内容。

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

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

12 个解决方案

#1


56  

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.

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

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

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

screenshot of code search filter syntax

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

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

#2


13  

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

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

  1. Setup a search server - could be any windows machine/server
  2. 设置搜索服务器 - 可以是任何Windows机器/服务器

  3. 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
  4. 设置TFS通知服务*(Bissubscribe)以在每次签入时获取,删除,更新文件。因此,这是一个Web服务,其作用类似于TFS服务器上的侦听器,并更新/同步搜索服务器上的文件和文件夹。 - 这将显着提高准确性(实时搜索),并避免一次性负载定期获取

  5. Setup an indexing service/windows indexed search on the Search server for the root folder
  6. 在搜索服务器上为根文件夹设置索引服务/ Windows索引搜索

  7. Expose a web service to return search results
  8. 公开Web服务以返回搜索结果

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. 设置一个网页来调用搜索服务并格式化结果以显示在网页上 - 您还可以将此网页集成到visual studio中(通过宏或加载项)

  3. 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
  4. 创建一个Windows客户端界面(winforms / wpf)来调用搜索服务并格式化结果并在UI上显示它们 - 您还可以通过VSPackage或加载项将此客户端工具集成到visual studio中

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. 使用此工具而不是bissubscribe.exe

  3. Handling TFS events
  4. 处理TFS事件

  5. Team System Notifications
  6. 团队系统通知

#3


13  

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

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

TFS2008 Power Tools

TFS2008电动工具

#4


10  

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

就我而言,在C#中编写一个小实用程序是有帮助的。帮助我的链接 - 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?

如何使用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"));

            tfs.EnsureAuthenticated();

            var versiOnControl= tfs.GetService();


            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 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 SearchInFile(Item file)
    {
        var result = new List();

        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;
    }
}
}

#5


6  

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:

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

  • 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
  • 与Koders SmartSearch功能一样集成VSTS IDE

  • etc.

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

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

#6


6  

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."

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

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

    在CodePlex上发布了一个具有此功能的Windows程序。我刚刚安装并测试了它,效果很好。

#7


6  

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

从TFS 2015开始,现在可以使用代码搜索插件。 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.

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

#8


3  

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.

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

#9


1  

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

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

Team Foundation Sidekicks

Team Foundation Sidekicks

#10


1  

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. cd“C:\ Program Files(x86)\ Microsoft Visual Studio 12.0 \ Common7 \ IDE”

  3. tf dir "$/*.sql" /recursive /server:http://mytfsserver:8080/tfs
  4. 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.

在cd命令的情况下,我执行了cd命令,因为我正在寻找tf.exe文件。从该目录开始并添加整个路径更容易。既然我明白了如何使这个工作,我会在引号中使用绝对路径。

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.

在tf搜索的情况下,我用$ /从服务器的根开始,然后我搜索了以sql结尾的所有文件,即* .sql。如果您不想从根目录开始,请改用“$ / myproject / * .sql”。

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.

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

#11


1  

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.

假设你有Notepad ++,一个经常遗漏的功能是“在文件中查找”,它非常快,并附带过滤器,正则表达式,替换和所有N ++好东西。

#12


1  

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

目前无法开箱即用,但有一个用户语音建议添加它:http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2037649-implement-indexed-全文检索用的工作项

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.

虽然我怀疑它就像翻转开关一样简单,但如果每个看过这个问题的人都投了票,那么MS可能会实现一些东西。

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...

更新:刚刚阅读Brian Harry的博客,该博客显示此请求正在他们的雷达上,并且Visual Studio的在线版本对搜索git用作vcs的搜索有限:http://blogs.msdn.com/b/ visualstudioalm /存档/ 2015/02/13 /宣布有限预览换视觉工作室在线代码search.aspx。从这一点来看,我认为这只是一个时间问题是公平的......

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

更新2:现在有一个Microsoft提供的扩展,代码搜索,可以搜索代码和工作项。


推荐阅读
author-avatar
APP精品限免大全_312
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有