Visual Studio 2010, how to remove $(ProjectDir) from include path? - visual-studio-2010

My VC++ project is configured so that all source files are in $(ProjectDir)\source\ (which is in the include path). The annoyance is that somehow it seems that $(ProjectDir) is automatically put in the include path... which isn't a huge deal, every time I write a #include I get an intellisense popup with a lot of directories that don't even have header files in them. Any way to fix this?

In Project properties --> VC++ directories --> Include Directories you can manually set your include path without using the $(ProjectDir).

Related

How do I extract source code files from Visual Studio pollution?

In a directory where source code resides, there are also Visual Studio related files, like *.user, *.vcxproj. And Debug and Release folders.
I would like to change project directory layout so it looks like this:
For example, the project is named ProjectX.
In the ProjectX main folder, there would be only two subfolders:
ProjectX/Source
ProjectX/Build
In ProjectX/Source there would be all source code files, but nothing else.
In ProjectX/Build there would be all Visual Studio-related files.
How can I do it?
To move the vcxproj into the build directory, move the vcxproj into the build directory.
To move your source files under a source directory, move your source files under a source directory.
After either or both of the above steps, you'll need to re-add the files to Visual Studio, but I'm sure you knew that. Visual Studio isn't psychic and can't guess where your files are if you move everything around.
The SDF file can be moved by asking Stack Overflow how to move the SDF file: How to change ipch path in Visual Studio 2010
Visual Studio 2015 should not be creating .user files any more. Perhaps you're not fully updated?
At this point you have everything you wanted, even though it's weird. Except for portable projects, people aren't generally moving their vcxproj files. The vcxproj file is typically considered the root of the project, just like a makefile would be; under it is build and source.
Now let me give you advice. Don't do all of that. Do this instead:
Move your source files in a source directory. Now in Visual Studio, go to project properties and change Output Directory and Intermediate Directory to $(ProjectDir)Build\$(Platform)\$(Configuration)\
Now you have one Build directory instead of a Debug and Release directory. That means a lot to some people. It means more to people with more build configurations.

Visual Studio + Qt cleaning of generated files

When I press "Clean Solution" in Visual Studio 2008 for a Qt project all moc and ui header files from generatedfiles folder are cleaned.
I have one more my own generated *.h file in this folder, how to delete it too?
Where moc and ui headers file are deleted? I can't find any setting, with a option to add custom file except "Extension to Delete on Clean". But there is nothing about "generatedfiles".
And Project->Properties->Configuration Properties->General->Extensions to Delete on Clean can't be used in this case, because it ignores paths and recognize only extensions or file names.
The Visual Studio Qt Plugin is designed to put all files generated by uic, rcc and moc into a GeneratedFiles directory. Just like you stated, if you clean out the project, all of these generated files are also removed.
The files generated will be:
ui_*.h for all form files created with QtDesigner
qrc_*.cpp for all resource files created with QtResource
moc_*.h for all header files that contain Q_OBJECT
*.moc for all .cpp files that contain Q_OBJECT
The plugin is not designed to clean out any other files that you might put there yourself because it's not intelligent enough to know what your purpose with them is.
I would suggest that you put all your own header files somewhere else and delete them manually whenever you need to.

Visual Studio Makefile Project makes extraneous 'obj' folder

I'm using a Makefile project in Visual Studio 2012 express just fine. However, regardless of the Build Command specified, Visual Studio always makes an 'obj' folder containing empty subfolders obj\Win32\Debug and obj\Win32\Release.
To reproduce the problem, simply create a "Visual C++ - General - Makefile Project" and use a DOS command like 'dir' in the Build Command Line. As soon as you build, the empty obj\Win32\Debug folder will show up.
I can simply skip these in my Mercurial ignore file but it'd be nice to find a fix. Anyone know how to make Visual Studio not generate these empty folders?
Found a trick: to set the intermediate output directory on an existing directory. I modified the project file by hand and added this:
<IntermediateOutputPath>$(ProjectDir)</IntermediateOutputPath>
inside the configuration PropertyGroup. I used the project directory, which obviously already exists. No more useless obj directory!
The obj folder represents VS' own metadata about your project for intellisense support and designer support (for WF/WPF apps). For the most part you can ignore the folder completely without issue.
On occasion though this data can become corrupt and cause VS to show invalid Intellisense options and the workflow/WPF designer can cause errors. Closing VS and deleting the obj folder will quickly resolve this though.

VC++ Visual Studio added .hpp files in subdirectory but get "Error: cannot open source file ..."

This is driving me nuts - I've added a number of .hpp files in subdirectories in the root of an existing VC++ projects source directory.
Visual Studio complains "Error: cannot open source file ..." but if I right click on the and select open document, VS can display it.
I've tried:
"Rescan solution" which appears to do nothing.
Adding existing item (both on it's own and with a "filter" - which appears to be a directory?)
Closing the project and VStudio in the vain hope it would eventually discover the directories/files I'd added
VStudio complains it cannot find these files when it is capable of opening them? My question is simply this: "How can I add a directory containing source files to a VC++ project such that the linker/complier can see them?
(disclaimer; i've never used Visual Studio before or many Microsoft products, so am finding this all very alien)
Workaround;
Add the files to a directory outside of the project and then reference those directories in the "Additional Include Directories" in Properties -> Configuration Properties -> C/C++ -> General.
Why I can't add additional directories within the project and have Visual Studio rescan them (like an Eclipse refresh) is beyond me.
Please see the answer at the following question. This answer fixed the problem for me. It has to do with adding $(ProjectDir) in the "C/C++ Include Directory" in the project settings.
"Cannot open include file" error in VS2010
The answer linked above, fixed my issue with not being able to include subdirectory files inside of the project. I hope this helps anyone else having this issue.
Thanks,
first you need to include any header file you'd like to use into your cpp files by #include "path/file.hpp". in your case your probably didn't specify path, e.g. "subdir/file.hpp"

Storing source files outside project file directory in Visual Studio C++ 2009

Visual Studio projects assumes all files belonging to the project are situated in the same directory as the project file, or one underneath it.
For a particular project (in the non-Visual Studio sense) this is not what I want. I want to store the MSVC-specific files in another folder, because there might be other ways to build the application as well, for example with SCons. Also all the stuff MSVC splurts out clutters the source directory.
Example:
/source
/scons
/msvc <- here is where I want my MSVC-specific stuff
I can add the files, in Explorer, to the source directory manually, and then link them in Visual Studio with the project. It's not the end of the world, but it annoys me a bit that Visual Studio tries to dictate the folder structure of my project.
I was looking through the schemas for the project files but realized that this annoying assumption is in the IDE and not the format of the project files.
Do someone know a neater way to solve this than manually linking files to the project from the source directory?
I use this sometimes, pretty sure it's what you want:
make sure the Show All Files option is on in your solution explorer.
create a symlink that targets your source directory and put the link at the same level as your project, or even lower if you want finer control. The command is mklink /j target source
For the example project structure you show, you'd run mklink /msvc/source /source and in the project the source directory will show up as if it was in the project dir (well, actually it is). Additional bonus: adding new items through VS also automatically puts them in the right directory.
You can add files with links like this, they are searchable, view-able, but they do not checkout if you try to change them, also visual studio leaves the wildcards in place:
<ItemGroup>
<Content Include="..\Database Schema\Views\*.sql">
<Link>Views\*.sql</Link>
</Content>
</ItemGroup>
This goes inside the .proj file.

Resources