locked
AddProjectReference(VCProject) RRS feed

  • Question

  • Hello,

    i want to manipulate a C++ VCProject with C#-Code. Especially, i want to add a project reference. Every attempt to add a project reference with AddProjectReference() leads to an exception. (System.InvalidCastException because the desired data is in a zombie state) Other operations (like AddFile, AddFilter) work correctly...

    Has anybody an idea what i do wrong?

    Thanks in advance.

    VCProjectEngine vcProjectEngine = new
     VCProjectEngineObject();
    VCProject project1 = (VCProject)vcProjectEngine.LoadProject(@"C:\test1\test1.vcproj" );
    VCProject project2 = (VCProject)vcProjectEngine.LoadProject(@"C:\test1\test2.vcproj" );

    project1.AddProjectReference(project2);
    Friday, January 21, 2011 6:44 AM

Answers

  • Hi Jay_85_ush,

     

    Thanks for your post.

    As far as I know, you cannot add project reference without a solution loaded, and these two project should be in the same solution.

    If you add project reference manually my Visual Studio IDE, you can see a dialog popped up and the reference information is added to the project file, which is done by Visual Studio IDE.

    It means even if you can load this project, it is on a zombie state, you cannot modify the project file programmatically without the solution loaded.

    Therefore, if you expect to add project reference programmatically, you can create an addin or macro to do so.

    Hope my reply helps resolve your issue.

     

    Best Regards,

    Ziwei Chen

     

     


    Ziwei Chen [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Victor_Chen Thursday, January 27, 2011 9:57 AM
    Monday, January 24, 2011 8:05 AM

All replies

  • Hi Jay_85_ush,

     

    Thanks for your post.

    As far as I know, you cannot add project reference without a solution loaded, and these two project should be in the same solution.

    If you add project reference manually my Visual Studio IDE, you can see a dialog popped up and the reference information is added to the project file, which is done by Visual Studio IDE.

    It means even if you can load this project, it is on a zombie state, you cannot modify the project file programmatically without the solution loaded.

    Therefore, if you expect to add project reference programmatically, you can create an addin or macro to do so.

    Hope my reply helps resolve your issue.

     

    Best Regards,

    Ziwei Chen

     

     


    Ziwei Chen [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Victor_Chen Thursday, January 27, 2011 9:57 AM
    Monday, January 24, 2011 8:05 AM
  • Hi jay_85_ush,

     

    I'm going to close this thread, if you have further questions, be free to unmark it or post a new one.

    Thanks for your understanding.

     

     

    Best Regards,

    Ziwei Chen

     

     

     


    Ziwei Chen [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, January 27, 2011 9:57 AM