Compartir a través de


VSWebSite (Interfaz)

Proporciona propiedades y métodos para un proyecto de sitio web.

Espacio de nombres:  VsWebSite
Ensamblado:  VsWebSite.Interop (en VsWebSite.Interop.dll)

Sintaxis

'Declaración
<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

El tipo VSWebSite expone los siguientes miembros.

Propiedades

  Nombre Descripción
Propiedad pública CodeFolders Obtiene una colección de carpetas configuradas como carpetas de código en el sitio web.
Propiedad pública DTE Obtiene una referencia al objeto DTE2 que contiene el proyecto de sitio web.
Propiedad pública Project Obtiene una referencia al sitio web como un objeto Project.
Propiedad pública References Obtiene un objeto AssemblyReferences que contiene las referencias a los ensamblados y proyectos para el sitio web actual.
Propiedad pública TemplatePath Obtiene la ruta de acceso completa y nombre de la carpeta que contiene las plantillas para los elementos del sitio web.
Propiedad pública URL Obtiene la dirección URL utilizada para abrir el sitio web.
Propiedad pública UserTemplatePath Obtiene la ruta de acceso a la carpeta de plantillas de usuario para los nuevos elementos de proyecto.
Propiedad pública VSWebSiteEvents Obtiene el objeto VSWebSiteEvents para el sitio web, que se puede utilizar para agregar controladores de eventos.
Propiedad pública WebReferences Obtiene un objeto WebReferences que contiene referencias a los servicios Web utilizados por el sitio web.
Propiedad pública WebServices Obtiene un objeto WebServices que contiene una colección de servicios Web expuestos por este sitio web.

Arriba

Métodos

  Nombre Descripción
Método público AddFromTemplate Crea un nuevo ProjectItem en el proyecto de sitio web.
Método público EnsureServerRunning Inicia el servidor de desarrollo de ASP.NET si es necesario y devuelve la dirección URL del sitio web.
Método público GetUniqueFilename Devuelve un nombre de archivo que es único dentro de la carpeta especificada, con el nombre raíz especificado y la extensión de nombre de archivo.
Método público PreCompileWeb Compila el sitio web y escribe el resultado de compilación en la carpeta especificada.
Método público Refresh Actualiza la presentación para responder de los cambios realizados en el sitio web fuera de Visual Studio.
Método público WaitUntilReady Bloquea todas las llamadas a métodos hasta que los procesos en segundo plano terminen de ejecutarse.

Arriba

Comentarios

Utilice la interfaz VSWebSite para manipular un proyecto de sitio web desde una macro o un complemento de Visual Studio.

Además de las propiedades y métodos de esta clase, hay más propiedades disponibles para los proyectos de sitio web mediante la clase WebSiteProperties.

NotaNota

La funcionalidad que proporciona esta clase está disponible en versiones de arranque de Visual Studio con Visual Studio 2005.No está disponible en Visual Web Developer Express.

Ejemplos

En el ejemplo siguiente se muestra cómo utilizar un complemento para interactuar con un proyecto de sitio web de Visual Studio. El complemento utiliza los controladores de eventos para escribir en el registro de eventos cuando se agrega al proyecto una referencia a un ensamblado o una referencia web a un servicio Web. Además, escribe un resumen de cada proyecto de sitio web en un archivo de texto cuando se cierra la solución.

Para ejecutar el ejemplo, utilice el Cómo: Crear un complemento para crear un proyecto de complemento y reemplace todo el código del archivo Connect.cs resultante por el código de ejemplo. También necesitará crear una referencia al ensamblado 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
}

Vea también

Referencia

VsWebSite (Espacio de nombres)

EnvDTE

WebSiteProperties

Otros recursos

Referencia de automatización y extensibilidad

Establecer referencias a los ensamblados de automatización y al objeto DTE2

Visual Studio Macros

Crear complementos y asistentes