可以调用EnvDTE,操作Visual Studio,向已经打开的解决方案中添加工程,或者工程中添加文件等等操作
需要引入envdte开头的几个动态库,VSLangProj开头的几个动态库,下面是我写的一个简单的添加工程的例子
using EnvDTE;
using System;using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.ComTypes;
using System.Text;
namespace EnvDTESolution
{
public class CNxEnvDTEHelper
{
[DllImport("ole32.dll")]
private static extern void CreateBindCtx(int reserved, out IBindCtx ppbc);
[DllImport("ole32.dll")]
private static extern int GetRunningObjectTable(int reserved, out IRunningObjectTable prot);
public static Project AddProjectToDTE(_DTE dte, string projectName, bool Exclusive = false)
{