Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 970
Rajaram Shelar Avatar asked Nov 16 '16 07:11

Rajaram Shelar


People also ask

How do I search for all text in Visual Studio?

How do I search all files in Visual Studio? Search across files# VS Code allows you to quickly search over all files in the currently opened folder. Press Ctrl+Shift+F and enter your search term.

How do you search an entire project in VS?

You can search across all files in the open folder with the following shortcuts. Use “Ctrl + Shift + F” for Windows and all other operating systems. For Mac, it's “Command + Shift + F”.

How do I read .sln files?

A file with . SLN extension represents a Visual Studio solution file that keeps information about the organization of projects in a solution file. The contents of such a solution file are written in plain text inside the file and can be observed/edited by opening the file in any text editor.

Should I include .sln file in Git?

Yes, you always want to include the . sln file, it includes the links to all the projects that are in the solution. Save this answer. Show activity on this post.


2 Answers

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!

like image 144
tomRedox Avatar answered Oct 03 '22 23:10

tomRedox


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

like image 42
T.S. Avatar answered Oct 03 '22 22:10

T.S.