How can I exclude these folders and files when searching a very large Visual Studio project? - visual-studio

I am trying to search a very large application with hundreds of folders and thousands of files using the Visual Studio "Find in files" feature. I want to search all C# files (*.cs) excluding:
View*.cs
*\UnitTests\*.cs
*\Archive\*.cs
I found How do I tell Visual Studio to exclude folders from the Find in Files? and responses, but due to the size of the application, adding each folder is not workable, nor is unchecking "Search subfolders":
New folders are added frequently so I'd rather have an exclude list instead of an include list so I don't miss anything.
Is there a "Not" operator syntax for file types? I tried ^, !, and | to no avail.

Did you try Ctrl + Shift + F which will give you following option.
In the search window you can select which folders to include in the search.
Alternatively if you have Git Bash installed and if your project is a git repo then easiest way is to use following command. I tested it with my project and it works fine with sub folders as well.
git ls-files -- '*.cs' ':!:*Test*.cs'
This will include *.cs file but exclude anything like *Test*.cs. You can change the pattern as per your requirement.

Related

Visual studio 2015 tfs add files to source control

I have the following issue-
On Team Explorer - Pending Changes there is an option that automatically detects added files to folders that are under source control. The problem is that more than 50,000 files are detected.
Is there any way to edit this list? to remove items I don't care about so it will be relevant when I do have files I want to add?
(I know I can add items in the Source Control but I want to make this option usable)
You can click the 'Detected' link to pop up the "Promote Candidate Changes" dialog, then select the files you want to check in to promote.
If you're using local workspaces, you can add a .tfignore file to ignore the files which you don't want to be detected in source control. eg: ignore by file extension .txt, then all the .txt files will be ignored in source control. They will not be detected.
Please see Customize which files are ignored by version control for details.
Please note that with TFVC you need to put .tfignore in every solution root.
.tfignore file rules The following rules apply to a .tfignore file:
# begins a comment line
The * and ? wildcards are supported.
A filespec is recursive unless prefixed by the \ character.
! negates a filespec (files that match the pattern are not ignored)
.tfignore file example
######################################
# Ignore .cpp files in the ProjA sub-folder and all its subfolders
ProjA\*.cpp
#
# Ignore .txt files in this folder
\*.txt
#
# Ignore .xml files in this folder and all its sub-folders
*.xml
#
# Ignore all files in the Temp sub-folder
\Temp
#
# Do not ignore .dll files in this folder nor in any of its sub-folders
!*.dll

gitignore file pattern not working

I have dynamic directory structure like,
dependency
a
b
c
d e
f
g
h
I want to ignore all files under dependency folder recursively except .xml files.
I am using below pattern to achieve the same.
dependencies/**
!dependencies/**/*.xml
But it seems it's not working for me. It's ignoring all the files but accepting only .xml files which are directly inside the dependency folder, not recursively. :(
I am using below environment.
OS : Windows 7(64 bit)
Git : 2.6.1.windows.1
Can anyone help me?
This should work:
You ignore everything but white-list the parent folders.
Then you can white-list files.
dependencies
!dependencies/**/
!dependencies/**/*.xml
As I mentioned in "How do I add files without dots in them (all extension-less files) to the gitignore file?", there is mainly one rule to remember with .gitignore:
It is not possible to re-include a file if a parent directory of that file is excluded.
That means, when you exclude everything ('*'), you have to white-list folders, before being able to white-list files.
Check if this is working with git check-ignore -v -- afile to see if it is ignored (and by which rule) or not.

Can Visual Studio read a set of include file paths from a text file for the Additional Include Directories?

I'm trying to figure out how to get Visual Studio to read a set of include files from a text file.
For example, I would like to create a text file called IncludePaths.txt that contains a list of include paths such as "/I ../../header"
I would then tell Visual Studio reference this file.
I believe you could do this by adding #IncludePaths.txt to the Additional Include Directory, but I cannot get this to work. I have seen this done in projects I have worked on in the past but I can't find any documentation or figure out the trick.
After a little more research and talking to a couple of other developers, I figured out the "trick"
1) Create a file called IncludePaths.txt next to my project file.
2) Add your include paths to this file...
/I "..\..\..\..\open\common\include"
/I "..\..\..\common\include"
/I "..\..\"
3) Go to Properties -> C++ -> Command Line
4) Under "Additional Options" add #IncludePaths.txt
Alternatively, you can use custom properties to get this to work too.

Is it possible to sort the Compile Sources list in the Build Phases section of an Xcode project?

I want to sort the files in the 'Compile Sources' section of my Xcode project according to their names. Is it possible?
Yes, you can reorder the Compile Sources section in Xcode, but not from the GUI - which is a shame considering that this is already version 6 of the IDE and they still haven't gotten around to this basic feature.
As A-Live said, you need to edit the project.pbxproj file within the yourproject.xcodeproj file. Use Finder to select the yourproject.xcodeproj file and then use the context menu to Show Package Contents. After that open the project.pbxproj file with a text editor.
Find the PBXSourcesBuildPhase section and copy everything between files = ( and ); into a new text file. Remove the leading tabs/spaces. Save that file somewhere on your disk. Open up a terminal and do this:
sort -bf -t " " -k 3 PBXSourcesBuildPhase.txt > PBXSourcesBuildPhase.sorted.txt
Open up the new PBXSourcesBuildPhase.sorted.txt file in your text editor, copy the sorted lines into the PBXSourcesBuildPhase section of your project.pbxproj (overwrite the lines that you previously copied) and save.
Now you should be able to see all the files sorted in the Compile Sources section in Xcode.
I've tested this in Xcode 6.0.1 with a small project (~150 source files) and had no problems.
Careful: you should make a backup of your project file (or better: use version control) before you try this. Just in case.
I reckon it is a shame that this is not possible.
as a workaround in most of situations, you can use the search filter on the right upper corner of the file list.
for example, I needed to add a compiler flag in many files which (fortunately) all started with the same prefix. to do so, as stated here, you have to double click on a file.
then, I filtered the files for the prefix, shift-clicked them in order to select them all, then released shift and double-clicked one of them. this way I was able to add the flag to all of the files at once
The accepted solution works fine, but it requires manual steps(open the project file, find the section for the target that you want etc.) so it is a little cumbersome and it can not be automated if you need to keep the section sorted each time you perform a build or commit.
I faced with the same problem and I created a ruby script to sort these sections. The script sorts the 'Compile Sources', 'Copy Bundle Resources’ and all the 'Copy files' sections under Build Phase for a specified or all the targets.
#!/usr/bin/env ruby
require 'xcodeproj'
require 'set'
project_file, target_name = ARGV
# open the project
project = Xcodeproj::Project.open(project_file)
# find the target
targets_to_sort = project.native_targets.select { |x| x.name == target_name || target_name.nil? }
phases_to_sort = [Xcodeproj::Project::Object::PBXSourcesBuildPhase, Xcodeproj::Project::Object::PBXCopyFilesBuildPhase, Xcodeproj::Project::Object::PBXResourcesBuildPhase]
targets_to_sort.each do |target|
puts "sorting files for target #{target.name}"
phases_to_sort.each do |phase_to_sort|
target.build_phases.select { |x| x.class == phase_to_sort }.each do |phase|
phase.files.sort! { |l, r| l.display_name <=> r.display_name }
end
end
end
puts 'saving project'
project.save
To sort all targets:
./sort_sources.rb MyProject.xcodeproj
Or to sort only one target:
./sort_sources.rb MyProject.xcodeproj My_Target
It requires the gem xcodeproj:
gem install xcodeproj
This is thoroughly answered, but I thought I'd share the Emacs command that sorted these in place for me. Navigate to project.pbxproj, mark all files under PBXSourcesBuildPhase, and use the command:
M-3 M-x sort-fields
...aka sorting the marked area by the 3rd column, which happens to be the filenames. C-x C-s and you're on your way.
You can reorder the entries of PBXSourcesBuildPhase section at the project.pbxproj, it worked for me but of course there's no guarantee in general for it to work. Don't forget to backup your backups first.

How can I make Textmate always ignore the /log folder in the "Find in Project" search?

How can I make Textmate always ignore the /log folder in the "Find in Project" search?
Add the log folder to the excludeInFolderSearch option in your ~/.tm_properties file, e.g.:
excludeInFolderSearch = "{$excludeInFolderSearch,$extraExcludes,log}"
I found a easier way to do it.
Go to Settings > Advanced > Folder References
And add |log| to the pattern.
valid for TextMate 1
Other answers did not work for me on TextMate 2.0-beta.12. After many frustrating attempts, this line was able to exclude the log, vendor, tmp and .git directories from fuzzy searching.
excludeInFileChooser = "{$excludeInFileChooser,log,vendor,tmp,.git}"
I added this line to a .tm_properties file in my project directory. I verified that this also works if you decide to put the .tm_properties in the home directory.
Edit:
Use excludeInFileChooser for modifying search paths in Textmate's "Go To File" navigation feature, which is activated by ⌘T.
Use excludeInFolderSearch for modifying paths when searching for text within the files of a directory, which is activated by either ⌘F or ⌘↑F
None of these worked for me. What worked was adding the following in a .tm_properties file (project root)
excludeDirectories = "{node_modules,}"
No $exclude variable. Add trailing comma.
For Textmate 2:
Click on the top menu Textmate, then Preferences.
Navigate to the second tab, called Projects.
On the "Exclude files matching" just add 'log' to the end of the list, for example:
{*.{o,pyc},Icon\r,CVS,_darcs,_MTN,\{arch\},blib,*\~.nib,tmp,log}
This should do it, the log folder should no longer be searched, or used as match when opening a file.
Use AckMate, https://github.com/protocool/AckMate and read hot to change the normal Find in Project Shift+Cmd+F here github.com/protocool/AckMate/wiki/Usage
Alternatively you could explicitly tell Mate to look at a specific subset of folders.
~/project/mate app db models
Project find will be restricted to those folders.
Or to just remove the log dir you could add an alias to ~/.profile:
alias m="ls | grep -v 'log' | xargs mate"
Just remove reference to log folder from project tree.
Also you may right click on *.log files and mark then as binary (they will not be searched).
http://wiki.macromates.com/Troubleshooting/FindInProject
For TextMate2 it should be: excludeDirectories = "{$excludeDirectories,log}"

Resources