开发者

How can I create new blank solution in vs 2008 programmatically?

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

I have to create a blank solution program开发者_如何学Cmatically 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.


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).


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜