How can I include .pdf files when I publish but not in a search and replace in visual studio? - visual-studio

More specifically my problem is if I include a pdf in my project and set its build action to content so it gets copied to the server when I publish, is there a way to exclude it from visual studios search and replace feature. Would a post build action be a solution to this? I just don't want anybody to do a global search and replace in my project and mess up the pdfs...
I know I just said a mouth full so let me know if you need clarification. Thanks!!!

If you look in the section headed "Find options" in the find dialog, there is an option titled "Look at these file types". If you qualify the type as *.cs, it will only look in files with that extension. You can also enter multiple file extensions. As long as you don't include pdf files in that filter, it will not apply to them. An alternative is to define a folder set to search in by clicking the ... next to the folder combo. Put your PDF files into a sub-directory of your project and exclude that folder from the folder set.
Additionally, as you have said, not including them in the project and using a post-build event to copy them to the output would also work.
I would qualify though that you are trying to solve a problem that shouldn't really be a problem. The onus is on the developer doing a find and replace to take care in doing so, and to not replace the contents of files they don't intend to change in the first place. Find an replace can be a dangerous tool.

Related

How to locate a variable throughout the whole project in Visual Studio?

I have a C++ Visual Studio project, in which I wish to locate one particular constant throughout the whole project. That is, I want to locate that particular variable in every single file in my project, including all .cpp and .h.
A previous question seems to be relevant, but it is only able to locate the variable within ONE file.
How may I do it?
You can use Quick Find available on the Edit ► Find and Replace ► Quick Find menu. With my key bindings it is bound to Ctrl-F.
The Quick Find dialog box is shown in the upper right corner of the editor window. You can change where to search from the drop down. Normally you search in Current Document but you can change it to Entire Solution.
If you want to search .h files that are not part of your solution you can use Find in Files available on the Edit ► Find and Replace ► Find in Files menu. Here you can specify a scope that also includes files of a specific type in a folder.

Excluding specific files from Visual Studio search

Is it possible to exclude certain files from search in Visual Studio.
For example jquery.js is almost always polluting my search results with half result coming from that file.
I know you can white-list specific types, but when I want to search in .js extension is there solution for that?
Vote here for feature: https://developercommunity.visualstudio.com/idea/405990/code-search-exclude-files-from-search.html?inRegister=true
Altough it does not solve your problem it may help out a bit
Ctrl + Shift + F should trigger the Find and Replace window.
From there, click Result Options and select "Display file names only".
It won't have all the info you need but might make it easier to recognize the files.
In Visual Studio 2019 they modernized the "find in files" feature, now you can exclude files, file extensions and directories using an exclamation mark before the items to be excluded in the "File types" textbox, like this:
*.*;!jquery.js
another example:
!*\bin\*;!*\obj\*;!*\.*;!*.xml
More info: https://devblogs.microsoft.com/visualstudio/modernizing-find-in-files/
In Visual Studio 2017 there is a workaround: you can right-click a search result and then click Delete. I use it to eliminate the big minified files from the Find Results window.
I've got the same problem with unwanted .js files polluting the search result. Especially the minified versions (e.g. jquery.min.js) are really annoying since they consist of only one (1) single very very long line. All of that line is displayed line-wrapped in search result. Not ideal!
Possible solutions:
Since .js files are (normally) just static content, you should be able to name them as you like. Rename it to jquery.min.js.nosearch and include the file with <script type="text/javascript" src="jquery.min.js.nosearch"></script> in HTML.
Get these files from an CDN and delete your local files.
Exclude these files from the VS project, provided that you can handle the inclusion of them in an other way when needed, e.g. when deploying (and provided that you scope your search to solution/project, not folder).
From this answer there was an UltraFind extension, which unfortunately doesn't exist for newer than 2010 (but see thread for hack to "update" it to 2012)
It's not particularly elegant - I'd be reluctant to call it a solution to the question - but if you can have Visual Studio Code running side-by-side with VS201x, its Find and Replace feature is pretty sophisticated. If you're using Git for source control, it will exclude any files or folders found in .gitignore from its search results - this is great when used in conjunction with tools like LibMan. Failing that, you can always manually add files / folders to its "files to exclude" option when searching.

If i want to make a copy of my c# project in the same workspace how can i do it?

In other words lets say i have already completed a project using visual studio. Now i want to make a separate project that is identical to the already completed project(except for some future changes).
How can i do this while keeping the new project in the same workspace as the original without:
creating a new project and copy pasting code over
copy-pasting the folder that holds the project and changing the name of the folder
I'm asking because there must be a better way to do this than the two options above.
Right click on the solution and "Open Folder in File Explorer"
Copy the project folder
Rename the new Project folder
Open the new project folder and rename the .csproj file
Right click on the solution and "Add" "Existing Project" to the solution
Open the "Properties" for the new project
Under "Application", change the assembly name and default namespace
Select "Tools", "Create GUID", Option 6, "Copy"
Under Assembly information, change the name and product
Paste in the GUID and clear the "" suffix
Rename the namespace in the source files to reflect the new
namespace from above.
Depending on your needs, you could get by with a subset of these steps (e.g. steps 1 and 2), however, I think a complete copy requires all of the steps mentioned.
The second option is exactly what you should do: duplicate the folder containing your project and then rename it.
To make this work, you might also have to change the GUID used by the project to avoid clashes. Visual Studio is supposed to do this automatically if another project with the same GUID already exists in the solution. If something goes wrong, you can do it manually by editing the project file (it's the field called ProjectGUID). It's just a standard GUID value, so use any freely-available GUID generator like the one bundled with Visual Studio or one you find online.
Why should there be a better option than this? What would that "better" option look like? It's not like there's going to be a menu command for it, this isn't a very commonly used feature. Most programmers use a source control system that handles branching/duplicating for them automatically and [mostly] without pain.

How do you exclude .svn directories from search in Visual Studio?

I have to "look in:" a subfolder of the project because the entire project is very large and takes too long to search through.
I also have AnkhSVN installed and wonder if a setting in the plugin could help too.
If you use "Find in files" instead of the standard search, you can search a subfolder for file types you specify.
However, it's a lot easier to perform this kind of task using the Ultrafind add-on (http://visualstudiogallery.msdn.microsoft.com/9fa9fdd7-1c06-45e3-a9f3-0381caab8f94) which you can use to exclude specific file patterns.
Sadly, it seems that despite all the wonderful functionality of Visual Studio, the easiest way to omit .svn directories from searches is to use Windows Explorer to navigate to the .svn directory, right click the folder, go to Properties, and click the Hidden checkbox under Properties.
If you then re-open your Visual Studio solution, it should keep those files out of the searches.
A quick and dirty way is to simply include every other file type except .svn and .svn-base etc.
Try using this set of wildcards and add any other valid extensions beginning with S that you might need:
*.sql;*.svc;*.;*.?;*.??;*.a??;*.a???;*.a????;*.b??;*.b???;*.b????;*.c??;*.c???;*.c????;*.d??;*.d???;*.d????;*.e??;*.e???;*.e????;*.f??;*.f???;*.f????;*.g??;*.g???;*.g????;*.h??;*.h???;*.h????;*.i??;*.i???;*.i????;*.j??;*.j???;*.j????;*.k??;*.k???;*.k????;*.l??;*.l???;*.l????;*.m??;*.m???;*.m????;*.n??;*.n???;*.n????;*.o??;*.o???;*.o????;*.p??;*.p???;*.p????;*.q??;*.q???;*.q????;*.r??;*.r???;*.r????;*.t??;*.t???;*.t????;*.u??;*.u???;*.u????;*.v??;*.v???;*.v????;*.w??;*.w???;*.w????;*.x??;*.x???;*.x????;*.y??;*.y???;*.y????;*.z??;*.z???;*.z????;*.0??;*.0???;*.0????;*.1??;*.1???;*.1????;*.2??;*.2???;*.2????;*.3??;*.3???;*.3????;*.4??;*.4???;*.4????;*.5??;*.5???;*.5????;*.6??;*.6???;*.6????;*.7??;*.7???;*.7????;*.8??;*.8???;*.8????;*.9??;*.9???;*.9????;
(I had to use various combinations of ? instead of a single * because the final extension could still be .svn)

How is "Add Existing Item..." in Visual Studio meant to work?

I never use "Add existing item..." feature in Visual Studio's Solution Explorer because it is confusing:
it seems to me the way it should work is that if you have a Customer.cs file in Models directory, that you could choose "Add existing item", it would then show you which items exist in that directory an allow you to choose one. Instead, it opens a file dialogue to some seemingly random directory on your hard drive, and I'm not sure if it is going to make a copy of that file, or use it outside the solution, etc.
instead, if I want to "add an existimg item", I go into windows explorer, click file, CTRL-C, click folder in solution explorer, ctrl-v, and it is clear
Do others do it differently? Am I missing something about how "add existing item" in solution explorer is supposed to work?
The folder opens where-ever you last left it...
As for using this feature; by default (Add) it does IMO the least useful thing; copy the file. But if you notice, the add button is actually a drop-down; hit the down arrow and you can add a link to the file - i.e. leave it where it is and reference it by location (Add As Link).
The quick and easy way to do what you are trying to do (add an existing file that already exists within the folder in your project) is:
At the top of the Solution Explorer window is an icon/button for "Show All Files", enable it (if it is already enabled and the file you are looking for is not shown, click "Refresh"). Note that this setting is enabled on a per project basis.
Right click on the file that you want to include and select "Include in Project".
Add Existing file adds the file to the project. Keeping it in the project directory is something different and making it a part of the project is something different. By making it a part of the project, its entry is made in .csproj/.vcproj/etc and then further properties can be set of this file such as specifying a custom build step etc.
And No, it doesn't create a copy of the file in your current project's directory in case of a Visual C++ project. In case of a CSharp Project, it does create a copy.
e.g., I use this when I need to add a bitmap/png file in my project which I have gotten from an external source. I just copy the file to my project directory and then use Add Existing File to add this to the project.
I'm using it. I even didn't know it's possible to ctrl+c ctrl+v in solution explorer.
It's particulary handy, if you want to add something 'as link'.
I do use it but often I just add file as a link. That make it easier to maintain some common classes if you do not want to make full assembly out of them.
As far as my experience goes using this function, it does the same copy and paste that you are describing.

Resources