Wednesday, September 5, 2012

Find in Files : New feature of TFS Administrators Toolkit

The other day I was asked if it was possible to find out if a specific string ever had occurred in the source files of a specific project. As this is not possible in TFS out of the box today I said that it could probably be done in a couple of hours if needed.

Creating a search function    
Quite soon I was asked to put my money where my mouth was:) So I developed an Visual Studio Extension that, using the tfs api, would loop through each file and each file revision. As this would be a quite intense operation I placed it as a new feature in the TFS administrators Toolkit. I have some ideas to make it available as a standalone VS extension, extending source control explorer with a Find in File context menu, but at the moment it’s a TFS Administrators toolkit feature only.

Find in Files window
The result of my effort is the new Find in Files window in TFS Administrators Toolkit.  It enables you to search for text in the content of source controlled files.  Amongst its features is
•    Search files in source control matching selected wildcards
•    Option to search in History, searching through each file revision.
•    Option to search case sensitive or not
•    Option to search using Regular Expressions


Update!!! The Find in Files feature is availble in both VS 2010 and 2012. The 2012 version is updated with more features, as Search result prview, Source Control Explorer integration and more...

You can download the TFS Adminsitrators Toolkit from Visual Studio Gallery at

VS 2012 http://visualstudiogallery.msdn.microsoft.com/96a425aa-9ef0-4a92-b874-217d544a74bf
VS 2010 http://visualstudiogallery.msdn.microsoft.com/11f5e313-ced1-4713-9794-d7300c7d12e0

31 comments:

  1. It would be nice to have option to search one file history. Eg I have line of code that is missing somewhere between 50+ changes and I need to find what was the last changeset it was present...

    ReplyDelete
  2. You can do that by specifying the complete filname instead of a wildcard...
    Perhaps I can add a context menu and perhaps speed up the search if you only have a file selected.

    ReplyDelete
  3. Being able to actually view the files somehow directly from the results dialog would be very useful as well.

    Maybe a preview pane that loads each one as you click on the individual result, with highlighted search matches?

    ReplyDelete
    Replies
    1. Late update, Its done, hope you enjoy the new preview and open file features

      Delete
  4. Thanks for your suggestions, actually I’ve been thinking about going in that direction also.
    I created 2 work items based on you suggestions.
    For the preview feature I’ve actually started to build something, stay tuned…

    ReplyDelete
  5. Subscription is not working - no subscriptions can be found...

    If I specify a path and wildcards VS is crashing

    I deinstalled the extension

    ReplyDelete
  6. I have visual studio 2012 ultimate, connecting TFS 2010 server. After installing the extension http://visualstudiogallery.msdn.microsoft.com/96a425aa-9ef0-4a92-b874-217d544a74bf, I don't see the TFS adminstrator ToolKit option available in the context menu. Should I have admin rights?

    ReplyDelete
    Replies
    1. Have you restarted VS?
      Check if you have the menu as in http://i1.visualstudiogallery.msdn.s-msft.com/11f5e313-ced1-4713-9794-d7300c7d12e0/image/file/85254/1/vs2012_tfs_admin_menu2.png

      Delete
  7. I just downloaded the toolkit for VS2012. I'm a fan!

    Would you consider updating the FindInFiles to process multiple filename masks? We have a very large codebase and would like to search multiple file types without having to search gif, jpg, dll, etc. For instance, it would be extremely helpful to be able to put in a mask like this to search specific code file types:

    *.vb;*.cs;*.aspx;*.ascx;*.asmx;*.xsd;*.dbml

    Thanks,
    Jim Thorn

    ReplyDelete
    Replies
    1. HI Jim, and thank you for your kind words :)
      Actually my first reaction was that you could probably do it with the current version. The file mask is converted to a regexp and matched against the filename.

      Unfortunately it looks like the current code prevent it from working by escaping the input. But I added the capability to handle multiple file masks seperated with ;

      It’s changeset 103979 (http://tfsadmintoolkit.codeplex.com/SourceControl/changeset/103979
      ) if you want to build your own version and try it out.
      I’ll try to push a new version as soon as I checked some other feedback…

      Delete
    2. Thank you for such a quick response! Looking forward to trying the new version. Keep up the good work.
      Jim

      Delete
    3. Just released a minor update, so now you can try it out in an official release :)
      Also, if you like it, consider reviewing it at the Visual Studio Gallery

      Delete
    4. Works great. Dramatically cut the time to search the code base by including only the file types I want to search.
      Thanks,
      Jim

      Delete
  8. Thanks for the tool Mattis.
    The find file option is great but how does it search ?
    Does it look into the users workspace or the server workspace?
    Should I getlatest of the files?
    Should I be mapped to a particular folder?

    ReplyDelete
    Replies
    1. It doesn't search at all on your local disc! The tool fetches all files and file revisions directly from the server and performs the search directly in memory.
      So you don’t need to worry about what you got on your local file system, or fear that it will be changed by a search.

      Delete
  9. First of all, thank you so much for creating this tool. I was wondering if you would consider allowing a search on all source code within the entire collection rather than projects only?

    ReplyDelete
    Replies
    1. i have been trying to run this against numerous projects within a collection to search for references to a specific table. however, it frequently gets very far into the search and then errors out and restarts visual studio which causes me to lose the file locations already retrieved prior to the error. I'm not sure why it keeps getting errors, but it would be great if when it did, it simply displayed an error message instead of restarting vs and subsequently purging all of the search results in the process. Also, is there any way to export the search results to excel?

      Delete
    2. If your using the VS 2012 extension, you can search on all code in a collection by right clicking on the root node/Collection name in Source Control Explorer and select Find In Files...

      Delete
    3. Im truly sorry if it restart your VS doing the search, are you using the 2012 or 2010 extension ? If your running 2010, can you try the same with the 2012 extension.
      I will take a look if I got some error handling missing that could cause VS to restart.

      For exporting to Excel, you can mark all rows in the search result table and copy and past it to Excel

      Delete
    4. hi, thanks for your response. i am using tfs 2010 and the 2010 extension. i just tried to download the 2012 extension from this link, but when i attempt to install, i get an error that says the extension manifest is invalid.
      http://visualstudiogallery.msdn.microsoft.com/96a425aa-9ef0-4a92-b874-217d544a74bf

      Delete
    5. Strange, have you installed VS 2012 or TeamExplorer 2012 ? You need to have a 2012 client installed to use the 2012 extension (but you can still connect to your old tfs server)

      Delete
    6. i installed VS 2012 and your 2012 extension, and it worked great! thank you so much for publishing this.

      Delete
  10. Thanks for this great tool. I have not figured out how I can restrict it to only search in certain parts of TFS instead on the whole archive. We have a structure like $ABC/main, $ABC/Branch/123, $ABC/Branch/345, ... I want to search only in the $ABC/main part and not in all the branches. How to do this?

    ReplyDelete
  11. Thank you a lot for this great tool Matt. Is there any update of the tool (under VS 2010 & TFS 2008) or maybe a trick, to specify a teamproject branches/subdirectories. My teamproject contains a number of branches, and it takes a while to find a filecontent.

    Regards

    ReplyDelete
  12. I just installed your extension (VS2010 version) but I can't find the Find in Files dialog anywhere in the Source Control Explorer, am I looking in the wrong place? In Source Control Explorer I'm right clicking on a folder, but no FindInFiles anywhere.

    ReplyDelete
  13. I would be nice if the Find In Files dialog was not modal that way I could continue to work while it searches.

    ReplyDelete
    Replies
    1. I tried it, but I had a hard tim e getting it to a good experience, and didnt want to invest to much in it as Microsoft was working on a code search feature. I could take a swing at it again if I ever get an afternon free and dont have anything better to do :)

      Delete
  14. Can this be used to find a file that ONCE WAS in TFS but has been deleted? I know the name of the file, but don't remember where it was or when it existed. I would like to find the changeset where I deleted it within a collection.

    ReplyDelete
  15. Are there plans to update this for VS 2015 and TFS 2015?

    ReplyDelete
  16. I've installed TFS Administrators Toolkit in VS 2013 Professional. In the "Find In Files" section, how do I enter the project I would like to search? I cannot type in the "Search in" field and only one project (not the one I want) is displayed to choose from.

    ReplyDelete
  17. Hi I have downloaded the installed for TFSADMINTOOLKIT 2010, 2013, 2012 and 2017 however I am not able to start using them there is no .exe file to have it included in TFS, please help how to get started using this tool.

    ReplyDelete