如何以编程方式在vs 2008中创建新的空白解决方案? [英] How can I create new blank solution in vs 2008 programmatically?

查看:106
本文介绍了如何以编程方式在vs 2008中创建新的空白解决方案?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于设计的方法是:新建项目->其他项目类型-> Visual Studio解决方案->空白解决方案

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

我必须在C#中以编程方式创建空白解决方案并在此解决方案中添加新的空项目和文件。我在网上使用DTE找到了很多代码,但是他们在现有的解决方案资源管理器中添加了我的空项目,因此请给我一些参考代码。

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.

推荐答案

您可以使用DTE这样创建新的空白解决方案:

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

的任何地方,您都必须添加对EnvDTE.dll,EnvDTE80.dll和EnvDTE90.dll。您将获得的结果文件非常简单,可以用其他方式创建(作为纯文本文件)。

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

这篇关于如何以编程方式在vs 2008中创建新的空白解决方案?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆