Code Search using Visual Studio Team Services a.k.a VSO
Posted by: Gouri Sohoni
in Category VSTS & TFS (Azure DevOps)
Abstract: Code Search is a cool feature available only with Visual Studio Team Services a.k.a Visual Studio Online. It allows you to search code across TFVS and Git projects in Visual Studio Team Services.
Code Search is a new feature to search code across TFVS (Team Foundation Version Control) and Git projects in Visual Studio Team Services. It is scoped to your VS Team Services account you apply. It provides full text search as well as allows you to search for specific contexts like class definitions, comments etc.
In case you are wondering if Visual Studio Team Services is a new product, please note that Visual Studio Online (VSO) has been renamed to Visual Studio Team Services or also known as VS Team Services (VSTS). VSO as a name was a little confusing as people used to think it is something related to Visual Studio, but actually it was TFS as a service in the cloud. Apart from the name change everything basically remains same.
Installing Code Search
Code Search is available in the Visual Studio market place as a free download and install. As the feature is only available with VS Team Services, you need to apply it for all or a particular VSTS account. In order to install it you can go to https://marketplace.visualstudio.com/ select the tab for Visual Studio Team Services and you get Code Search.
You can also go to market place from your Visual Studio Team Services account by selecting a small icon from right hand corner as shown below
Once you click on Install and select the account for which to apply, it checks for permissions. If you are account administrator it will immediately allow to install and apply, but otherwise it requests for installation. This request is sent to account administrator which can be verified by him/her and approved. This Code Search feature is available as one of the extensions for VSTS.
Once you have installed the feature, it will take some time to index your projects before you can actually start using it. Please wait till the indexing is complete to try how it works.
After installing Code Search for an account you will get a text box on the right hand side as shown below
The key features provided by Code Search are as follows:
- Full Text search across all non-binary files
- Query can be added with filters like by code type, projects, file names, file extensions.
- The operators like AND OR NOT can be used
- Provides integration with Version Control in terms of
- Tracing who changed the line of code
- Tracking change history
- File permissions checks
Searching Code with Code Search
Let us see code search in action. Enter the keyword to be searched in the text and click on enter. The default behaviour is to show all the occurrences across all projects within the current account.
If we select a particular project, it shows the path under which the code belongs
Right clicking on the search string will bring up the following menu:
Selecting Command Palette provides options like the following:
We can filter it for a particular project or even refine the search by Code Type like Class, Comment, Definitions etc. as seen below. Let us select String Literal to refine the search
We can get various options to filter by clicking in the search text box
Clicking on annotate button will let us know the person who changed the code. The diagram also shows file extension added to the search.
You can also select the history tab to give more information as well as use Compare to compare between two changesets. Selecting a particular entry will take you to the actual changeset.
The boolean operators like AND, OR and NOT can be used for advanced search. Even wildcards like * and ? can be used.
Though Code Search provides a lot of features and Microsoft is constantly improving upon it, there are some limitations. It searches with the default branch (mostly mater). It searches only for files less than 10 MB. The filter works for C#, C and C++ code and support for other languages may be added in the near future.
Overall Code Search is a cool feature currently available only with Visual Studio Team Services a.k.a Visual Studio Online.
This article has been editorially reviewed by Suprotim Agarwal.
C# and .NET have been around for a very long time, but their constant growth means there’s always more to learn.
We at DotNetCurry are very excited to announce the The Absolutely Awesome Book on C# and .NET. This is a 500 pages concise technical eBook available in PDF, ePub (iPad), and Mobi (Kindle).
Organized around concepts, this eBook aims to provide a concise, yet solid foundation in C# and .NET, covering C# 6.0, C# 7.0 and .NET Core, with chapters on .NET Standard and the upcoming C# 8.0 too. Use these concepts to deepen your existing knowledge of C# and .NET, to have a solid grasp of the latest in C# and .NET OR to crack your next .NET Interview.
Click here to Explore the Table of Contents or Download Sample Chapters!