Aracılığıyla paylaş


Nasıl yapılır: Proje belirli türleri için dosya erişim özellikleri

El ile ayarlayın ve proje dosyalarında dosyanın özelliklerini inceleyin Visual Studio tümleşik geliştirme ortamı (IDE).Dosya özelliklerini incelemek için bir proje açın Visual Studio, filename.cs gibi bir proje dosyasını sağ tıklatın, Solution Explorer.Kısayol menüsünden Properties'i seçin özelliklerini görüntülemek için özelliklerini iletişim kutusu.Özelliklerini iletişim kutusunda seçtiğiniz dosyayı el ile ayarlayabilirsiniz dosya özelliklerini görüntüler.

VSLangProj80 Ad dosya özelliklerindeki program aracılığıyla erişmek için bir yol sunar Visual C# veya Visual Basic projeleri.Özellikle, FileProperties2 zengin bir denetleme ve dosya bilgilerine erişmek için özellikler kümesini tanımlar.Tanımlanan bazı özellikler FileProperties2 her dosya türü için geçerli değildir.Örneğin, DateCreated özelliği için diğer proje dosyalarına ancak AVI Dosyalarını Ayrıştırmada Kod tanımlanır.

Belirli bir erişim için FileProperties2 özelliği gerekir geçirmek özel özellik adını bir dize olarak EnvDTE.Property.Properties.Item(object index), aşağıdaki kod örneğinde gösterildiği gibi.

Project project;
ProjectItems projItems;
ProjectItem projItem;
Property prop;
project = _applicationObject.Solution.Projects.Item(1);
projItems = project.ProjectItems;
projItem = projItems.Item(1);
prop = projItem.Properties.Item("FileName");

Bu kod erişir FileName içinde bir dosya özelliği bir Visual C# veya Visual Basic proje.

Özellikleri etkin tanımlanan FileProperties2 özelliği maddeler için proje olarak erişilen dosyaları kullanılabilir özellikleri başvuru listesi Visual C# veya Visual Basic projeleri.

Aşağıdaki adımları ayrıntılı dosya özellikleri programlı olarak nasıl bir Visual Studio eklentisi.

[!NOT]

Gördüğünüz iletişim kutuları ve menü komutları, etkin ayarlarınıza ve ürün sürümüne bağlı olarak Yardım menüsünde açıklanana göre farklılık gösterebilir.Bu yordamlar, genel geliştirme ayarları ile etkin geliştirilmiştir.Ayarlarınızı değiştirmek için Araçlar menüsünden İçeri ve Dışarı Aktarma Ayarları'nı seçin.Daha fazla bilgi için bkz. Visual Studio ayarları.

Belirli türde bir proje için dosya özellikleri'ne erişmek için

  1. Oluşturma bir Visual Studio kullanarak eklenti projesinin Visual C#.

  2. Üzerinde Proje menüsünde,'ı Add Reference,'ı .net sekmesini seçin VSLangProj, VSLangProj2, ve VSLangProj80,'ı tıklatın ve Tamam.

  3. Aşağıdaki using ifadelerini Connect.cs dosyasýný dön.

    using VSLangProj;
    using VSLangProj2;
    using VSLangProj80;
    
  4. Aşağıdaki yöntem çağrısı OnConnection yöntemine ekleyin.

    public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
    {
        _applicationObject = (DTE2)application;
        _addInInstance = (AddIn)addInInst;
        VSProjectFileProps2(_applicationObject);
    }
    
  5. OnConnection yönteminin hemen altındaki VSProjectFileProps2 yöntemine ekleyin.

    public void VSProjectFileProps2(DTE2 dte)
    {
        try
        {
            // Open a Visual C# or Visual Basic project
            // before running this add-in.
            Project project;
            ProjectItems projItems;
            ProjectItem projItem;
            Property prop;
            project = _applicationObject.Solution.Projects.Item(1);
            projItems = project.ProjectItems;
            for(int i = 1 ; i <= projItems.Count; i++ )
            {
                projItem = projItems.Item(i);
                prop = projItem.Properties.Item("FileName");
                MessageBox.Show("The file name of item " + i + " is: " 
    + prop.Value.ToString());
                if (prop.Value.ToString().Contains(".cs") 
    || prop.Value.ToString().Contains(".vb"))
                {
                    prop = projItem.Properties.Item("FileSize");
                    MessageBox.Show("The file size of item " + i + " 
    is: " + prop.Value.ToString());
                    prop = projItem.Properties.Item("DateCreated");
                    MessageBox.Show("The creation date of item " + i 
    + " is: " + prop.Value.ToString());
                }
            }
        }
        catch(Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }
    

    VSProjectFileProps2 listeleri FileName projedeki her dosya için özellik.Yöntemi, daha sonra dosyayı .cs veya .vb uzantısı olup olmadığını belirler.Varsa, Filesize ve DateCreated özellik değerleri de görüntülenir.

    Tam kod örnek bölümünde listelenir

  6. Eklenti Oluştur'ı tıklatarak Build Solution , Build menü.

  7. Open a Visual C# or Visual Basic project in the Visual Studio IDE.

  8. Üzerinde araçları menüsünde tıklatın Add-in Manager, eklentiniz alanından seçin ve Add-In Manager iletişim kutusu.Tıklatın Tamam eklenti çalıştırmak için.

Örnek

Aşağıdaki örnek bir temel olan Visual Studio kullanarak belirli tür bir proje dosyasının özelliklerini nasıl gösteren eklenti Visual Studio Otomasyon.

using System;
using Extensibility;
using EnvDTE;
using EnvDTE80;
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;
    VSProjectFileProps2(_applicationObject);
}
public void VSProjectFileProps2(DTE2 dte)
{
    try
    {
        // Open a Visual C# or Visual Basic project
        // before running this add-in.
        Project project;
        ProjectItems projItems;
        ProjectItem projItem;
        Property prop;
        project = _applicationObject.Solution.Projects.Item(1);
        projItems = project.ProjectItems;
        for(int i = 1 ; i <= projItems.Count; i++ )
        {
            projItem = projItems.Item(i);
            prop = projItem.Properties.Item("FileName");
            MessageBox.Show("The file name of item " + i + " is: " 
+ prop.Value.ToString());
            if (prop.Value.ToString().Contains(".cs") 
|| prop.Value.ToString().Contains(".vb"))
            {
                prop = projItem.Properties.Item("FileSize");
                MessageBox.Show("The file size of item " + i + " is: "
 + prop.Value.ToString());
                prop = projItem.Properties.Item("DateCreated");
                MessageBox.Show("The creation date of item " + i 
+ " is: " + prop.Value.ToString());
            }
        }
    }
    catch(Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}
Imports System
Imports Microsoft.VisualStudio.CommandBars
Imports Extensibility
Imports EnvDTE
Imports EnvDTE80
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)
    VSProjectFileProperties2(_applicationObject)
End Sub
Sub VSProjectFileProperties2(ByVal dte As DTE2)
    ' Open a Visual C# or Visual Basic project
    ' before running this add-in.
    Try
        Dim project As Project
        Dim projItems As ProjectItems
        Dim projItem As ProjectItem
        Dim prop As [Property]
        project = _applicationObject.Solution.Projects.Item(1)
        projItems = project.ProjectItems
        For i As Integer = 1 To projItems.Count
            projItem = projItems.Item(i)
            prop = projItem.Properties.Item("FileName")
            MsgBox("The file name of item " & i & " is: "  _
            & prop.Value.ToString())
            If (prop.Value.ToString().Contains(".cs")  _
            Or prop.Value.ToString().Contains(".vb")) Then
                prop = projItem.Properties.Item("FileSize")
                MsgBox("The file size of item " & i & " is: "  _
                & prop.Value.ToString())
                prop = projItem.Properties.Item("DateCreated")
                MsgBox("The creation date of item " & i & " is: "  _
                & prop.Value.ToString())
            End If
        Next i
        Catch ex As System.Exception
            MsgBox(ex.ToString)
        End Try
    End Sub

Kod Derleniyor

Bu kodu derlemeye yeni bir oluşturmak Visual Studio eklenti projesi ve örnek kodda OnConnection yönteminin kodu Değiştir.Bir eklenti çalıştırma hakkında daha fazla bilgi için bkz: Nasıl yapılır: denetim Eklenti Yöneticisi'ni kullanarak eklentileri.

Ayrıca bkz.

Diğer Kaynaklar

Project Properties

Proje türü belirli proje ve proje öðesi yapılandırma özelliklerini erişme