I have seen several projects with the "Shader" folder in the Solution Explorer.
However, when I create one myself, I can only see "Header files", "Source files", "Resource files", and "External dependencies" folder.
Is there a way to tell Visual Studio I need a "Shader" folder because I'm going to use shaders?
If not, how can I create it manually?
Visual Studio has virtual folders called "Filters". These can map to real folders in the file system or you can just use them to define logical/conceptual groups of items inside your projects.
To create a filter under a project in Visual Studio, just right-click with the mouse on your project in the Solution Explorer, expand "Add" and click "New Filter". A new filter ("NewFilter1") will be created under your project which you can then rename as you like.
You can drag items from your project inside it in order to group them "logically" or you can right-click on your new filter and choose Add>Existing Item or Add>New Item. You can even nest multiple filters inside each other.
For example in your case, you would call this filter "Shader" and you can drag-and-drop all shader-related files inside it. This only affects your project and not the directory structure in the file system.
You can still create a "real" folder in the file system and then add files into it, which you can then reference in your project's filter.
Related
I need something similar to the resource system that Qt has.
Instead of writing the full path to the files and dragging them with the program, I would like to create a single file like Qt does and enter relative file paths.
I can't use Qt in my project, and using the. rc files that Visual Studio provides is very complex and cumbersome.
What can I use instead?
You might need the .resx Resource Files.
A way to create this is to open Visual Studio:
Right-click your project
Select Add | New Item
Select Resources File
Give it a name (e.g. Resources)
Click Add
You will now have a Resources file in your project with the name you provided, and it should auto-open the resources editor. If it doesn't, double-click it in the project.
In the top-left of the editor, click the "Strings v" drop down and select "Icons".
Drag your icon into this screen.
Rename it to whatever you want (e.g. something).
If you familiar with the QT Resource files you will get to use it in no time.
Source: How to create resx files
Brief doc: https://learn.microsoft.com/en-us/dotnet/framework/resources/creating-resource-files-for-desktop-apps
https://learn.microsoft.com/en-us/dotnet/framework/resources/working-with-resx-files-programmatically
In my file explorer, my C++ project folders are like this:
... -> Documents -> C++ -> Files . . . . Projects
[In C++ folder, there are two more folders, called Files and one called Projects. I keep all my games/projects in the Projects folder. Each game has its own folder inside.]
Now here's the problem: I want all my common functions (.cpp & .h) to stay in one file folder, so if I ever change it, it changes for all my games. I want to keep these in Files. Is there a way to achieve this, like #include [Directory]? I know I can keep a file in its own game, but I want these to be all changed easily, and my code does not need to be transferred between computers. Thanks
This is not the right way to do it. If you have functionality that is shared between different applications (games, in your case), make a library from them and include that library in all your projects.
Solution for Visual Studio (2017)
For Source Files:
In the solution explorer right click on Sourcefiles and click "Add"/"Add existing" and choose your file(s)
Setting Include directory:
In the solution Explorer right click on your "Project" and click Properties
On the top set "Configuration" to "All Configurations"
Choose in the lsit on the left "VC++ Directories"
Click on the Dropdown arrow on the row with "Include directories" (you might have to click once on the row for the arrow to appear
Click "edit"
Add one line for each include directory. Use the folder icon on the top to open the file explorer to choose the directories
I've never had a C++ project that has required organizing stuff in folders before, because I mostly use C# for everything, but now I have this kind of project. What I have done is right click on "Header Files" in the solution explorer, and looked for "Add Folder", but there is no such thing. However, there is something called a "Filter", and it appears to work like a folder, but I don't know if this is how C++ uses folders, or what. Is this the case, using filters as folders, or is there a way to make folders?
Thanks for your help.
You can use filters if you like. These place files into pseudo-folders based on their file extensions. By default, you get header files in "Header Files", source files in "Source Files", etc., but these are customizable, as you've found out.
However, if you prefer the Solution Explorer to reflect the file system, then that is an option as well. Just click the "Show All Files" button at the top of the Solution Explorer to toggle it on. The filters will no longer be active (although they'll still be saved with your project settings so that you can toggle them back on at any time), and you will see the folders exactly as they are in the file system. You can drag-and-drop files between folders, create new folders, and everything, just as you normally would.
(overcompressed JPG image stolen from Ben Williams' blog)
I prefer to keep the filters disabled and see the file system in the Solution Explorer. But I'm a control freakāI like files to be exactly where I put them.
The obvious drawback of this, of course, is that you'll see all files in your solution's directory on disk, even those that have not been added to your project/solution. Those that have not been included will appear grayed out or with a dotted outline, and can be easily included by right-clicking and selecting "Include In Project."
You can add projects to Visual Studio solution. Each project would be in separate folder. They also can be stored hierarchically.
I Use Visual Studio 2012 Professional and C++. When creating so called 'filters' and adding source files to them, the files in the solution explorer are divided into sub directories, while on the file system they are all in the same directory (the project directory)
Question: I want to add a file to a filter while at the same time adding it to the corresponding directory on the file system. How can this be accomplished other than manually moving files around?
One alternative would be to switch to "Show All Files" in Solution Explorer top menu.
This way you can move and manage files in folders.
Filters will not get used though.
The "Show All Files" solution did not work for me because in my case the source files were not located under the directory containing the project file.
I finally ended up with writing a VS extension which allows you to organize either the filter structure inside the project or the file structure on the disk automatically by invoking a command through the context menu. I thought some of you might be interested in that extension too:
https://github.com/reloZid/vc-fileutils
I know only this workaround: you create first the folder structure in windows explorer and then drag / drop the files / folder from windows explorer into the solution explorer of Visual Studio.
It will add them all as a "filter" to Visual Studio!
I am using visual studio 2010. My code is in C++ and my solution contains many projects and each project again contains multiple folders under it. Whenever I change a file it gets automatically selected in solution explorer as I have enabled the option "Track Active Item in Solution Explorer" in Tools->Options->Projects and Solutions->General. But after changing the file I have to manually select the project (this could be cumbersome as I have to scroll up and down due to many files present) and then right click on it and select "build". Is there any other simple way to do this?
You could assign a shortcut to Build.BuildSelection or Build.BuildOnlyProject
Go to Tools menu, then Options=>Environment=>Keyboard and enter Build.BuildSelection or Build.BuildOnlyProject in the Show commands containing search text area. Then assign two free shortcuts. Build.BuildSelection is for building the current file; Build.BuildOnlyProject will build its project.
I use ctrl-shift+b to build all the solution. I hate to use the mouse for those repetitive tasks.