[英]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 基于设计的方法是:新项目 - >其他项目类型 - > Visual Studio解决方案 - >空白解决方案
I have to create a blank solution programmatically in C# and in this solution add new empty project and files. 我必须在C#中以编程方式创建一个空白解决方案,并在此解决方案中添加新的空项目和文件。 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: 您可以使用DTE创建一个新的空白解决方案,如下所示:
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. 您必须添加对EnvDTE.dll,EnvDTE80.dll和EnvDTE90.dll的引用。 The resulting file you will get is very simple and could be created in other ways (as a plain text file).
您将获得的结果文件非常简单,可以通过其他方式创建(作为纯文本文件)。
如果你真的只需要创建一个带有空项目文件的解决方案,那么手工编写.sln文件(它是一个纯文本文件)和.csproj文件(它是一个XML MSBuild文件)可能要容易得多。搞乱Visual Studio自动化。
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.
用{n}替换项目/解决方案名称/其他特定数据,以便稍后使用string.Format填充它们。 Then embed those files (sln and csproj) to your assembly and use them as resource.
然后将这些文件(sln和csproj)嵌入到程序集中并将它们用作资源。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.