locked
Visual Studio Add - In : Item template does not get included into project. RRS feed

  • Question

  • Hi 

    I am creating a Visual Studio add in in which I am successfully able to add the project using custom project template. I am successfully able to add Item from the custom Item template that I have created but when I explore the solution explorer I see that the Item template files are excluded from the project. They were copied to the Solution but were excluded.

    I am trying to add it using C# code. The following code would help better in understanding.

    string vsItemTemplatePath_ULS = newSolution.GetProjectItemTemplate("aasd**", "CSharp");                
                    newSolution.Projects.Item(1).ProjectItems.AddFromTemplate(ASDASDF**, "ABC");


    Any pointers in this regards would be appreciated.

    Thanks and Regards



    Thursday, April 10, 2014 9:38 AM

Answers

  • Hi,

    I think your code is ok. Even the files have been added in the project file, they will appear after you click "show all files" button in the solution explorer. If you want to show it directly in the solution explorer, you need to right click and select "include the file in Project" manually. I suggest you post this issue on connect since we see the issue exists in VS2010. It seems that it hasn't been fixed in VS2012.

    Best regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Anna Cc Sunday, June 29, 2014 3:37 AM
    Wednesday, June 25, 2014 12:43 PM

All replies

  • Hi S Shankar,

    According to your description, I guess your problem is similar as Colin Svingen posted iconnect site.

    http://connect.microsoft.com/VisualStudio/feedback/details/763863/projectitems-addfromtemplate-doesnt-work-when-project-is-a-solutionfolder

    Quote reply from Microsoft:

    Thank you for your feedback, after further evaluation we have decided not to fix the issue. The issue has been present in the product since Visual Studio 2010, and we have not received significant customer feedback.

    If this is the problem, I suggest you update your VS.

    If I misunderstand you, please feel free to let me know.

    Best regards,

    Sunny


    • Edited by Anna Cc Friday, April 11, 2014 8:07 AM
    Friday, April 11, 2014 8:03 AM
  • Thanks Sunny.

    I had checked the link earlier but it says that the code does not work, while in my case it is adding the '.cs' file to the solution location as specified and as expected and it is opening the file initially in visual studio also but then we manually have to include the file to project by- showing hidden items in solution explorer and then right click and select "include the file in Project" manually.

    I believe the issue mentioned in the link was there in VS 2010, however I am using VS 2012. I did not find any reference to the issue mentioned about VS 2012.

    Appreciate the help extended.

    Regards


    Friday, April 11, 2014 9:00 AM
  • Hi 

    I am creating a Visual Studio add in in which I am successfully able to add the project using custom project template. I am successfully able to add Item from the custom Item template that I have created but when I explore the solution explorer I see that the Item template files are excluded from the project. They were copied to the Solution but were excluded.

    I am trying to add it using C# code. The following code would help better in understanding.

    string vsItemTemplatePath_ULS = newSolution.GetProjectItemTemplate("aasd**", "CSharp");                
                    newSolution.Projects.Item(1).ProjectItems.AddFromTemplate(ASDASDF**, "ABC");

    Checked the msdn link- 
    http://connect.microsoft.com/VisualStudio/feedback/details/763863/projectitems-addfromtemplate-doesnt-work-when-project-is-a-solutionfolder

    It says that the code does not work, while in my case it is adding the '.cs' file to the solution location as specified and as expected and it is opening the file initially in visual studio also but then we manually have to include the file to project by- showing hidden items in solution explorer and then right click and select "include the file in Project" manually.

    I believe the issue mentioned in the link was there in VS 2010, however I am using VS 2012. I did not find any reference to the issue mentioned about VS 2012.

    Any pointer in this regards would be highly appreciated.

    Thanks


    • Edited by Saurabh Shankar Monday, April 14, 2014 6:23 AM
    • Merged by Anna Cc Monday, April 14, 2014 6:46 AM same
    Friday, April 11, 2014 10:54 AM
  • Hi,

    Thank you for your feedback!

    >>showing hidden items in solution explorer and then right click and select "include the file in Project" manually.

    I'm glad to see if you upload a screenshot of "copied to the Solution but were excluded".

    Best regards,

    Sunny


    • Edited by Anna Cc Thursday, April 17, 2014 1:20 PM
    Thursday, April 17, 2014 1:19 PM
  • I created the solutions using the add in.

    And the manually include the files to the project.

    The code that I have used to add the files to the solutions is as given below-

    /// <summary>
            /// Create solution
            /// </summary>
            private void CreateSolution()
            {
                Solution2 newSolution = (Solution2)this._applicationObject.Solution;            
    
                //Get the visual studio project template
    
                string vsTemplatePath = newSolution.GetProjectTemplate("SP2013 - EmptySolution.zip", "csproj");
    
                newSolution.Create(txt_Path.Text, txt_SolutionName.Text);
                newSolution.AddFromTemplate(vsTemplatePath, txt_Path.Text + "\\" + txt_SolutionName.Text, txt_SolutionName.Text, false);
    
                //Get the item templates selected by the user.
    
                if (chkbx_ULS.Checked == true)
                {
                    string vsItemTemplatePath_ULS = newSolution.GetProjectItemTemplate("SharePoint 2013 - ULS Logging", "CSharp");                
                    newSolution.Projects.Item(1).ProjectItems.AddFromTemplate(vsItemTemplatePath_ULS, "ULS_Logger");
    
                }
                if (chkbx_Login.Checked == true)
                {
                    string vsItemTemplatePath_Login = newSolution.GetProjectItemTemplate("Login", "CSharp");
                    newSolution.Projects.Item(1).ProjectItems.AddFromTemplate(vsItemTemplatePath_Login, "Login");
    
                }
    
                newSolution.SaveAs(txt_Path.Text + "\\" + txt_SolutionName.Text + ".sln");
                newSolution.Open(txt_Path.Text + "\\" + txt_SolutionName.Text + ".sln");
            }

    Monday, April 21, 2014 4:33 AM
  • Hi Sunny

    Do we have any update on the issue?

    Appreciate your response on this.

    Thanks

    Tuesday, May 6, 2014 5:21 AM
  • Hi,

    I think your code is ok. Even the files have been added in the project file, they will appear after you click "show all files" button in the solution explorer. If you want to show it directly in the solution explorer, you need to right click and select "include the file in Project" manually. I suggest you post this issue on connect since we see the issue exists in VS2010. It seems that it hasn't been fixed in VS2012.

    Best regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    • Marked as answer by Anna Cc Sunday, June 29, 2014 3:37 AM
    Wednesday, June 25, 2014 12:43 PM