Solution2 接口

表示集成开发环境 (IDE) 中所有的项目和解决方案属性。

命名空间:  EnvDTE80
程序集:  EnvDTE80(在 EnvDTE80.dll 中)

语法

声明
<GuidAttribute("FA238614-FBB1-4314-A7F7-49AE8BB6C6BA")> _
Public Interface Solution2 _
    Inherits _Solution
[GuidAttribute("FA238614-FBB1-4314-A7F7-49AE8BB6C6BA")]
public interface Solution2 : _Solution
[GuidAttribute(L"FA238614-FBB1-4314-A7F7-49AE8BB6C6BA")]
public interface class Solution2 : _Solution
[<GuidAttribute("FA238614-FBB1-4314-A7F7-49AE8BB6C6BA")>]
type Solution2 =  
    interface
        interface _Solution
    end
public interface Solution2 extends _Solution

Solution2 类型公开以下成员。

属性

  名称 说明
公共属性 AddIns (继承自 _Solution。)
公共属性 AddIns 获取 AddIns 集合,它包含与解决方案关联的所有当前可用的外接程序。
公共属性 Count (继承自 _Solution。)
公共属性 Count 获取一个值,该值指示解决方案中项目的数目。
公共属性 DTE (继承自 _Solution。)
公共属性 DTE 获取顶级扩展性对象。
公共属性 Extender[String] (继承自 _Solution。)
公共属性 Extender[String] 如果请求的 Extender 对象可用于此对象,则获取该 Extender 对象。
公共属性 ExtenderCATID (继承自 _Solution。)
公共属性 ExtenderCATID 获取对象的扩展程序类别 ID (CATID)。
公共属性 ExtenderNames (继承自 _Solution。)
公共属性 ExtenderNames 获取此对象的可用 Extender 的列表。
公共属性 FileName (继承自 _Solution。)
公共属性 FileName 基础结构。仅由 Microsoft 内部使用。
公共属性 FullName (继承自 _Solution。)
公共属性 FullName 获取对象文件的完整路径和名称。
公共属性 Globals (继承自 _Solution。)
公共属性 Globals 获取 Globals 对象,该对象包含可以保存在解决方案 (.sln) 文件、项目文件或用户的配置文件数据中的任何变量值。
公共属性 IsDirty (继承自 _Solution。)
公共属性 IsDirty 基础结构。仅由 Microsoft 内部使用。
公共属性 IsOpen (继承自 _Solution。)
公共属性 IsOpen 获取一个值,该值指示解决方案是否已打开。
公共属性 Parent (继承自 _Solution。)
公共属性 Parent 获取 Solution2 对象的直接父对象。
公共属性 Projects (继承自 _Solution。)
公共属性 Projects 获取解决方案中当前项目的集合。
公共属性 Properties (继承自 _Solution。)
公共属性 Properties 获取属于 Solution2 对象的所有属性的集合。
公共属性 Saved (继承自 _Solution。)
公共属性 Saved 获取或设置一个值,该值指示解决方案自上次保存或打开以来是否未经过修改。
公共属性 SolutionBuild (继承自 _Solution。)
公共属性 SolutionBuild 获取解决方案的 SolutionBuild 对象,该对象表示位于解决方案级的生成自动化模型的根。
公共属性 TemplatePath[String] (继承自 _Solution。)
公共属性 TemplatePath[String] 已被 GetProjectTemplate 取代。

页首

方法

  名称 说明
公共方法 AddFromFile(String, Boolean) (继承自 _Solution。)
公共方法 AddFromFile(String, Boolean) 向基于已存储在系统中的项目文件的解决方案添加一个项目。
公共方法 AddFromTemplate(String, String, String, Boolean) (继承自 _Solution。)
公共方法 AddFromTemplate(String, String, String, Boolean) 将现有项目文件及其包含的任何项或子目录复制到指定位置,并将其添加到解决方案。
公共方法 AddSolutionFolder 将解决方案文件夹添加到 ProjectItems 集合中。
公共方法 Close(Boolean) (继承自 _Solution。)
公共方法 Close(Boolean) 关闭当前解决方案。
公共方法 Create(String, String) (继承自 _Solution。)
公共方法 Create(String, String) 在指定的目录中创建具有指定名称的空解决方案。
公共方法 FindProjectItem(String) (继承自 _Solution。)
公共方法 FindProjectItem(String) 在项目中定位项。
公共方法 GetEnumerator() (继承自 _Solution。)
公共方法 GetEnumerator() 返回集合中项的枚举。
公共方法 GetProjectItemTemplate 返回所指示的项目项模板的路径。
公共方法 GetProjectTemplate 返回所指示的项目模板的路径。
公共方法 Item(Object) (继承自 _Solution。)
公共方法 Item(Object) 返回 Projects 集合的一个索引成员。
公共方法 Open(String) (继承自 _Solution。)
公共方法 Open(String) 打开指定的解决方案。
公共方法 ProjectItemsTemplatePath(String) (继承自 _Solution。)
公共方法 ProjectItemsTemplatePath(String) 已被 GetProjectItemTemplate 取代。
公共方法 Remove(Project) (继承自 _Solution。)
公共方法 Remove(Project) 从解决方案中移除指定的项目。
公共方法 SaveAs(String) (继承自 _Solution。)
公共方法 SaveAs(String) 保存解决方案。

页首

备注

此接口包含 IDE 当前实例中的所有项目以及所有解决方案范围属性(如生成配置)的集合。 它包含每个项目的项目元素,不管这些项目是打包项目、子项目还是顶级项目。

使用 DTE.Solution 属性,可以查找打开的解决方案。 若要引用虚项目(如 MiscFile 或 SolutionItem),请使用 Solution.Item(EnvDTE.Constants.vsProjectKindMisc 或 Solution.Item(EnvDTE.Constants.vsProjectKindSolutionItems。

示例

有关如何运行此外接程序代码的信息,请参见如何:编译和运行自动化对象模型代码示例

下面的代码在给定的路径中创建新的控制台应用程序解决方案。

Public Sub OnConnection(ByVal application As Object, _
 ByVal connectMode As ext_ConnectMode, ByVal addInInst As Object, _
 ByRef custom As Array) Implements IDTExtensibility2.OnConnection
    _applicationObject = CType(application, DTE2)
    _addInInstance = CType(addInInst, AddIn)
    SolutionExample(_applicationObject)
End Sub

Sub SolutionExample(ByVal dte As DTE2)
    ' This function creates a solution and adds a Visual Basic Console
    ' project to it.
    Try
        Dim soln As Solution2 = CType(DTE.Solution, Solution2)
        Dim vbTemplatePath As String
        ' This path must exist on your computer.
        ' Replace <file path> below with an actual path.
        Dim vbPrjPath As String = <file path>
        MsgBox("starting")
        ' Get the project template path for a Visual Basic console application project.
        vbTemplatePath = soln.GetProjectTemplate _
        ("ConsoleApplication.zip", "VisualBasic")
        ' Create a new Visual Baic Console project using the template obtained 
        ' above.
        soln.AddFromTemplate(vbTemplatePath, vbPrjPath, _
        "New Visual Basic Console Project", False)
        MsgBox("done")
    Catch ex As System.Exception
        MsgBox(ex.ToString)
    End Try
End Sub
//you will need to add this reference to your project as well
using System.Windows.Forms;  

public void OnConnection(object application,
 Extensibility.ext_ConnectMode connectMode, object addInInst,
 ref System.Array custom)
{
    _applicationObject = (DTE2)application;
    _addInInstance = (AddIn)addInInst;
    // Pass the applicationObject member variable to the code example.
    SolutionExample((DTE2)_applicationObject);
}

public void SolutionExample(DTE2 dte)
{
    // This function creates a solution and adds a Visual C# Console
    // project to it.
    try{
        Solution2 soln = (Solution2)_applicationObject.Solution;
        String csTemplatePath;
        // The file path must exist on your computer.
        // Replace <file path> below with an actual path.
        String csPrjPath = <file path>;
    MessageBox.Show("Starting...");
csTemplatePath = 
soln.GetProjectTemplate("ConsoleApplication.zip", "CSharp");
        // Create a new C# Console project using the template obtained 
        // above.
        soln.AddFromTemplate(csTemplatePath, csPrjPath,
 "New CSharp Console Project", false);
        MessageBox.Show("Done!");
    }
    catch(SystemException ex)
    {
        MessageBox.Show("ERROR: " + ex);
    }
}

请参见

参考

EnvDTE80 命名空间