Windows – way to add source files to visual studio project from command-line

command linevisual studio 2010windows

I want to use sublime to edit a visual studio project.
I have a custom build:

{
   "cmd": ["c:\\Windows\\Microsoft.NET\\Framework\\v4.0.30319\\MSBuild.exe"],
    "working_dir": "${project_path:${folder:${file_path}}}/../Project"
}

But if I add new files I also need to include them in the project.

Is there a way to do this from the command line, maybe at compile-time?

I am working with opengl using c++;

I basically set up a project using one of the examples provided on the opengl website.

Then I opened the project folder in sublime text and successfully compiled it using the custom build system.

However, when I add NEW source files to the project (*.h and *.cpp) I get a linking error.

I get the same error when I build in visual studio.

The error disappeared after I had included the files by manually browsing and adding them to the project.

What I wanted was a way to automatically add all the source files in a folder to the project(via command line, or wildcard or smth else).

This way I can easily work on a vs2010 project in sublime, add new source files and build the project.

Or maybe there already is a better workflow for this?

Best Answer

You could try to modify your .vcxproj file to include any .h and .cpp file in your project folder or folders below.

In case of a c++ VS project you can try to alter your .vcxproj file like this:

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <!-- rest of project file untouched -->

    <!-- start of modified part -->

    <ItemGroup>
        <ClInclude Include="**\*.h" />
    </ItemGroup>
    <ItemGroup>
        <ClCompile Include="**\*.cpp" />
    </ItemGroup>

    <!-- end of modified part -->

    <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
    <ImportGroup Label="ExtensionTargets">
    </ImportGroup>
</Project>

Be aware that adding files to your project from inside VS at later point will replace the modification described above!

As an alternative you could also create an external project file holding the same <ItemGroup /> elements described above and include this project file into your .vcxproj.

I'll add an example of this alternative if you're interested.