Mar*_*rie 100 tfs search visual-studio-2008 code-search-engine
有没有办法在TFS中搜索特定字符串或正则表达式的每个文件的最新版本?这可能是我唯一想念的Visual Source Safe ......
目前我在整个代码库上执行Get Latest并使用Windows Search,但是在75,000个文件中超过1GB的代码会非常痛苦.
编辑:尝试提到的powertools,但"通配符搜索"选项似乎只搜索文件名而不是内容.
更新:我们在现有的MOSS(Search Server)安装中实现了自定义搜索选项.
Gra*_*day 57
Team Foundation Server 2015(内部部署)和Visual Studio Team Services(云版本)包括对搜索所有代码和工作项的内置支持.
您可以执行简单的字符串搜索,例如foo布尔操作foo OR bar或更复杂的特定于语言的操作class:WebRequest
您可以在此处阅读更多相关信息:https://www.visualstudio.com/en-us/docs/search/overview
小智 14
就我而言,在C#中编写一个小实用程序是有帮助的.帮助我的链接 - http://pascallaurin42.blogspot.com/2012/05/tfs-queries-searching-in-all-files-of.html
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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
mar*_*kom 13
如果您安装TFS 2008 PowerTools,您将在团队资源管理器右键菜单中获得"在源代码管理中查找"操作.
Vin*_*Vin 13
还有另一种替代解决方案,似乎更具吸引力.
现在通过上述所有设置,您可以为客户端提供一些选项:
更新:我确实走了这条路,它一直很好用.只是想加入这个.
参考链接:
我们为Team Foundation Server源代码控制(不是你提到的SourceSafe)设置了一个类似于Grant建议的解决方案; 预定TF Get,Search Server Express.但是,用于C#文件(文本)的IFilter没有给出我们想要的结果,因此我们将源文件转换为.htm文件.我们现在可以向文件中添加其他元数据,例如:
但是,我们更喜欢TFS源代码控制的协议处理程序,以及专用的源代码IFilter,用于更具针对性的解决方案.
现在,通过使用Code Search插件,可以在TFS 2015中实现.https://marketplace.visualstudio.com/items?itemName=ms.vss-code-search
搜索是通过Web界面完成的,不需要您将代码下载到本地计算机,这很好.
| 归档时间: |
|
| 查看次数: |
101144 次 |
| 最近记录: |