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 是用來測試轉換前的專案類型。
範例
若要將此範例當做增益集來執行,請參閱 HOW TO:編譯和執行 Automation 物件模型程式碼範例。
若要判斷 Visual Basic 或 Visual C# 專案是否為智慧型裝置專案,請使用 prjKindSDEVBProject 和 prjKindSDECSharpProject。
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.");
}
}