Share via


Web Application Project Model Essentials (C#)

The Web application project (WAP) model add-on to Visual Studio 2005 provides a project-file-based structure for Web projects similar to that used in Visual Studio. WAP supports Visual C# and Visual Basic project types; you can extend it to support your language and project type by providing the following:

  • Code-behind code generator.

  • Code-behind event binder.

  • WAP project factory.

  • WAP properties.

  • WAP-specific project and item templates.

Note

You can download WAP and its prerequisites for Visual Studio 2005 from https://msdn.microsoft.com/asp.net/reference/infrastructure/wap/default.aspx.

Requirements

WAP works by customizing your project type through subtyping (also known as flavoring). Therefore, your project type must support subtyping to be usable as a WAP project type.

Note

Project types you develop with the Managed Package Framework (MPF) automatically support subtyping. For C++ or managed VSPackages you develop without the MPF, you must manually support subtyping. For more information, see Project Subtypes.

As the WAP system also supports a designer, supporting WAP also requires supporting the designer with appropriate code model and CodeDom language providers.

Code-behind code generator

The code-behind code generator generates declarations for controls added to Web pages. The WAP system includes a generator for Visual C# and Visual Basic project types. If you provide CodeDom and code model support for your language, you can subclass CodeBehindCodeGenerator which calls the WAP generator. The WAP generator uses the code model to parse code-behind and designer source files and then uses CodeDom to generate the designer source-file contents.

For example, the IronPython code-behind code generator (in [Visual Studio SDK installation path]\VisualStudioIntegration\Samples\IronPythonIntegration\Project\PythonCodeBehindCodeGenerator.cs) consists of just two methods:

internal class PythonCodeBehindCodeGenerator : Microsoft.VisualStudio.Package.Web.CodeBehindCodeGenerator
{
  public PythonCodeBehindCodeGenerator()
  {
    this.IsPartialClassDisabled = true;
  }

  protected override bool ShouldDeclareField(string name, string typeName)
  {
    return false;
  }
}

PythonCodeBehindCodeGenerator relies on the CodeDom provider that is included with IronPython.

If you do not have a CodeDom provider, you can directly implement IVsCodeBehindCodeGenerator.

Code-behind event binder

The code-behind event binder lets the WAP system retrieve information about existing event handlers, create new ones, and open them in the editor. The WAP system includes code-behind event binders for Visual C# and Visual Basic project types. Those code-behind event binders use code model support; if your language offers code model support, you can use the Visual C# or Visual Basic code-behind event binders.

For example, the IronPython project type registers its code-behind event binder using the GUID of the Visual C# code-behind event binder ({349c5856-65df-11da-9384-00065b846f21}). (See "WAP properties," later, for the attribute that registers the code-behind event binder.)

If your language does not support the code model, you can directly implement IVsCodeBehindEventBinding.

WAP project factory

You must provide a project factory only to register support for WAP. The WAP project factory does nothing; it just provides a GUID to register support for WAP and to register WAP properties specific to your language and project type.

For example, here is the WAP project factory for IronPython (from [Visual Studio SDK installation path]\VisualStudioIntegration\Samples\IronPythonIntegration\Project\PythonProject.cs):

[GuidAttribute("0C1E5196-4828-499e-9F72-98268B955B28")]
public class WAPythonProjectFactory { }

You then associate the WAP project factory with your real project factory by applying the WAProvideProjectFactoryAttribute and WAProvideProjectFactoryTemplateMappingAttribute attributes to your project package, which is of type ProjectPackage:

...
[WAProvideProjectFactory(typeof(WAPythonProjectFactory), "IronPython Web Application Project Templates", "IronPython", false, "Web", null)]
[WAProvideProjectFactoryTemplateMapping("{" + PythonProjectFactory.PythonProjectFactoryGuid + "}", typeof(WAPythonProjectFactory))]
...
public class PythonProjectPackage : ProjectPackage
{
  ...
}

The RegPkg tool reads the attributes to generate the appropriate registration. For more information, see How to: Register a VSPackage (C#) and How to: Generate Registry Information for an Installer (C#).

WAP properties

Your project type must provide certain properties for the WAP system by applying the WAProvideLanguagePropertyAttribute attribute to your project package. The following table lists the available properties:

Property

Required

Description

CodeBehindCodeGenerator

Yes

See "Code-behind code generator."

CodeBehindEventBinding

Yes

See "Code-behind event builder."

CodeFileExtension

Yes

Extension for code-behind files.

DebugPageGUID

No

GUID of a debugging property page; the WAP system replaces it with a WAP-specific page.

RootIcon

No

Resource ID of an icon Solution Explorer displays for the WAP project node.

TemplateFolder

Yes

Name of subdirectory for WAP project and item templates.

For example, here are the WAP properties for IronPython (from [Visual Studio SDK installation path]\VisualStudioIntegration\Samples\IronPythonIntegration\Project\PythonProject.cs):

...
[WAProvideLanguageProperty(typeof(WAPythonProjectFactory), "CodeFileExtension", ".py")]
[WAProvideLanguageProperty(typeof(WAPythonProjectFactory), "TemplateFolder", "IronPython")]
//[WAProvideLanguageProperty(typeof(WAPythonProjectFactory), "RootIcon", "#8001")]
[WAProvideLanguageProperty(typeof(WAPythonProjectFactory), "CodeBehindEventBinding", "349c5856-65df-11da-9384-00065b846f21"/*typeof(CSWACodeBehindEventBinding)*/)]   // class implementing IVsCodeBehindEventBinding
[WAProvideLanguageProperty(typeof(WAPythonProjectFactory), "CodeBehindCodeGenerator", typeof(PythonCodeBehindCodeGenerator))] // class implementing IVsCodeBehindCodeGenerator
[ProvideObject(typeof(PythonCodeBehindCodeGenerator))]
//The following value would be the guid of the Debug property page for IronPython (if it existed). The reason this guid is needed is so
//WAP can hide it from the user.
//[WAProvideLanguageProperty(typeof(WAPythonProjectFactory), "DebugPageGUID", "{00000000-1008-4FB2-A715-3A4E4F27E610}")]
public class PythonProjectPackage : ProjectPackage
{
  ...
}

WAP-specific project and item templates

Because WAP works by subtyping your project type, your WAP templates must include the GUIDs for both your project factory and WAP. For example, the IronPython Web application project template (from [Visual Studio SDK installation path]\VisualStudioIntegration\Samples\IronPythonIntegration\Project\Templates\Projects\Web\WebApplication\WebApplication.pyproj) includes the following property:

<Project DefaultTargets="Build" xmlns="https://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    ...
    <ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{af48b115-53db-4e4f-a04c-cf2b83c29ee3}</ProjectTypeGuids>
    ...
  </PropertyGroup>
  ...
</Project>

{349c5851-65df-11da-9384-00065b846f21} is the GUID for WAP. {af48b115-53db-4e4f-a04c-cf2b83c29ee3} is the GUID for the IronPython project factory. Note that the project specifies the real project factory, not the "do-nothing" WAP project factory.

For more information, see Web Application Project Templates.

See Also

Concepts

Discovering Code by Using the Code Model (Visual C#)

Reference

CodeModel

Other Resources

IronPython Web Site Support System

IronPython Windows Forms Designer and CodeDOM Sample