-1

I am trying to generate a Visual Studio 2010 solution and add VS 2010 projects from custom templates!

My requirement: 1. Generate a VisualStudio Solution 2010, Save it to a folder, add VisualSTudio Project from my own templates (I have 3 different templates: ClassLibrary,WinForms ,WCFService)

My issue: I implemented something that is working half a way!

  1. Solution is created correctly but the content of the ".sln" file is very poor! No project reference is added >

  2. In the root folder, it creates a Solution also for the C# Project, which I do not want. I want only the MainSolution file. (In my case "TestSolution.sln"). How can I stop creating a solutionfile for each project created?

Below the source code I use:
//for The solution: enter image description here

//adding a project enter image description here

Am I using the wrong interfaces? Why the vs2010Solution.AddFromTemplate(..) returns null after the call, but no exception is thrown? Also the Project is created correctly in the folderstructure! But at runtime I can't check the list of projects "vs2010Solution.Projects" as it is null! (After correctly adding a project). I need the Project added because I need to add some references programmatically, which I try to do in the next line, but it doesn't work because vs2010Project is null).

So I am trying to wrap the VisualStudio 2010 automation model, to create a solution and add projects! But is not really working! Do I need to cast EnvDTE.Project to "VSLangProj.Project" at some point? I want to create a clean wrapper for VS2010, after that one for VS 2012! Any help is much appreciated.

Cerbrus
  • 70,800
  • 18
  • 132
  • 147
Giuseppe
  • 1
  • 2

1 Answers1

0

See the several articles of the section "Articles about automating project creation" on my web site:

http://www.visualstudioextensibility.com/articles/add-ins/

They explain why AddFromTemplate method returns null, how to create a solution, a project, a project inside a solution folder, a project item, etc.

Carlos Quintero
  • 4,300
  • 1
  • 11
  • 18
  • Thx Carlos, I solved partally the issue! Now I can generate a Soluton, add 4 projects andalso 2 references for each projects (With a test). The issue is that while running the tests in debug mode, everything works fine! As soon as I try to run the source code, it adds only one project to the solution and then it quits! – Giuseppe Oct 16 '14 at 20:54