1

Is there a way to programmatically add a source file to the project, given a file path?

I am trying to work on a visual studio project in sublime text 2. I can build using a custom build:

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

I can link libraries using #pragma comment(lib, "path to library")

I can include the new source files using #include ""

but I cannot add new source file to the project.

Is there any code that could do that?

In the end Filburt gave a brilliant answer here: Is there a way to add source files to visual studio project from command-line?

Community
  • 1
  • 1
Vlad Otrocol
  • 2,952
  • 7
  • 33
  • 55

1 Answers1

1

There are two ways how you could do this.

  1. You simply treat the project as XML and you edit that XML.
  2. You use Visual Studio's COM/.NET APIs.

It is not (IMHO) easy to do it using the Visual Studio APIs but it is doable. Start at MSDN's "How to: Get References to the DTE and DTE2 Objects" and follow the links.

wilx
  • 17,697
  • 6
  • 59
  • 114
  • for DTE all the code I could fine is either in c# or VB. Is this supported in c++ at all? If not.. can you please expand a little bit on how to treat my project as xml? – Vlad Otrocol Jul 22 '13 at 14:51
  • Since it is all COM, you can use it from pure C++ as well. See the linked page, it shows bits of C++. – wilx Jul 22 '13 at 14:54