locked
Can't get AdditionalIncludeDirectories in VS2008 RRS feed

  • Question

  • I've tried at least a dozen ways of getting  from the DTE instance to the AdditionalIncludeDirectories.  Every path fails when I try to cast from a DTE "general" project/collection/configuration to an VCxxx.  For instance:

     

    Array projects = (Array)application.ActiveSolutionProjects;
    Project prj= (Project)projects.GetValue(0);
    VCProject proj = (VCProject)prj.Object;         //  <<<<<<<    cast fails
    IVCCollection coll = (IVCCollection)proj.Configurations;
    VCConfiguration cfg = (VCConfiguration)coll.Item(2);
    IVCCollection tools = (IVCCollection)conf.Tools;
    VCCLCompilerTool compiler = (VCCLCompilerTool)tools.Item("VCCLCompilerTool");
    MessageBox.Show(compiler.AdditionalIncludeDirectories);

     

    and

    Array projects = (Array)application.ActiveSolutionProjects;
    Project prj= (Project)projects.GetValue(0);
    VCConfiguration
    conf = (VCConfiguration)(prj.Properties.Item("Configurations").Object as IVCCollection).Item(1);  //  <<<<<<  cast fails
    IVCCollection tools = (IVCCollection)conf.Tools;
    VCCLCompilerTool compiler = (VCCLCompilerTool)tools.Item("VCCLCompilerTool");
    MessageBox.Show(compiler.AdditionalIncludeDirectories);

    These approaches are adapted from other posts in this forum, but nothing seems to work.


    Any suggestions for solving this problem?
    Thanks,
    -Harry


    Any suggestions for solving this problem?
    Thanks,
    -Harry

     

    Tuesday, April 14, 2009 10:10 PM

Answers

  • Hi, Harry

    Following is my code snippet from a previous thread, hope it helps.
    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;
        System.Windows.Forms.MessageBox.Show(addDir);
    }

    Sincerely!
    Please mark the replies as answers if they help and unmark them if they provide no help. Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Wesley Yao Tuesday, April 21, 2009 3:12 AM
    Thursday, April 16, 2009 9:59 AM