locked
Issue while adding an existing project to the current solution using AddFromTemplate() RRS feed

  • Question

  • Hi ,

    I have a requirement wherein I need to add an existing project to the solution (VS2008,C#)when I add an item template to the project.I tried to use AddFromTemplate but its throwing error.

    Following is the code used in the customWizard's RunStarted method:

    DTE

     

    dte = (DTE)automationObject;

    Solution3 sol3 =(Solution3) dte.Solution;

    bool ProjExist = false;

     

    string projpath;

     

    //string solpath="<file path>";

    projpath = sol3.GetProjectTemplate(

    "AB.zip","CSharp");

     

    foreach (EnvDTE.Project project in sol3.Projects)

    {

     

    if (project.Name == "AB")

    ProjExist =

    true;

    }

     

    if (!ProjExist)

    {

     

    sol3.AddFromTemplate(projpath,

    @"D:\Projects\SmartDeviceProject", "A", false);

    }

     

    Also in AddFromTemplate () I have hardcoded the destination path(D:\Projects\SmartDeviceProject).How can I get the solution path to which I want to add my project through automation.It should be such that I can add the project to any solution.Hence I can't hard code it.

    Also was getting with the code above.What am I missing.

    Please help.Thanks in advance

    Thursday, June 17, 2010 11:09 AM

Answers

  • Hello, Hepsi

    Could you tell me what is the error message?, since you add your custom template, the error may caused by it fail to get the template. You could use a message box to the projpath to know whether the project template was added successfully.

    Actually as I know, the GetProjectTemplate will search the C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ProjectTemplates folder.

    For how to get the solution path, you could use _Solution.FullName Property.

    Thanks

    Chao

    • Marked as answer by Chao Kuo Thursday, June 24, 2010 2:54 AM
    Friday, June 18, 2010 9:44 AM

All replies

  • Hello, Hepsi

    Could you tell me what is the error message?, since you add your custom template, the error may caused by it fail to get the template. You could use a message box to the projpath to know whether the project template was added successfully.

    Actually as I know, the GetProjectTemplate will search the C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ProjectTemplates folder.

    For how to get the solution path, you could use _Solution.FullName Property.

    Thanks

    Chao

    • Marked as answer by Chao Kuo Thursday, June 24, 2010 2:54 AM
    Friday, June 18, 2010 9:44 AM
  • Hi Chao,

    I added the template in :\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ProjectTemplates folder.That time when I add the item template to the project it said 'File not available'.So I added the template to \Visual Studio 2008\Templates\ItemTemplates folder.This time I got an error message saying 'File already exists'.

    Below is the code used:

    Solution3 sol3 =(Solution3) dte.Solution;


    string projpath = sol3.GetProjectTemplate("ProjA.zip","CSharp");

    solpath=sol3.FullName;

    sol3.AddFromTemplate(projpath, solpath, "ProjA", false);

    Can you please tell me what am I missing.

    Thanks in advance


    Thursday, June 24, 2010 8:06 AM
  • Hi Chao,

    Waiting for your suggestions.Please help.

     

    Thanks

    Monday, June 28, 2010 12:57 PM