Solution3.FindProjectItem 方法

在项目中定位项。

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

语法

声明
Function FindProjectItem ( _
    FileName As String _
) As ProjectItem
ProjectItem FindProjectItem(
    string FileName
)
ProjectItem^ FindProjectItem(
    String^ FileName
)
abstract FindProjectItem : 
        FileName:string -> ProjectItem
function FindProjectItem(
    FileName : String
) : ProjectItem

参数

  • FileName
    类型:String

    必需。 要定位的项目项的名称。

返回值

类型:ProjectItem
一个 ProjectItem 对象。

备注

FindProjectItem 执行 OpenFile 类型的搜索以查找给定的文件名。 找到的第一个包含该项的项目为此文件名返回其 ProjectItem 对象。 如果在解决方案中找不到该文件,则返回 nullnull 引用(在 Visual Basic 中为 Nothing)。

示例

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

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)
    SolnFindProjectItemExample(_applicationObject)
End Sub

Sub SolnFindProjectItemExample(ByVal dte As DTE2)
    ' This add-in finds a project item in a  solution.
    ' Make sure you have a solution open in Visual 
    ' Studio before running this example.
    Try
        Dim soln As Solution3 =  _
        CType(_applicationObject.Solution, Solution3)
        MsgBox("Finding a project item in the solution ")
        ' Find the specified project.
        Dim proj As ProjectItem
        proj = soln.FindProjectItem _
(soln.Projects.Item(1).ProjectItems.Item(1).Name.ToString())
        MsgBox(proj.Name.ToString())
    Catch ex As System.Exception
        MsgBox(ex.ToString)
    End Try
End Sub
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.
    CreateExample((DTE2)_applicationObject);
}

public void CreateExample(DTE2 dte)
{
    // This add-in finds a project item in a solution.
    // Open a solution in Visual Studio before running 
    // this example.
    try
    {
        Solution3 soln = (Solution3)_applicationObject.Solution;
        MessageBox.Show("Finding a project item in the solution.");
        ProjectItem proj;
        proj =
          soln.FindProjectItem
          (soln.Projects.Item(1).ProjectItems.Item(1).Name.ToString());
        MessageBox.Show("The project item found is: " 
          + proj.Name.ToString());
    }
    catch (SystemException ex)
    {
        MessageBox.Show("ERROR: " + ex);
    }
}

.NET Framework 安全性

请参阅

参考

Solution3 接口

EnvDTE90 命名空间

其他资源

如何:编译和运行自动化对象模型代码示例