Copy all header files in a project RRS feed

  • Question

  • I am thinking of porting a scons based project to Visual Studio 2008. The project in visual studio will become a solution with various projects. There will be many subdirectories in each project. In order to make things a bit easier concerning project setup I would like to have a pre-build task that copies all header files in the project to a top level include directory. Then this include directory could be given to the compiler as an additional include dir in stead of a whole bunch of subdirectories.

    I have no been able to find any examples of how to automate this in Visual Studio. I was thinking of using a macro. It strikes me that this must be something that other developers has encountered and that a solution should exist somewhere.

    Grateful for any help.
    Wednesday, March 11, 2009 8:46 AM


  • Hello,

    In my idea, you could create an Add-in to automate it, in the code, go through all the sub include directories and copy them to the top one, this job can be done in any language, so here I just post the way to iterate the projects, do copy and setting their AdditionalIncludeDirectories attributes.  About the method copyDirectory , please implement it as you wish.

    Code snippet:
    foreach (Project proj in _applicationObject.Solution.Projects)  
        VCProject vcp = proj.Object as VCProject;  
        IVCCollection ivcc = vcp.Configurations as IVCCollection;  
        VCConfiguration cfg = ivcc.Item(1) as VCConfiguration;  
        IVCCollection tools = cfg.Tools as IVCCollection;  
        VCCLCompilerTool compiler = tools.Item("VCCLCompilerTool"as VCCLCompilerTool;  
        string[] addDir = compiler.AdditionalIncludeDirectories.Split(';');  
        foreach (string dir in addDir)  
            copyDirectory(dir.Substring(1, dir.Length - 2), "..\\Includes");  
        compiler.AdditionalIncludeDirectories = "..\\Includes";  

    Please mark the replies as answers if they help and unmark them if they provide no help.
    • Marked as answer by Nancy Shao Tuesday, March 17, 2009 8:04 AM
    Friday, March 13, 2009 7:35 AM