EnvDTE.DTE dte = (EnvDTE.DTE)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.15.0"); EnvDTE.Solution solution = dte.Solution;
EnvDTE.DTE dte = (EnvDTE.DTE)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.15.0"); EnvDTE.Solution solution = dte.Solution; EnvDTE.Project project = solution.AddFromTemplate("ConsoleApplication.zip", "C:\temp\MyProject", "MyProject", false); project.Save();
EnvDTE.DTE dte = (EnvDTE.DTE)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.15.0"); EnvDTE.Solution solution = dte.Solution; EnvDTE.Project project = solution.Projects.Item(1); EnvDTE.ProjectItem item = project.ProjectItems.Item(1); EnvDTE.FileCodeModel codeModel = item.FileCodeModel;Description: This code retrieves the instance of Visual Studio, the active solution, and a project from the solution. The fourth line retrieves a specific item from the project (in this case, the first item), and the fifth line retrieves the FileCodeModel for that item. This can be used to generate code, navigate the syntax tree, and more. Package library: EnvDTE