Keep source files in an external directory in Visual Studio/C++ - visual-studio

Is there any way to instruct Visual Studio 2010 to keep my .h files and .cpp files separate from the project files and databases that VS generates to manage the project? Specifically, I would like to have a set up where the project files are in the VS install folder and the source files are in a completely separate folder in my Dropbox, and monitored by git.

You can put the .cpp and .h files wherever you want. A project file just lists the locations of the source files. Create the .cpp and .h files where you want them, perhaps with Notepad, and then use "Add Existing File" to add them to the project. (Right-click on the project name in Solution Explorer and choose "Add Existing File".)
Source files are represented in the project file using relative paths, so if both the sources and the projects are on the same disk drive, the sources will be represented something like "..\..\..\..\MyFiles\work\SuperCalc\Input\parser.cpp". If they're on a different drive, then they'll use absolute paths like "D:\MyFiles\work\SuperCalc\Input\parser.cpp".
A detailed example of a source file and build file layout which uses this technique is presented in this StackOverflow response about organizing Visual C++ source files. You may find it helpful.
As an aside, if you really want to store your project files in the VS install folder, which is under C:\Program Files\Microsoft Visual Studio 10.0", then you'll need to run VS in Administrator mode, because C:\Program Files is a protected directory.

Related

VSIX - include other application in package

How can we include a separate .NET application inside a VSIX package? Preferably in a subdirectory so that it doesn't interfere with DLLs of the Visual Studio extension itself (different versions). The application is available in the same solution, but for the same reason I van also not add a reference to it in the main project.
The intention is to run that application as a separate process, started by the extension. The extension will then connect to that application through WCF.
I'm pretty certain you just need to include the .EXE in your .VSIX. A .VSIX is just a .zip file, and you can include additional files into it by simply adding them to your project and setting the Include in VSIX property to true.
To confirm, try downloading something like the Azure Data Lake and Stream Analytics Tools VSIX to disk. (I mention this one because I noticed it installed a number of .EXE's under my C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\Extensions directory).
Once you have the .VSIX on disk, rename it as a .zip file and unzip, or view its contents with the windows explorer. Note that the extensions.vsixmanifest file contained in that .zip has no references or entries for any of the .exe files installed by that .VSIX. Which means, all you really need to do is include it in the .zip file.
Add a subfolder to your .VSIX project, copy the .exe there, add it to your project, set the Include In VISX property to true, and I suspect you'll be all set.
Sincerely,

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.

Add a bunch of non source code files to a vcxproj

I need to add a folder containing lots of Qml files into a visual studio project. (The folder has subfolders and I want to add every thing to the project)
I tried to drag & drop from Explorer (and with the "Show all Files" way) to add the containing folder but this ways work only for source files (.cpp, .h, ...)
Do you know how to add easly lots of non-source-code files into a visual studio project ?

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.

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