How can I create a new empty solution in vs 2008 programmatically?

Design-based approach: New project → Another type of project → Visual Studio solution → Empty solution

I need to create an empty solution programmatically in C #, and in this solution add a new empty project and files. I found a lot of code on the Internet using DTE, but they add my empty project to an existing solution developer, so please give me some reference code.

+3
source share
3 answers

You can create a new empty solution using DTE, for example:

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 need to add links to EnvDTE.dll, EnvDTE80.dll and EnvDTE90.dll. The file you received is very simple and can be created in other ways (as a text file).

+6
source

If you just need to create a solution with an empty project file, it is much simpler to simply write the .sln file (this is a simple text file) and the .csproj file (MSBuild XML file) manually than this is related to Visual Studio automation.

0
source

Create a solution with an empty project manually. Replace the project / solution name / other specific data with {n} so you can fill it with string.Format later. Then paste these files (sln and csproj) into your assembly and use them as a resource.

0
source

All Articles