How can I tell Visual Studio to exclude folders from the Find in Files? - visual-studio

We use subversion so we have subfolders named _svn in our solution. Doing a Find in Files returns strings from these subfolders.
Is there any way to tell Visual Studio to ignore these files?

From "Find in Files", in "File Types" or "Look at these file types", you can use:
!*\ExcludeFolder\*
Example:
!*\bin\*;!*\obj\*;!*\.*;!*\ExcludeFolder\*

What you can do is to setup a set of folders that will be used for searching. In Find and Replace window, on the right hand side of "Look In" input you have a "Choose Search Folders" option where you can setup those sets of folders.
Just remember to turn off "Include sub folders" options if you have added root project folder.
If you don't have hundreds of folders this solution should work.

Never had an issue with the global find until we moved to Visual Studio 2017 and started with Angular + .net Core applications... (mostly problems with the HUGE node_modules folder being searched)
I found that using the MSBuild exclusion property DefaultItemExcludes is working fine to exclude from global find in Visual studio 2017..
I now by default open up the project file (.csproj) for a new core project in VS2017 and adjust the property as follows to exclude the node_modules (sometimes I add the wwwroot too):
<DefaultItemExcludes>$(DefaultItemExcludes);node_modules\**</DefaultItemExcludes>
See also
https://github.com/dotnet/cli/issues/7525 , there they advise to prepend the folders to exclude and seem to use a forward slash instead of backward slash, like this :
<PropertyGroup>
<DefaultItemExcludes>node_modules/**;$(DefaultItemExcludes)</DefaultItemExcludes>
</PropertyGroup>
Hope this helps anyone experiencing issues with VS2017 global find / search .

I had this problem when moving to Windows 10 using Visual Studio 2015 and TortoiseSVN. Previously the .svn folders were all hidden so did not appear in search results. To solve this I simply went to the folder properties in Windows Explorer and checked the 'Hidden' attribute for the .svn folder. After refreshing the folder view in Visual Studio the .svn folder no longer appeared and is ignored when using Find!

Instead of searching for files in a directory (your solution's directory, in this case), you could limit your search to the files that are part of the project or the solution. Those in the _svn directories will thus be ignored.

I found in Visual Studio 2017 especially when using Angular Cli that the generated javascript files or other build files can be added to your project sometimes unknowingly. This can cause several headaches including adding a bunch of files to the searches and really slowing things down, especially intellisense because it is searching all of the generated files on top of the source files.
The easiest way I have found to correct this is to simply right click on the build folder (i.e. {Project}/dist) and select Exclude from Project. This will remove the folder from the project but the generated contents will still be available for runtime, it is just hidden from the UI.
If you need to still see the files, you can show hidden directories and files by selecting Show all Files or
click on the Icon:
on the top of the Solution Explorer.
Basically you want to exclude all build folders from your project/solution.

I don't think you can set this (after all, you are asking for "Entire Solution" search), but often you can remove the folder from the project / hide the directory in filesystem (for Web Site project type).

If you are not using VS2019 or VS Code (for which the solution has already been found in other answers), as a workaround you can use the search in Far Manager, it supports masks to exclude certain files or folders from the search.

Related

Excluding files in Visual Studio project

I've search everywhere for this, but have yet to find the answer.
I have a VS2012 project with thousands of files and folders I wish to exclude from the project as I don't need them to build any longer. Clicking on the folder and choosing Exclude From Project works, but takes literally forever - at times it appears Visual Studio has stopped running and I have to kill the process.
Question: What is Visual Studio actually doing to exclude a file from a project? Is there a way to simply go into the project file and exclude the files by folder? My project file does not appear to store this information. Where are excluded files defined for the project?
You can open the project file (in s text editor, i.e. Notepad) and remove the lines with the files that you want to exclude.
You can also do that in visual studio but you first need to unload the project (right-click on the project, unload)
Delete the folder in VS which has project to unload then restore it from recycle bin.
It works for me.

Visual Studio dotted folder

In the Visual Studio (2010) Solution Explorer, what do the dotted "ghost" folders mean? I can still open them up and open contents within them, so how do they differ from the rest of the normal yellow folders? My reason for asking is that currently my project is missing a file that it expects to be in one of the dotted folders, so I was hoping that some insight into exactly what they mean would be helpful.
Thanks!
Also this can refer to a file/folder that is not included in the project. This can be included by right clicking and selecting 'Include In Project'.
It means it is showing you a file or folder that typically would be hidden by Visual Studio. For example, the bin folder isn't something you typically interface with directly - when you build in VS, it adds the files into the bin folder. So, you don't really need to have access to it as it doesn't contain any editable files. However, it does still exist within the directory.

adding multiple existing folders and multiple existing files to Visual Studio project in single step

Does anyone have a way to add multiple folders and (existing) files within those folders to a Visual Studio project in a single step (or via macro)? Let's assume all of the folders and files were copied/pasted into the project folder where they need to reside relative to the project folder, but are not actually stored in the .csproj or .vbproj file, which I believe is a requirement to compile those files into the solution/project.
This works great if you have a web application project in your solution, but not so well if you have a .csproj or .vbproj. In that case, you must manually add folders (and nested folders), and add existing files and browse to each one individually, which can take a long time.
In the solution explorer, select the project, click the "Show All Files" button - .
This will show all the files, even those not part of the project. You can now select all of these in the solution explorer (using Ctrl + Click) then right click and go to "Include In Project".
In Visual Studio 2013 (and possibly earlier) you drag the folder from windows explorer and drop it on the project in the solution explorer.
Other answer given in this thread wouldn't work for me as the files I want to add (DTSX files) are in a different folder, and copying/moving them causes other problems. Here is what worked for me:
Using Visual Studio 2015, use Windows Explorer to locate the files you want to add to your project. Copy those files to the clipboard. If DTSX files are what you are dealing with, in the Solution Explorer right-click on SSIS Packages, and then click on Paste.

VS 2010: Add as Link a complete directory of XML to a solution Folder? (no project exists at this level)

I need to add (as link) a complete directory structure that lives under my solution folder but not under any project folder.
Is this possible, i can't seem to find it.
I suppose 1 option is to add a new project type and then add these files under that project..
But it seems not a good way, what type of project type do i add, a c# class project? The files i wish to include are standard XML files and nothing to do with C#
Any ideas or i get around this?
This is possible in Visual Studio 2010 Professional and above. You can add a solution folder and then include files within that folder. Just right click the solution in the Solution Explorer and choose Add|New Solution Folder. Once the folder is added, right-click it and select Add|Existing Item... to add each of the files that you want to access from that folder.
Solution folders are symbolic (i.e. they don't have to map to a single physical location) so you can store shortcuts to files from many different file system locations under the same solution folder.

Make Visual Studio's Find in Files default to the project directory?

I have many different branches/checkouts of the same project code on my development machine. Each one is virtually the same except for various maintenance bug fixes or improvements I'm working on within each project.
The problem comes when I use Find in Files inside Visual Studio to search through my code. VS2005 stores the last search directory that was used in its Find in Files dialog ... this may or may not be the project directory I'm working on. Since my projects are so similar, it's easy to accidentally search through a similar project, change some code, and only realize later that I've edited the wrong project. (Argh!!)
Is there a way to make VS default its Find in Files search to the project directory? Obviously a properties setting would be wonderful, but an add-in would be fine too.
This drives me nuts too. But in "Look In:" dropdown on the find in files dlg you will find items for Solution and project. I think that should work for you.
In VS2008, with no files open, when I select 'Current Project' it searches whatever project is currently selected in the Solution Explorer. When I switch between files in different projects, it correctly searches the project of the currently selected file. I don't see any options for changing this behavior.

Resources