Rajaram Shelar
Rajaram Shelar

Reputation: 7877

Find text in VS including .sln and .csproj file

How to find text including .sln and .csproj? I wanted to search package version present in all the project. I have instance where package version is not captured in npm but is present in .csproj file and hence causes issues.

Upvotes: 19

Views: 8724

Answers (5)

David Liang
David Liang

Reputation: 21476

For me, switching Solutions and Folders view and doing the global search .csproj file types did the trick!

enter image description here

Searching among .csproj files only works when you're on Folder View.

Upvotes: 4

T.S.
T.S.

Reputation: 19330

Visual Studio has option called "Find in Files". You open the form, type your text you want to search for and you can actually set the file types. As example, if you want to search project files, solution files and code files, you can set filter as

*.??proj;*.sln;*.vb;*.cs;*.asax;*.ashx

We have mixture of c# and vb, so *.??proj covers all of them.

Click "Find All"

When your search is over, in the result window, click on the line and it will take you to the line in file where your match is found

Important Note

When field "Look in" is set to "Entire Solution" or "Current Project" or "All open documents" search will totally skip *.??proj files even if they are listed in filter. If you unload the project and open project file for edit, "Entire Solution" and "All open documents" options will search through opened project file.

Also keep in mind

Bugs have been reported to MS about functionality of Find in Files. Especially VS2017 is affected. So, based on the VS version you have, something may or may not work correctly. I know that subfolders feature was affected. I've seen this searching only 3 folders deep but not deeper. Here you can look at or report new bug

Upvotes: 11

tomRedox
tomRedox

Reputation: 30403

In VS:

Go to Edit > Find and Replace > Find in Files, which opens this screen:

enter image description here

Then press the ellipsis button to the right of Look In that's circled in red above.

That opens a screen where you can select folders:

enter image description here

use the right arrow between the lists (circled in red) to select which folder(s) to search, choose the ones that contain the .proj or .sln files you want searched.

Press OK

Back on the Find and Replace screen you can add the filter (similar to that mentioned in the other answer) if you want just project files, e.g. .??proj;.sln;.asax;.ashx

enter image description here

And then finally the Find buttons will be enabled, hit Find All and that will return results that include project files:

enter image description here

NB: @T.S. just made the very good point that I have 'Display file names only' ticked in the screenshots. You don't need that to make this work, I had that ticked because I have minified files in my project and they cause the Find Results window to slow to a crawl if they are included in the search results!

Upvotes: 19

Ravi Kant Shivhare
Ravi Kant Shivhare

Reputation: 11

In Visual Studio:

  • open "Find in Files"
  • Under 'Find what:' enter the text you want to search
  • Under 'Look in:' click on ... 3 dots, it will open 'Choose Search Folders'
  • Select the respective folder of your solution from 'Available folders'
  • Once folder is identified, move it to right using > under 'Selected Folders:' and press 'OK'.
  • Now click on 'Find All' in Search popup.

It will search the text in all files including .sln and .csproj files.

Upvotes: 1

asdf_enel_hak
asdf_enel_hak

Reputation: 7630

You can do search in project items in visual studio. The only way to search in csproj and sln files you should do use for example windows explorer. this may be helpful

Upvotes: -1

Related Questions