VSWebSite Interface

 

Provides properties and methods for a Web site project.

Namespace:   VsWebSite
Assembly:  VsWebSite.Interop (in VsWebSite.Interop.dll)

Syntax

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

Properties

Name Description
System_CAPS_pubproperty CodeFolders

Gets a collection of folders that are configured as code folders in the Web site.

System_CAPS_pubproperty DTE

Gets a reference to the DTE2 object that contains this Web site project.

System_CAPS_pubproperty Project

Gets a reference to this Web site as a T:EnvDTE80.Project object.

System_CAPS_pubproperty References

Gets an AssemblyReferences object containing references to assemblies and projects for the current Web site.

System_CAPS_pubproperty TemplatePath

Gets the full path and name of the folder that contains templates for Web site items.

System_CAPS_pubproperty URL

Gets the URL that was used to open the Web site.

System_CAPS_pubproperty UserTemplatePath

Gets the path to the user templates folder for new project items.

System_CAPS_pubproperty VSWebSiteEvents

Gets the VSWebSiteEvents object for the Web site, which can be used to add event handlers.

System_CAPS_pubproperty WebReferences

Gets a WebReferences object containing references to the Web services consumed by the Web site.

System_CAPS_pubproperty WebServices

Gets a WebServices object containing a collection of Web services that are exposed by this Web site.

Methods

Name Description
System_CAPS_pubmethod AddFromTemplate(String, String, String, String, Boolean, String, String)

Creates a new ProjectItem in the Web site project.

System_CAPS_pubmethod EnsureServerRunning()

Starts the ASP.NET Development Server, if necessary, and returns the URL for the Web site.

System_CAPS_pubmethod GetUniqueFilename(String, String, String)

Returns a filename that is unique within the specified folder, using the specified root name and file name extension.

System_CAPS_pubmethod PreCompileWeb(String, Boolean)

Compiles the Web site and writes the compiled output to the specified folder.

System_CAPS_pubmethod Refresh()

Refreshes the display to account for changes that have been made to the Web site outside of Visual Studio.

System_CAPS_pubmethod WaitUntilReady()

Blocks all method calls until background processes have finished executing.

Remarks

Use the VSWebSite interface to manipulate a Web site project from either a macro or from an add-in to Visual Studio.

Besides the properties and methods in this class, there are more properties for Web site projects available using the WebSiteProperties class.

Note

The functionality provided by this class is available in versions of Visual Studio starting with Visual Studio 2005. It is not available in Visual Web Developer Express Edition.

Examples

The following example shows how to use an add-in to interact with a Visual Studio Web site project. The add-in uses event handlers to write to the event log when either a reference to an assembly or a Web reference to a Web service is added to the project. In addition, it writes a summary of each Web site project to a text file when the solution is closed.

To run the example, use the How to: Create an Add-In to create an add-in project, and replace all of the code in the resulting Connect.cs file with the sample code. You will also need to create a reference to the VsWebSite.Interop assembly.

[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
}

See Also

EnvDTE
WebSiteProperties
VsWebSite Namespace
Automation and Extensibility Reference
Referencing Automation Assemblies and the DTE2 Object

Creating Add-ins and Wizards
d300ae97-9048-4c35-90e5-87473f0528ca

Return to top