28

This question is similar to: Find in Files: Search all code in Team Foundation Server However it was asked 4 years ago. I'm asking specifically about TFS 2010 with VS 2010.

Has Microsoft finally got around to adding back the searching of files for code snippets like they had way back in Visual Source Safe? If so, how to enable it and use it?

I've tried adding in Microsoft's Power Tools. While it has a search feature, the search is only for file names and ignores looking in the content in the files. :(

Community
  • 1
  • 1
DMCS
  • 31,720
  • 14
  • 71
  • 104
  • Grant Holliday's answer from the TFS 2008 question you cite is still accurate for TFS 2010. One thing to note, your quote about *"adding back"* suggests that it existed once in TFS. I realize that a (rudimentary) search existed in VSS, but I want to specifically point out that VSS and TFS are two separate products and have no shared lineage. (That is to say that it's not the case that search once existed in TFS and we removed it.) – Edward Thomson Mar 28 '12 at 03:55
  • 1
    As stated in my question VSS had a great code search that will search thru code files for your query (nothing to install, it just came with it as a basic feature). TFS never came with it nor did MS allow you to get it as an add-on. The lineage is clear. This is Microsoft's source control product. Just because it changed names, doesn't mean they don't both store code, allow checkins and checkout, and version files. – DMCS Mar 29 '12 at 20:40
  • It didn't *change names*. They're completely different products. There is exactly zero code in common. – Edward Thomson Mar 29 '12 at 20:56
  • So let me get this straight. Visual Source Safe does not version code and files allowing checkout, checkins, locks, version comparison or is it TFS does not do those things? Are not both VSS and TFS the source control programs of choice to integrate with their respective versions of Microsofts's integrated development environments? (because oddly enough I've been using both of those over the last 13 years and they sure seem to purposed for it) – DMCS Mar 29 '12 at 23:50
  • I'm relatively certain that it's pointless to argue about this, but I never said that VSS wasn't a source control product. Again, my only point is that they're two separate products. If you want to continue this discussion (though I think we're arguing about two different things), I think chat would be more appropriate. – Edward Thomson Mar 30 '12 at 01:15
  • 2
    @EdwardThomson You're not looking at it from an end-user standpoint. Microsoft's source control solution has had a major piece of functionality removed - code search across versions. That's all the user understands, or needs to. – Craig Jan 22 '13 at 09:24

7 Answers7

26

I had the same problem and found this thread whilst looking for the solution. I then found that this functionality is available in a Visual Studio 2010 add-on called 'TFS Administrators Toolkit' in the Visual Studio Gallery. It seems to work!

MSDN links:

TFS Administrators Toolkit for VS 2010

TFS Administrators Toolkit for VS 2012

TFS Administrators Toolkit for VS 2013

F. P.
  • 5,018
  • 10
  • 55
  • 80
Craig
  • 1,277
  • 2
  • 16
  • 29
  • 1
    For Visual Studion 2013, [TFS Administrators Toolkit for VS 2013](https://visualstudiogallery.msdn.microsoft.com/33713c5d-31a3-44b3-ae94-3c413e6b21c7) – JohnC Jul 07 '15 at 11:40
5

There's nothing inbuilt, and it would be difficult to do this at the database level due to the way that TFS stores files as deltas from previous versions.

The way I see it, there are two viable options, but both only work for the "tip" revision of the code. The easiest way is to do a "get" of all of your source, then use either the findstr command in a command window, or use something like Windows Grep to do the searching.

Alternatively, you could do what one of our more enterprising developers did, and use Lucene to index your code, then put a nice front-end around the results. We have this set up to get our MAIN branch and DEV branch on a regular basis, so we can get near-real-time search results.

There are also products like CAST which do impact analysis, and allow you to do some degree of searching, but at that point, you're looking at dropping some decent gold pieces to get the product.

Robaticus
  • 22,857
  • 5
  • 54
  • 63
  • We have many many product development teams at my company. To have to download and keep the code from every single one of them stored locally is not viable. It'd be much cleaner to have the search work thru the place where the data is already stored. What you have answered are some great work-around fixes. +1 for your info. – DMCS Mar 29 '12 at 20:46
1

I'm not aware of anything that will do this.

The SourceSafe storage approach of 20 years ago was very basic, and the databases were limited to what we would now regard as "tiny" amounts of data. TFS stores compact differences between file versions, and there is no longer any "great big lump of text" that anyone can trivially search.

Any such tool would need to Get every version of every file to rebuild the original text to be searched, which would hammer your server for days or weeks. Add the testing overhead of producing a robust tool, and the chance of many people actually needing it, and it's not hard to see why it may never reach the top of the MS priority list - especially when they are still working on getting basic features like a usable pending checkins window, merge tools, and hopefully renaming of files(!) working for VS11.

It could be argued that with the automation model, or even just a console app calling tf.exe, writing a few lines of code yourself to iterate through all the versions of every file and apply a RegEx would be a relatively trivial task, if you really needed to apply such a search.

Jason Williams
  • 56,972
  • 11
  • 108
  • 137
  • "and it's not hard to see why it may never reach the top of the MS priority list - especially when they are still working on getting basic features like a usable pending check-ins window, merge tools, and hopefully renaming of files(!) working for VS11." -- With a company as large as Microsoft, it does take a lot of force to get even small things changed. It's not that small agile speed boat like it once was, now it's a huge cruise-liner that takes a lot of energy to get it to change it's direction. I also gave you a +1. – DMCS Mar 29 '12 at 23:55
1

I know how I did it years ago using PVCS Version manager. I had a trigger on checkin and add archive. This queued up a worker process that would pull the source code and use the cygwin / unix command updatedb to create an index of all the files. The building of the database would go to a temp database and then swap out the read database super fast once it was built.

Then I had a website with a search function that called locatedb to pull back the names of files that contained the text.

TFS has subscriptions that can invoke webserivces.

Christopher Painter
  • 54,556
  • 6
  • 63
  • 100
1

In case you do not want to roll your own solution, I've worked with Krugle for TFS before (only testing and evaluating it) at a previous company and found it to be a very good solution.

Edward Thomson
  • 74,857
  • 14
  • 158
  • 187
0

I check out the entire library (Latest Revision) and run this Powershell script:

C:\Users\username>powershell
Windows PowerShell
Copyright (C) 2013 Microsoft Corporation. All rights reserved.

PS C:\Users\username> cd C:\LocalDevelopment
PS C:\LocalDevelopment> get-childitem -include *.* -rec | select-string -pattern "a string" > a_string.txt

which is: Do a recursive search on all files in c:\LocalDevelopment for "a string" (add your string there, of course) and output the results to a text file.

Bob Probst
  • 9,533
  • 8
  • 32
  • 41
0

TFS doesn't provide that function out of the box, but you can use Powershell to combine existing TFS functions to get what you need.

My plan is to first use tf dir get a list of files, then use tf view to get files contents and finally feed the contents to Select-String to find the string (or regex) we are looking for.

You can start with:

tf dir /recursive $/

but that list is probably going to be huge, so try to restrict your search to a small scope, like:

tf dir /recursive $/some/path/*.cs

Next step is to transform the results of the previous step into a format that we can then feed into tf view. Here is a powershell script that does that:

(tf dir /recursive $/) -join "+" -replace ":", "" -replace "\+\+", "`n" -split "`n" | %{ $arr = $_ -split "\+"; $arr | select -Skip 1 | %{ $arr[0] + '/' + $_ } }

Now let's pipe the list into tf view and then Select-String:

... | %{ $file = $_ ; if (tf view "$file" /console | Select-String "some string") { Write-Host $file } }

Don't forget to change the part that says "some string".

Altogether, you get:

(tf dir /recursive $/) -join "+" -replace ":", "" -replace "\+\+", "`n" -split "`n" | %{ $arr = $_ -split "\+"; $arr | select -Skip 1 | %{ $arr[0] + '/' + $_ } } | %{ $file = $_ ; if (tf view "$file" /console | Select-String "some string") { Write-Host $file } }

Oh, and don't forget to replace the part that says "some string" with your actual search query.

Saintali
  • 4,482
  • 2
  • 29
  • 49