VSWebSite 인터페이스

웹 사이트 프로젝트의 속성 및 메서드를 제공합니다.

네임스페이스:  VsWebSite
어셈블리:  VsWebSite.Interop(VsWebSite.Interop.dll)

구문

‘선언
<GuidAttribute("70758CA4-91F8-46AD-80A7-73BC21BAE68B")> _
Public Interface VSWebSite
[GuidAttribute("70758CA4-91F8-46AD-80A7-73BC21BAE68B")]
public interface VSWebSite
[GuidAttribute(L"70758CA4-91F8-46AD-80A7-73BC21BAE68B")]
public interface class VSWebSite
[<GuidAttribute("70758CA4-91F8-46AD-80A7-73BC21BAE68B")>]
type VSWebSite =  interface end
public interface VSWebSite

VSWebSite 형식에서는 다음과 같은 멤버를 노출합니다.

속성

  이름 설명
Public 속성 CodeFolders 웹 사이트에서 코드 폴더로 구성된 폴더의 컬렉션을 가져옵니다.
Public 속성 DTE 해당 사이트 프로젝트가 들어 있는 DTE2 개체에 대한 참조를 가져옵니다.
Public 속성 Project 해당 웹 사이트에 대한 참조를 Project 개체로 가져옵니다.
Public 속성 References 현재 웹 사이트의 어셈블리 및 프로젝트에 대한 참조가 들어 있는 AssemblyReferences 개체를 가져옵니다.
Public 속성 TemplatePath 웹 사이트 항목의 템플릿이 들어 있는 폴더의 전체 경로 및 이름을 가져옵니다.
Public 속성 URL 웹 사이트를 여는 데 사용된 URL을 가져옵니다.
Public 속성 UserTemplatePath 새 프로젝트 항목의 사용자 템플릿 폴더 경로를 가져옵니다.
Public 속성 VSWebSiteEvents 이벤트 처리기를 추가하는 데 사용할 수 있는 웹 사이트의 VSWebSiteEvents 개체를 가져옵니다.
Public 속성 WebReferences 웹 사이트에 사용되는 웹 서비스에 대한 참조가 들어 있는 WebReferences 개체를 가져옵니다.
Public 속성 WebServices 해당 웹 사이트에서 노출하는 웹 서비스 컬렉션이 들어 있는 WebServices 개체를 가져옵니다.

위쪽

메서드

  이름 설명
Public 메서드 AddFromTemplate 웹 사이트 프로젝트에 새 ProjectItem을 만듭니다.
Public 메서드 EnsureServerRunning 필요한 경우 ASP.NET Development Server를 시작하고 웹 사이트의 URL을 반환합니다.
Public 메서드 GetUniqueFilename 지정된 루트 이름 및 파일 확장명을 사용하여 지정된 폴더 내에서 고유한 파일 이름을 반환합니다.
Public 메서드 PreCompileWeb 웹 사이트를 컴파일하고 지정한 폴더에 컴파일 출력을 씁니다.
Public 메서드 Refresh 화면 표시를 새로 고쳐 Visual Studio 외부에서 웹 사이트를 변경한 내용을 반영합니다.
Public 메서드 WaitUntilReady 백그라운드 프로세스의 실행이 완료될 때까지 모든 메서드 호출을 차단합니다.

위쪽

설명

VSWebSite 인터페이스를 사용하여 매크로나 추가 기능을 통해 Visual Studio에서 웹 사이트 프로젝트를 조작할 수 있습니다.

이 클래스의 속성 및 메서드 외에도 WebSiteProperties 클래스를 사용하여 웹 사이트 프로젝트의 추가 속성을 사용할 수 있습니다.

참고

이 클래스가 제공하는 기능은 Visual Studio 2005으로 시작하는 Visual Studio 버전에서 사용할 수 있습니다.Visual Web Developer Express 에디션에서는 이 기능을 사용할 수 없습니다.

예제

다음 예제에서는 추가 기능을 사용하여 Visual Studio 웹 사이트 프로젝트와 상호 작용하는 방법을 보여 줍니다. 이 추가 기능에서는 어셈블리에 대한 참조 또는 웹 서비스에 대한 웹 참조가 프로젝트에 추가될 때 이벤트 처리기를 사용하여 이벤트 로그에 데이터를 씁니다. 또한 솔루션을 닫을 때 각 웹 사이트 프로젝트에 대한 요약을 텍스트 파일에 씁니다.

이 예제를 실행하려면 방법: 추가 기능 만들기를 사용하여 추가 기능 프로젝트를 만들고 그 결과로 작성되는 Connect.cs 파일의 모든 코드를 샘플 코드로 바꿉니다. 또한 VsWebSite.Interop 어셈블리에 대한 참조를 만들어야 합니다.

[C#]

using System;
using System.IO;
using System.Collections;
using System.Diagnostics;
using Extensibility;
using EnvDTE;
using EnvDTE80;
using VsWebSite;

// The object for implementing an Add-in.
public class Connect : IDTExtensibility2
{
    private DTE2 _applicationObject;
    private AddIn _addInInstance;

    // Implements the constructor for the Add-in object.
    // Created by the Add-In Wizard
    public Connect()
    {
    }

    // Event method created by the Add-In Wizard.
    // Occurs when the Add-In connects with the application.
    public void OnConnection(object application, ext_ConnectMode 
        connectMode, object addInInst, ref Array custom)
    {
        _applicationObject = (DTE2)application;
        _addInInstance = (AddIn)addInInst;

        // Attach Solution event handlers
        _applicationObject.DTE.Events.SolutionEvents.Opened 
            += new _dispSolutionEvents_OpenedEventHandler
                (SolutionEvents_Opened);
        _applicationObject.DTE.Events.SolutionEvents.QueryCloseSolution 
            += new _dispSolutionEvents_QueryCloseSolutionEventHandler
                (SolutionEvents_QueryCloseSolution);
    }

    // Custom event method that occurs before a solution is closed.
    private void SolutionEvents_QueryCloseSolution(ref bool fCancel)
    {
        foreach (Project proj in _applicationObject.Solution.Projects)
        {
            // Make sure background compilation is finished
            ((VSWebSite)proj.Object).WaitUntilReady();

            System.Text.StringBuilder strBldr = 
                new System.Text.StringBuilder();

            strBldr.AppendLine("Summary for Web Site: " 
                + ((VSWebSite)proj.Object).URL);
            strBldr.AppendLine("Solution: " 
                + _applicationObject.Solution.FullName);
            strBldr.AppendLine("Web References:");
            foreach (WebReference wref in 
                ((VSWebSite)proj.Object).WebReferences)
                strBldr.AppendLine("    " + wref.Namespace);
            strBldr.AppendLine("Assembly References:");
            foreach (AssemblyReference aref in 
                ((VSWebSite)proj.Object).References)
                strBldr.AppendLine("    " + aref.Name);
            // list the files?

            ((VSWebSite)proj.Object).VSWebSiteEvents.WebReferencesEvents.WebReferenceAdded
                -= WebRefEvents_WebRefAdded;

            string strBody = strBldr.ToString();

            // Save the summary as a text file in the Web site.
            string fName = _applicationObject.FullName;
            fName = fName.Substring(0, fName.Length - 4);
            fName += "." + ((VSWebSite)proj.Object).GetUniqueFilename
                ("/", "ProjectSummary", ".txt");
            if (File.Exists(fName))
                File.Delete(fName);
            StreamWriter sw = File.CreateText(fName);
            sw.Write(strBody);
            sw.Close();
        }
    }

    // Custom event method that occurs when a solution is opened.
    private void SolutionEvents_Opened()
    {
        // When solution is opened, attach event handlers for projects
        foreach (Project proj in _applicationObject.Solution.Projects)
        {   // Only attach event handlers if it is a Web site
            if (proj.Object is VSWebSite)
            {
                ((VSWebSite)proj.Object).VSWebSiteEvents.WebReferencesEvents.WebReferenceAdded +=
                    new _dispWebReferencesEvents_WebReferenceAddedEventHandler
                    (WebRefEvents_WebRefAdded);
                ((VSWebSite)proj.Object).VSWebSiteEvents.AssemblyReferencesEvents.AssemblyReferenceAdded += 
                    new _dispAssemblyReferencesEvents_AssemblyReferenceAddedEventHandler
                    (AssemblyRefsEvents_AssemblyRefAdded);
            }
        }
    }

    // Custom event method that occurs when a Reference is added.
    private void AssemblyRefsEvents_AssemblyRefAdded(AssemblyReference AssemblyRef)
    {
        EventLog appLog = new EventLog();
        appLog.Source = "VSWSTest." + AssemblyRef.ContainingProject.Name;
        appLog.WriteEntry("AssemblyReference added: " + AssemblyRef.Name);
    }
    
    // Custom event method that occurs when a Web Reference is added.
    private void WebRefEvents_WebRefAdded(WebReference webRef)
    {
        EventLog appLog = new EventLog();
        appLog.Source = "VSWSTest." + webRef.ContainingProject.Name;
        appLog.WriteEntry("WebReference added: " + webRef.Namespace);
    }

    #region Required but unused event handlers

    /// <summary>Implements the OnDisconnection method of the IDTExtensibility2 interface. Receives notification that the Add-in is being unloaded.</summary>
    /// <param term='disconnectMode'>Describes how the Add-in is being unloaded.</param>
    /// <param term='custom'>Array of parameters that are host application specific.</param>
    /// <seealso class='IDTExtensibility2' />
    public void OnDisconnection(ext_DisconnectMode disconnectMode, ref Array custom)
    {
    }

    /// <summary>Implements the OnAddInsUpdate method of the IDTExtensibility2 interface. Receives notification when the collection of Add-ins has changed.</summary>
    /// <param term='custom'>Array of parameters that are host application specific.</param>
    /// <seealso class='IDTExtensibility2' />
    public void OnAddInsUpdate(ref Array custom)
    {
    }

    /// <summary>Implements the OnStartupComplete method of the IDTExtensibility2 interface. Receives notification that the host application has completed loading.</summary>
    /// <param term='custom'>Array of parameters that are host application specific.</param>
    /// <seealso class='IDTExtensibility2' />
    public void OnStartupComplete(ref Array custom)
    {
    }

    /// <summary>Implements the OnBeginShutdown method of the IDTExtensibility2 interface. Receives notification that the host application is being unloaded.</summary>
    /// <param term='custom'>Array of parameters that are host application specific.</param>
    /// <seealso class='IDTExtensibility2' />
    public void OnBeginShutdown(ref Array custom)
    {
    }

    #endregion
}

참고 항목

참조

VsWebSite 네임스페이스

EnvDTE

WebSiteProperties

기타 리소스

자동화 및 확장성 참조

자동화 어셈블리 및 DTE2 개체 참조

Visual Studio Macros

추가 기능 및 마법사 만들기