파일에서 찾기 : Team Foundation Server에서 모든 코드 검색
특정 문자열 또는 정규식에 대해 TFS에있는 모든 파일의 최신 버전을 검색하는 방법이 있습니까? 이것은 아마도 Visual Source Safe에서 내가 놓친 유일한 것입니다 ...
현재 전체 코드베이스에서 최신 정보 얻기를 수행하고 Windows 검색을 사용하지만 75,000 개 파일에 1GB가 넘는 코드가 있으면 상당히 고통스러워집니다.
편집 : 언급 된 powertools를 시도했지만 "와일드 카드 검색"옵션이 내용이 아닌 파일 이름 만 검색하는 데 나타납니다.
업데이트 : 기존 MOSS (Search Server) 설치에 사용자 지정 검색 옵션을 구현했습니다.
Team Foundation Server 2015 (온-프레미스) 및 Visual Studio Team Services (클라우드 버전)에는 모든 코드 및 작업 항목 검색을위한 기본 제공 지원이 포함되어 있습니다.
foo
, 같은 부울 연산 foo OR bar
또는 다음 과 같은 더 복잡한 언어 관련 작업과 같은 간단한 문자열 검색을 수행 할 수 있습니다.class:WebRequest
자세한 내용은 https://www.visualstudio.com/en-us/docs/search/overview에서 확인할 수 있습니다.
제 경우에는 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;
}
}
}
더 매력적으로 보이는 또 다른 대안이 있습니다.
- 검색 서버 설정-모든 Windows 컴퓨터 / 서버 일 수 있습니다.
- 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
- Setup an indexing service/windows indexed search on the Search server for the root folder
- Expose a web service to return search results
Now with all the above setup, you have a few options for the client:
- 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)
- 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:
If you install TFS 2008 PowerTools you will get a "Find in Source Control" action in the Team Explorer right click menu.
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.
Okay,
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."
There is a Windows program with this functionality posted on CodePlex. I just installed and tested this and it works well.
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.
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.
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.
This add-in claims to have the functionality that I believe you seek:
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.
- cd "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE"
- 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.
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...
업데이트 2 : 이제 Microsoft에서 제공하는 확장 기능인 코드 검색 을 통해 코드와 작업 항목에서 검색 할 수 있습니다.
참고 URL : https://stackoverflow.com/questions/41039/find-in-files-search-all-code-in-team-foundation-server
'Programing' 카테고리의 다른 글
.gradle 폴더를 버전 관리에 추가해야합니까? (0) | 2020.08.21 |
---|---|
mingw-w64 스레드 : posix 대 win32 (0) | 2020.08.21 |
Google지도 : 사용자 지정 InfoWindow를 만드는 방법은 무엇입니까? (0) | 2020.08.21 |
VIM 또는 Gvim에서 UTF-8 문자를 보는 방법 (0) | 2020.08.21 |
WebConfigurationManager와 ConfigurationManager의 차이점은 무엇입니까? (0) | 2020.08.21 |