有没有办法在TFS中的每个文件的最新版本中搜索特定的字符串或正则表达式?这可能是我在Visual Source Safe中唯一怀念的东西……
目前,我在整个代码库上执行Get Latest,并使用Windows搜索,但这对于75,000个文件中超过1 1GB的代码来说是相当痛苦的。
编辑:尝试了上面提到的powertools,但“通配符搜索”选项只搜索文件名,而不搜索内容。
更新:我们已经在现有的MOSS (搜索服务器)安装中实现了一个自定义的搜索选项。
发布于 2008-09-17 01:34:40
Team Foundation Server 2015 (内部部署)和Visual Studio Team Services (云版本)包括内置支持,可跨所有代码和工作项进行搜索。
您可以执行简单的字符串搜索(如foo )、布尔操作(如foo OR bar )或更复杂的特定于语言的操作(如class:WebRequest

你可以在这里阅读更多信息:https://www.visualstudio.com/en-us/docs/search/overview
发布于 2014-04-12 06:10:24
在我的例子中,用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?
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;
}
}
}发布于 2009-04-06 17:45:24
还有另一种解决方案,看起来更有吸引力。
设置一个搜索服务器-可以是任何windows machine/server
现在,通过以上所有设置,您可以为客户端提供以下几个选项:
将此客户端工具集成到visual studio中
更新:我确实走了这条路,而且运行得很好。只是想补充一下这个。
参考链接:
https://stackoverflow.com/questions/41039
复制相似问题