3

The design based approach is: New Project -> Other Project Type -> Visual Studio Solution -> Blank Solution

I have to create a blank solution programmatically in C# and in this solution add new empty project and files. i found a lot of code on the web using DTE but they are adding my empty project in existing solution explorer so please give me some reference code.

Simon Fischer
  • 3,816
  • 3
  • 23
  • 32
user591790
  • 545
  • 2
  • 15
  • 33
  • You may look @ this http://www.c-sharpcorner.com/UploadFile/tharakram/BuildDotNetSolution11162005052301AM/BuildDotNetSolution.aspx it shows you how to build a project or solution from the command line. – jon3laze Feb 18 '11 at 05:40

3 Answers3

6

You can create a new blank solution using DTE like this:

string visualStudioProgID = "VisualStudio.Solution.9.0";
Type solutionObjectType = System.Type.GetTypeFromProgID(visualStudioProgID, true);
object obj = System.Activator.CreateInstance(solutionObjectType, true);
Solution3 solutionObject = (Solution3)obj;
solutionObject.Create(".", "MySolution");
solutionObject.SaveAs(@"C:\Temp\MySolution.sln"); //or wherever you prefer

You have to add references to EnvDTE.dll, EnvDTE80.dll, and EnvDTE90.dll. The resulting file you will get is very simple and could be created in other ways (as a plain text file).

Simon Fischer
  • 3,816
  • 3
  • 23
  • 32
0

If you truly just need to create a solution with an empty project file it's probably much easier to just write the .sln file (it's a plain text file) and the .csproj file (it's an XML MSBuild file) by hand than it is to mess with Visual Studio automation.

Josh
  • 68,005
  • 14
  • 144
  • 156
  • josh Eistein, thanks for giving me quick reply But i have to create that solution programmatically using visual studio automation. so please give me code for that. your answer will be appreciated. thanks again. – user591790 Feb 18 '11 at 06:45
0

Create a solution with empty project manually. Replace project/solution name/other specific data with {n} so you can fill them using string.Format later. Then embed those files (sln and csproj) to your assembly and use them as resource.

dzendras
  • 4,721
  • 1
  • 25
  • 20