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

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.

Related

Organizing project files in Visual Studio for better explorer view

I have a project in visual studio where there are several files arranged in folders (filters). Inside the project, everything is well organized, but as soon as I go to the explorer, I see that all the project files are in the same folder. How can I properly organize my project so that the repository doesn't look like a bunch of files in one folder?
I use Visual Studio 2022
I tried to manually decompose the files into folders, but when I did this, visual studio began to swear that it could not find the files
Can you share a screenshot of what you have and what you want?
I ask because there are two aspects to this.
The arrangement of projects within Solution Explorer
The arrangement of files within projects within Solution Explorer
The first can be controlled by adding solution folders. The structure is stored within the .sln file.
The second is generally a representation of the file system, depending upon your project type.
Also, make sure you're using the Solution Explorer view. Does this button appear clicked for you?
If so, you should unclick it. Solution Explorer can show you either the solution view (default, and what I refer to above) or the file system view.

Visual Studio Show All Files not working - not showing some folders and files

I've started a new project and I've copied and pasted in some test files from another project. Normally to include them in the project I'd toggle on the "Show all files" option in the solution explorer. However that isn't working and I can't work out why!
I've updated to the latest version of VS Professional 2019. I've restarted the application and my machine. I've deleted the sln file and rebuilt. I can exclude files - I just can't get them all to show! Below I've attached a screenshot of an empty project with two test files that should be showing but aren't.
Anyone know what I'm doing wrong? :(
"Show All Files" is a project level option. In a multi-project solution you would need to turn it on for each project in turn.
This was reported on the VS Developer Community here, with the suggestion that it be extended to work at the solution level as well. Microsoft's answer suggests that that's not expected to happen anytime soon: "although this is a very valid suggestion, at this time we are closing it as is not among the features we are able to fit into the near future roadmap".
Another way to show all files under the entire solution directory is to Switch View to Folder View using the dropdown next to Home, though this loses the project structure.

Visual Studio 2013: How to copy a project's properties to use in another project?

I tried to copy a project's properties to use in another project as instructed in the stackoverflow question Visual Studio: can I copy a project's properties to use in another project? but it does not work. When I open the created PropertySheet it seems that nothing is copied to it from the original property settings. The above link seems to be for VS 2008 but now I am using 2013. What might be the fault.
Caveat: Tested only on a relatively basic C++ project. But it worked!
Right click on your source project (in the solution explorer)
Unload project
Right click on your destination project and unload that as well.
Right click on each project and Edit {project}.vcxproj. The projects' configuration files can now be edited. (Yes you could also just find the file and edit it directly)
Copy/replace elements from the source to the destination.
Reload both projects. They should reload withut problems.
Tips:
If the reload did not work then copy/replace in pieces instead of the entire project to isolate the problem.
Don't replace the "ItemGroup" and the "Globals" PropertyGroup because these (XML) elements identify the projects in the context of the solution. But you should be able to copy/paste everything below these elements from the source .vcxproj file to the destination one without problems.
Try this on two "empty" projects before proceeding to your magnum opus. And definitely make a backup of your projects before trying this. (you are reading all of this before starting, right? Of course you are...)
This solution works better than others I have seen because it sets and unsets settings completely. It's a total replacement, not just an additive one.

how to share a folder between two projects in Visual studio 2010

If I have a project called 'testing' in project A.
How can I share that folder 'testing' for project B in visual studio 2010?
The reason I would like to achieve about this is because when I change something in the folder testing of project A, I dont want to change the same things in project B.
Thanks in advance.
Maybe too late for the person who asked the question, but this is for people with similar problems. You can share folder contents with an extention 'Project Linker':
This builds upon the concept of linked files where you refer to the same file from two projects. This extention handles the management of that for an entire project. If you add a file to the project, it will be added too to the other project as a linked file. Same for deletes...
Attention: you need to have both projects in the same solution for this to work of coarse...
Extention VS2015
I used it in VS2010 and it's also availible for later versions.
You can't share folders in Visual Studio - they are logical constructs that are part of a solution or project.
The closest you can get is to add folders to the projects you need to share on and add all the files that you want to share as links. You will still need to manually synchronize all adds/deletes of files, but updates will come across all projects.
To make things easier, you may want to write a Visual Studio macro that synchronizes these folders for you (you can bind these to keyboard shortcuts and/or menu items).
If you put your solution (*.sln) files in the same directory they can share files in sub directories.

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

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.

Resources