Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 767
Skurmedel Avatar asked Jan 19 '10 17:01

Skurmedel


People also ask

Where do I put source files in Visual Studio?

The source files of the demonstration application are stored in subfolders named after the file type (for example, bms, cbl, copybook, jcl) in the C:\MFETDUSER\Bankdemo\Sources directory. The Visual Studio project is in the C:\MFETDUSER\Bankdemo\Projects folder.

How do I change the source directory in Visual Studio?

In Visual Studio, click Tools > Options. Expand Projects and Solutions and click Locations. The Projects location field defines the default location for storing new projects. You can change this path if you are using a different working folder.

Is it good to place solution and project in the same directory?

NET will create a new solution with the same name as the project, placing the solution files in the same directory as the project. Although this works fine for small projects, it isn't well suited to more complex applications.

How do I add files to a Visual Studio project folder?

Adding FilesRight click the project or contained folder and choose Add | Existing Item... . Use Show All Files . Click on files or folders you would like to add to the project and choose Include In Project . Drag and drop files and folders from Windows Explorer.


2 Answers

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.

like image 150
stijn Avatar answered Oct 25 '22 01:10

stijn


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.

like image 36
chongo2002 Avatar answered Oct 25 '22 03:10

chongo2002