VSTS | TFS 2017
By using Code Search you can:
Search across all of your projects: Search in your own codebase and your partner teams' codebases. Use cross-project searches over all the code in your VSTS or TFS instance to search across your organization's entire codebase. Narrow your search by using project, repository, path, file name, and other filter operators. Use wildcards to widen your search and Boolean operators to fine-tune it.
Find specific types of code: Use code type filters to search for specific kinds of code such as definitions, references, functions, comments, strings, namespaces, and more. You can use Code Search to narrow down your results to exact code type matches. Navigate quickly to a method definition to understand its implementation simply by applying the definition filter, or scope the search to references in order to view calls and maximize code reuse.
Easily drill down or widen your search: When you find an item of interest, simply place the cursor on it and use the shortcut menu to quickly search for that text across all your projects and files. Easily trace how your code works by using the shortcut menu to search for related items such as definitions and references - directly from inside a file.
Syntax for simple and compound searches
Use simple search strings for words or phrases. The default is a whole word search; for example, a search for "valid" will not find instances of the word "validation". However, searches are not case-sensitive.
When you search from inside a project, the default is to search only within that project.
In a TFVC project, you see a list of folder paths in that project for which you have read access - you won't see any projects and folders for which you don't have read permission. Select paths in the folder tree to narrow your search if required.
In a Git project, you see a list of the repositories it contains (Code Search indexes files in only the default branch of your Git repositories; usually this is the master branch). Use the project and repository checkboxes to widen your search to more or all projects, or to narrow your search to fewer projects and repositories. If there is more than a few projects or repositories, use the Show more link to see them all.
Code Search remembers your last settings, such as the project and repository or path you searched in. Clear all the checkboxes to search across all projects. Do this quickly and easily with the Clear all links when you want to search in a different scope.
Narrow your search with Boolean operators
Narrow your search by using Boolean operators to combine search criteria.
Combine multiple search criteria using
NOT (they must be
Use parentheses to specify the precedence of the operations when you use more than
one Boolean operator. By default, a search combines all the words you enter using
AND operator so that it will return only files that contain all of the
words you entered.
validate AND revisitfinds files that contain both the words validate and revisit. Note that
ANDis the default operator, and so this is equivalent to the search string
validate OR revisitfinds files that contain either of the words validate or revisit.
validate NOT revisitfinds files that contain the word validate but not the word revisit.
(validate NOT revisit) OR "release delayed"finds files that contain the word validate but not the word revisit or files that contain the phrase release delayed.
To find an exact match to a set of words, enclose your search terms in double-quotes.
"Client not found"
Broaden your search with wildcards
Use the wildcard characters
? to broaden your search criteria. For
CodeSenseHttp*finds files containing words that start with CodeSenseHttp, such as CodeSenseHttpClient and CodeSenseHttpClientTest.
CodeX23?Rfinds files containing words that start with CodeX23, have any alphanumeric character next, and end with R. For example, CodeX234R and CodeX23QR.
You can use wildcard characters anywhere in your search string except as
a prefix in a simple search string or a query that uses a
code type filter.
For example, you cannot use a search query such as
class:?RequestHandler. However, you can use prefix wildcards with the
other search filter functions; for example, the search query strings
repo:?Handlers are valid.
You can use more than one
? wildcard to match more than one character.
No results found for ...
If there is a very large number of hits when using a wildcard search, such as when using a very simple wildcard search string, you may see a message that no matching files were found. In this case, narrow your search to reduce the number of matches. For example, specify more characters of the word(s) you want to find, or add a condition or filter to limit the number of possible matches.
Functions to find specific types of code
As you type in the search box, select functions and keywords from the drop-down list to quickly create your query. Use the Show more link to display all the available functions and keywords. Mix and match the functions as required.
You can also select one or a combination of filters from the list in the left column. Again, the Show more link displays all the available functions and keywords.
Alternatively, you can type the functions and parameters directly into the search box. The following table shows the full list of functions for selecting specific types or members in your C#, C, C++, Java, and Visual Basic.NET code.
|To find code where findThis appears as a ...||... search for argument arg:findThis|
|Class definition or declaration||class:findThis|
Functions to select projects, repositories, paths, and files
Functions make it easy to narrow the search to specified locations, specific types of files within these locations, or specified filenames. Mix and match the functions as required.
Narrow the search to a specific location using the
QueueJobsNow proj:Fabrikamfinds all occurrences of the word QueueJobsNow in the Fabrikam project.
QueueJobsNow repo:Contosofinds all occurrences of the word QueueJobsNow in the Contoso repository.
QueueJobsNow path:VisualStudio/Services/Frameworkfinds all occurrences of the word QueueJobsNow in the path VisualStudio/Services/Framework and its sub-paths.
- Enclose the argument to the filter in double-quotes if it contains a space.
QueueJobsNow path:"VisualStudio/Windows Phones and Devices/Services".
Narrow the search to specific files using the
QueueJobsNow file:queueRegister*finds all occurrences of the word QueueJobsNow in all files where the filename starts with queueRegister.
QueueJobsNow ext:csfinds all occurrences of the word QueueJobsNow in only C# source files.
- A plain text search string that does not include file type functions will also find files where the string matches part of the filename.
Find related items or other terms
One of the powerful features of Code Search is the capability to expand your search interactively, based on the results of previous searches. For example, you can easily broaden your search to related files when tracing or debugging code.
Place the insertion point on a term in the file and open the shortcut menu (mouse: right-click) to start a new search for other files containing the selected term. You can search for it as text, for the definition if you select an object name, or for references to a selected object.
Some more examples of search strings are:
You can find all instances of "ToDo" comments in your code simply by selecting
You can search in specific locations, such as within a particular path, by using a search string such as
You can search for files by name, such as
Driver file:GreenCabs.cs, or just by file extension. For example, the search string
error ext:resxcould be useful when you want to review all error strings in your code. But even if your plain text search string (without specific file type functions) matches part of a filename, the file appears in the list of found files.
You can combine two or more words by using Boolean operators; for example,
validate OR release.
You can find an exact match to a set of words by enclosing your search terms in double-quotes. For example,
"Client not found".
You can use the code type search functions with files written in C#, C, C++, Java, and Visual Basic.NET.
Open the search results in a new browser tab from either search box by pressing Ctrl + Enter or by holding Ctrl and clicking the icon. In Google Chrome, press Ctrl + Shift + Enter to switch the focus to the new browser tab.