Share via


VSWebSite インターフェイス

Web サイト プロジェクトのプロパティおよびメソッドを提供します。

名前空間:  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 型で公開されるメンバーは以下のとおりです。

プロパティ

  名前 説明
パブリック プロパティ CodeFolders Web サイト内のコード フォルダーとして構成されているフォルダーのコレクションを取得します。
パブリック プロパティ DTE この Web サイト プロジェクトが含まれている DTE2 オブジェクトへの参照を取得します。
パブリック プロパティ Project この Web サイトへの参照を Project オブジェクトとして取得します。
パブリック プロパティ References 現在の Web サイトのアセンブリおよびプロジェクトへの参照を格納する AssemblyReferences オブジェクトを取得します。
パブリック プロパティ TemplatePath Web サイト項目のテンプレートが格納されているフォルダーの完全パスおよび名前を取得します。
パブリック プロパティ URL Web サイトを開くために使用された URL を取得します。
パブリック プロパティ UserTemplatePath 新しいプロジェクト項目のユーザー テンプレート フォルダーのパスを取得します。
パブリック プロパティ VSWebSiteEvents Web サイトの VSWebSiteEvents オブジェクトを取得します。このオブジェクトを使ってイベント ハンドラーを追加できます。
パブリック プロパティ WebReferences Web サイトで使用されている Web サービスへの参照が含まれている WebReferences オブジェクトを取得します。
パブリック プロパティ WebServices この Web サイトが公開する Web サービスのコレクションが含まれている WebServices オブジェクトを取得します。

このページのトップへ

メソッド

  名前 説明
パブリック メソッド AddFromTemplate Web サイト プロジェクトに新しい ProjectItem を作成します。
パブリック メソッド EnsureServerRunning 必要に応じて ASP.NET 開発サーバーを起動し、Web サイトの URL を返します。
パブリック メソッド GetUniqueFilename 指定されたルート名とファイル名拡張子を使用し、指定されたフォルダー内で一意であるファイル名を返します。
パブリック メソッド PreCompileWeb Web サイトをコンパイルし、指定されたフォルダーにコンパイルの出力結果を書き込みます。
パブリック メソッド Refresh Visual Studio の外で行われた Web サイトへの変更が反映されるように表示を更新します。
パブリック メソッド WaitUntilReady バックグラウンド処理の実行が完了するまで、すべてのメソッド呼び出しをブロックします。

このページのトップへ

解説

VSWebSite インターフェイスを使用することで、Visual Studio のアドインやマクロから Web サイト プロジェクトを操作できます。

このクラスで提供されるプロパティおよびメソッド以外にも、Web サイト プロジェクトに使用できるプロパティが WebSiteProperties クラスに用意されています。

注意

このクラスで提供される機能は、Visual Studio 2005 以降のバージョンの Visual Studio で使用できます。これは、Visual Web Developer Express Edition では使用できません。

次の例は、Visual Studio の Web サイト プロジェクトを操作するアドインの使用方法を示しています。 このアドインは、アセンブリへの参照または Web サービスへの Web 参照がプロジェクトに追加されたときに、イベント ハンドラーを使ってイベント ログを出力します。 さらに、ソリューションを閉じると、各 Web サイト プロジェクトの概要がテキスト ファイルに出力されます。

この例を実行するには、方法 : アドインを作成するを使用してアドイン プロジェクトを作成し、その結果として生成された 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

アドインおよびウィザードの作成