다음을 통해 공유


방법: 특정 프로젝트 형식에 대한 폴더 속성 액세스

Visual Studio IDE(통합 개발 환경)에서 프로젝트를 열고 솔루션 탐색기에서 폴더를 마우스 오른쪽 단추로 클릭하여 폴더 속성을 수동으로 설정하고 검사할 수 있습니다.바로 가기 메뉴에서 속성을 클릭하여 속성 대화 상자를 엽니다.

VSLangProj80 네임스페이스를 사용하면 Visual C# 또는 Visual Basic 프로젝트의 폴더 속성에 프로그래밍 방식으로 액세스할 수 있습니다.특히, FolderProperties2에서는 폴더 정보를 제어하고 이러한 정보에 액세스하기 위한 여러 가지 속성을 정의합니다.FolderProperties2에 정의되어 있는 속성 대부분은 속성 창에서 수동으로 액세스할 수 없습니다.

특정 FolderProperties2 속성에 액세스하려면 다음 코드 예제에서와 같이 특정 속성 이름을 **EnvDTE.Property.Properties.Item(object index)**에 문자열로 전달해야 합니다.

Project project;
ProjectItem folder;
Properties folderProps;
Property prop;
project = _applicationObject.Solution.Projects.Item(1);
folder = project.ProjectItems.AddFolder("MyFolder"
,Constants.vsProjectItemKindPhysicalFolder);
folderProps = folder.Properties;
prop = folderProps.Item("FullPath");

이 코드는 Visual C# 또는 Visual Basic 프로젝트 내에 있는 폴더의 FullPath 속성에 액세스합니다.

실제로 FolderProperties2에 정의된 속성은 Visual C# 또는 Visual Basic의 프로젝트 속성 항목으로 액세스할 수 있는 사용 가능한 폴더 속성에 대한 참조 목록입니다.

아래 단계에서는 Visual Studio 추가 기능을 통해 프로그래밍 방식으로 이러한 속성에 액세스하는 방법을 설명합니다.

[!참고]

표시되는 대화 상자와 메뉴 명령은 활성 설정이나 버전에 따라 도움말에서 설명하는 것과 다를 수 있습니다.이러한 절차는 일반 개발 설정을 사용하여 개발되었습니다.설정을 변경하려면 도구 메뉴에서 설정 가져오기 및 내보내기를 선택합니다.자세한 내용은 Visual Studio 설정을 참조하십시오.

특정 형식의 프로젝트에 대한 폴더 속성에 액세스하려면

  1. Visual C#을 사용하여 Visual Studio 추가 기능 프로젝트를 만듭니다.

  2. 프로젝트 메뉴에서 참조 추가를 클릭하고 .NET 탭을 클릭한 다음 VSLangProj, VSLangProj2VSLangProj80을 선택하고 확인을 클릭합니다.

  3. Connect.cs 파일의 맨 위에 다음과 같은 using 문을 추가합니다.

    using VSLangProj;
    using VSLangProj2;
    using VSLangProj80;
    
  4. OnConnection 메서드에 다음 메서드 호출을 추가합니다.

    public void OnConnection(object application, 
    ext_ConnectMode connectMode, object addInInst, ref Array custom)
    {
        _applicationObject = (DTE2)application;
        _addInInstance = (AddIn)addInInst;
        VSProjectFolderProps2(_applicationObject);
    }
    
  5. OnConnection 메서드 바로 아래 VSProjectFolderProps2 메서드를 추가합니다.

    public void VSProjectFolderProps2(DTE2 dte)
    {
        try
        {
            // Open a Visual C# or Visual Basic project
            // before running this add-in.
            Project project;
            ProjectItem folder;
            Properties folderProps;
            Property prop;
            project = _applicationObject.Solution.Projects.Item(1);
            // Add a new folder to the project.
            MessageBox.Show("Adding a new folder to the project.");
            folder =
     project.ProjectItems.AddFolder("MyFolder",
    Constants.vsProjectItemKindPhysicalFolder);
            folderProps = folder.Properties;
            prop = folderProps.Item("FullPath");
            MessageBox.Show("The full path of the new folder is:" 
    + "\n" + prop.Value.ToString());
            prop = folderProps.Item("FileName");
            MessageBox.Show("The file name of the new folder is:" 
    + "\n" + prop.Value.ToString());
            prop = folderProps.Item("URL");
            MessageBox.Show("The new folder has the following URL:" 
    + "\n" + prop.Value.ToString());
        }
        catch(Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }
    

    전체 코드는 예제 단원을 참조하십시오.

  6. 빌드 메뉴에서 솔루션 빌드를 클릭하여 추가 기능을 빌드합니다.

  7. Visual Studio IDE에서 Visual C# 또는 Visual Basic 프로젝트를 엽니다.

  8. 도구 메뉴에서 추가 기능 관리자를 클릭하고 추가 기능 관리자 대화 상자에서 추가 기능을 선택합니다.확인을 클릭하여 추가 기능을 실행합니다.

    FullPath, FileNameURL의 폴더 속성이 메시지 상자에 표시됩니다.

예제

다음은 Visual Studio 자동화를 사용하여 특정 프로젝트 형식의 폴더 속성에 액세스하는 방법을 보여 주는 기본 Visual Studio 추가 기능 예제입니다.

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;
    VSProjectFolderProps2(_applicationObject);
}
public void VSProjectFolderProps2(DTE2 dte)
{
    try
    {
        // Open a Visual C# or Visual Basic project
        // before running this add-in.
        Project project;
        ProjectItem folder;
        Properties folderProps;
        Property prop;
        project = _applicationObject.Solution.Projects.Item(1);
        // Add a new folder to the project.
        MessageBox.Show("Adding a new folder to the project.");
        folder =
 project.ProjectItems.AddFolder("MyFolder"
,Constants.vsProjectItemKindPhysicalFolder);
        folderProps = folder.Properties;
        prop = folderProps.Item("FullPath");
        MessageBox.Show("The full path of the new folder is:" + "\n" 
+ prop.Value.ToString());
        prop = folderProps.Item("FileName");
        MessageBox.Show("The file name of the new folder is:" + "\n" 
+ prop.Value.ToString());
        prop = folderProps.Item("URL");
        MessageBox.Show("The new folder has the following URL:" 
+ "\n" + 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)
    VSProjectConfigProperties(_applicationObject)
End Sub
Sub VSProjectConfigProperties(ByVal dte As DTE2)
    ' Open a Visual C# or Visual Basic project
    ' before running this add-in.
    Try
        Dim project As Project
        Dim folder As ProjectItem
        Dim folderProps As Properties
        Dim prop As [Property]
        project = _applicationObject.Solution.Projects.Item(1)
        ' Add a new folder to the project.
        MsgBox("Adding a new folder to the project...")
        folder = project.ProjectItems.AddFolder("MyFolder" _
        , Constants.vsProjectItemKindPhysicalFolder)
        folderProps = folder.Properties
        prop = folderProps.Item("FullPath")
        MsgBox("The full path of the new folder is:" & vbCr _
        & prop.Value.ToString())
        prop = folderProps.Item("FileName")
        MsgBox("The file name of the new folder is:" & vbCr _
        & prop.Value.ToString())
        prop = folderProps.Item("URL")
        MsgBox("The new folder has the following URL:" & vbCr  _
        & prop.Value.ToString())
    Catch ex As System.Exception
        MsgBox(ex.ToString)
    End Try
End Sub

코드 컴파일

이 코드를 컴파일하려면 새 Visual Studio 추가 기능 프로젝트를 만들고 OnConnection 메서드의 코드를 예제의 코드로 바꿉니다.추가 기능을 실행하는 방법에 대한 자세한 내용은 방법: 추가 기능 관리자를 사용하여 추가 기능 제어를 참조하십시오.

참고 항목

기타 리소스

Project Properties

특정 프로젝트 형식의 프로젝트, 프로젝트 항목 및 구성 속성에 액세스