简体   繁体   English

如何以编程方式在vs 2008中创建新的空白解决方案?

[英]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.

相关问题 创建新的活动解决方案平台(VS2008) - Create new active solution platform (VS2008) 如何在不重新编译VS2008中的解决方案的情况下热交换引用的DLL? - How can I hot swap referenced DLL's without recompiling the Solution in VS2008? 使用C#,如何以编程方式创建新的Visual Studio 2012解决方案? - Using C#, how do I create a new Visual Studio 2012 Solution programmatically? 如何以编程方式创建VS 2008 Windows Forms项目,该项目可以像手动创建的任何其他项目一样进行维护 - How to create a VS 2008 Windows Forms project programmatically, that can be maintained just like any other project created manually VS 2008中的解决方案文件 - Solution File in VS 2008 如何在Visual Studio 2008中以编程方式检索已加载的项目? - How can I programmatically retrieve a loaded project in Visual Studio 2008? 如何以编程方式编辑Windows 7 / Server 2008中的hosts文件? - How can I programmatically edit the hosts file in Windows 7/Server 2008? 如何使用C#以编程方式将内容添加到新的/现有的可执行文件中,并可能使解决方案在Mac上运行? - How can I programmatically add content to new/existing executable using c# and possibly make the solution work on a mac? 创建Visual Studio(vs.net)2008解决方案模板? - Create Visual Studio (vs.net) 2008 Solution Templates? 如何在VS 2008单元测试中使用数据文件? - How can I use a data file in a VS 2008 unit test?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM