Condividi tramite


Interfaccia VSWebSite

Fornisce le proprietà e i metodi per un progetto di sito Web.

Spazio dei nomi:  VsWebSite
Assembly:  VsWebSite.Interop (in VsWebSite.Interop.dll)

Sintassi

'Dichiarazione
<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

Il tipo VSWebSite espone i seguenti membri.

Proprietà

  Nome Descrizione
Proprietà pubblica CodeFolders Ottiene un insieme di cartelle configurate come cartelle del codice nel sito Web.
Proprietà pubblica DTE Ottiene un riferimento all'oggetto DTE2 che contiene il progetto di sito Web.
Proprietà pubblica Project Ottiene un riferimento al sito Web come oggetto Project.
Proprietà pubblica References Ottiene un oggetto AssemblyReferences che contiene riferimenti ad assembly e progetti per il sito Web corrente.
Proprietà pubblica TemplatePath Ottiene il percorso completo e il nome della cartella che contiene i modelli per gli elementi del sito Web.
Proprietà pubblica URL Ottiene l'URL utilizzato per aprire il sito Web.
Proprietà pubblica UserTemplatePath Ottiene il percorso della cartella dei modelli utente per i nuovi elementi del progetto.
Proprietà pubblica VSWebSiteEvents Ottiene l'oggetto VSWebSiteEvents per il sito Web, che può essere utilizzato per aggiungere gestori eventi.
Proprietà pubblica WebReferences Ottiene un oggetto WebReferences che contiene riferimenti ai servizi Web utilizzati dal sito Web.
Proprietà pubblica WebServices Ottiene un oggetto WebServices che contiene un insieme di servizi Web esposti dal sito Web.

In alto

Metodi

  Nome Descrizione
Metodo pubblico AddFromTemplate Crea un nuovo oggetto ProjectItem nel progetto di sito Web.
Metodo pubblico EnsureServerRunning Avvia il server di sviluppo ASP.NET, se necessario, e restituisce l'URL del sito Web.
Metodo pubblico GetUniqueFilename Restituisce un nome file univoco all'interno della cartella specificata, utilizzando il nome della directory radice e l'estensione specificati.
Metodo pubblico PreCompileWeb Compila il sito Web e scrive l'output compilato nella cartella specificata.
Metodo pubblico Refresh Aggiorna la visualizzazione per mostrare le modifiche apportate al sito Web al di fuori di Visual Studio.
Metodo pubblico WaitUntilReady Blocca tutte le chiamate al metodo fino al termine dell'esecuzione dei processi in background.

In alto

Note

È possibile utilizzare l'interfaccia VSWebSite per modificare un progetto di sito Web da una macro o da un componente aggiuntivo di Visual Studio.

Oltre alle proprietà e ai metodi di questa classe, sono disponibili altre proprietà per i progetti di sito Web tramite la classe WebSiteProperties.

Nota

Le funzionalità fornite da questa classe sono disponibili a partire da Visual Studio 2005. Non è disponibile in Visual Web Developer Express Edition.

Esempi

Nell'esempio seguente viene illustrato come utilizzare un componente aggiuntivo per interagire con un progetto di sito Web di Visual Studio. Il componente aggiuntivo utilizza gestori eventi per registrare nel log eventi l'aggiunta al progetto di un riferimento a un assembly o di un riferimento Web a un servizio Web. Crea inoltre un riepilogo di ogni progetto di sito Web in un file di testo quando la soluzione viene chiusa.

Per eseguire l'esempio, utilizzare Procedura: creare un componente aggiuntivo per creare un progetto di componente aggiuntivo e sostituire tutto il codice nel file Connect.cs risultante con il codice di esempio. Sarà inoltre necessario creare un riferimento all'assembly 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
}

Vedere anche

Riferimenti

Spazio dei nomi VsWebSite

EnvDTE

WebSiteProperties

Altre risorse

Riferimenti su Extensibility e automazione

Riferimenti agli assembly di automazione e all'oggetto DTE2

Visual Studio Macro

Creazione di componenti aggiuntivi e di procedure guidate