VSProject2 接口

更新:2007 年 11 月

包含特定于 Visual Basic、Visual C# 或 Visual J# 项目的信息。如果项目是 Visual Basic、Visual C# 或 Visual J# 项目,则由 Object 对象返回它。

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

语法

声明
<GuidAttribute("B1042570-25C6-424A-B58B-56FA83AA828A")> _
Public Interface VSProject2 _
    Implements VSProject
用法
Dim instance As VSProject2
[GuidAttribute("B1042570-25C6-424A-B58B-56FA83AA828A")]
public interface VSProject2 : VSProject
[GuidAttribute(L"B1042570-25C6-424A-B58B-56FA83AA828A")]
public interface class VSProject2 : VSProject
public interface VSProject2 extends VSProject

备注

Project 是核心扩展性对象,可包含有关任意语言的项目的信息。Project 对象的 Object 属性返回一个对象,该返回对象的类型取决于所用的项目语言。对于 Visual Basic、Visual C# 和 Visual J#,返回的对象是 VSProject2 对象。

Object 属性返回 Object 数据类型。然后,Object 属性返回的数据对象可显式转换为 VSProject2。下面的示例使用 CType 函数演示这种转换。PrjKind 用于在转换前测试项目的类型。

示例

若要将此示例作为外接程序运行,请参见如何:编译和运行自动化对象模型代码示例

若要确定 Visual Basic 或 Visual C# 项目是否为智能设备项目,请使用 prjKindSDEVBProjectprjKindSDECSharpProject

Imports VSLangProj
Imports VSLangProj2
Imports VSLangProj80
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)
    VSProject2Example(applicationObject)
End Sub

 Sub VSProject2Example(ByVal dte As DTE2)
    Dim aProject As Project
    Dim aVSProject2 As VSProject2

    aProject = applicationObject.Solution.Projects.Item(1)
    MsgBox(aProject.Kind & aProject.Name)
    If (aProject.Kind = PrjKind.prjKindVBProject) Or_
    (aProject.Kind = PrjKind.prjKindCSharpProject) Or_
    (aProject.Kind = PrjKind2.prjKindVJSharpProject) Then
        aVSProject2 = CType(applicationObject.Solution.Projects.Item(1).Object, _
        VSProject2)
        MsgBox(aVSProject2.Project.FullName)
    Else
        MsgBox("The first project is not a Visual Basic, C# _
        or J# project.")
    End If
End Sub
// To use Messabox.Show, a reference to Windows.Forms is required.
using System.Windows.Forms;
using VSLangProj;
using VSLangProj2;
using VSLangProj80;
public void OnConnection(object application, ext_ConnectMode
 connectMode, object addInInst, ref Array custom)
{
    applicationObject = (DTE2)application;
    addInInstance = (AddIn)addInInst;
    VSProject2Example((DTE2)applicationObject);
}

public void VSProject2Example(DTE2 dte)
{
    Project aProject = null; 
    VSProject aVSProject2 = null; 
    aProject = applicationObject.Solution.Projects.Item( 1 ); 
    MessageBox.Show( aProject.Kind + aProject.Name); 
    if ( ( aProject.Kind == PrjKind.prjKindVBProject ) |
 ( aProject.Kind == PrjKind.prjKindCSharpProject ) |
 ( aProject.Kind == PrjKind2.prjKindVJSharpProject ) ) 
    { 
        aVSProject2 = ( ( VSProject )
(applicationObject.Solution.Projects.Item( 1 ).Object ) ); 
        MessageBox.Show( aVSProject2.Project.FullName); 
    } 
    else 
    { 
        MessageBox.Show( "The first project is not a Visual Basic,
 C# or J# project."); 
    } 
}

另请参见

参考

VSProject2 成员

VSLangProj80 命名空间

VSProject