Defines a set of properties and methods for generating source code within the ASP.NET build environment. This class is abstract.
See Also: BuildProvider Members
The ASP.NET build environment uses System.Web.Compilation.BuildProvider objects to generate source code for different file types within an application. Classes derived from System.Web.Compilation.BuildProvider predominantly provide source code for files, Web pages, resources, and other custom items.
Typically, you do not create an instance of the System.Web.Compilation.BuildProvider class directly. Instead, you implement a class that derives from System.Web.Compilation.BuildProvider, and configure the System.Web.Compilation.BuildProvider implementation for use within the ASP.NET build environment.
Instances of the System.Web.Compilation.BuildProvider class are used with System.Web.Compilation.AssemblyBuilder objects to build one or more files into a compiled assembly. A System.Web.Compilation.BuildProvider instance generates source code in the appropriate language for individual files, and the System.Web.Compilation.AssemblyBuilder object combines the source contributed by each System.Web.Compilation.BuildProvider instance into a single assembly.
The ASP.NET build environment uses instances of the System.Web.Compilation.BuildProvider class to build files within an application. The BuildProvider.VirtualPath property of the System.Web.Compilation.BuildProvider class indicates the path of the file to be built. The file extension of each file within an application is mapped to a corresponding build provider. The ASP.NET build environment initializes a System.Web.Compilation.BuildProvider instance for each file based on the file extension, and uses the System.Web.Compilation.BuildProvider methods to generate source code for the file. The ASP.NET build environment passes an System.Web.Compilation.AssemblyBuilder object based on the preferred compiler language and the context of the file to the System.Web.Compilation.BuildProvider methods when building an assembly from one or more files, so that the System.Web.Compilation.BuildProvider instance can contribute source code for its file to the overall assembly.
To define custom build actions for a file type within an ASP.NET application, you must derive a class from System.Web.Compilation.BuildProvider, implement members within the derived class for building the file type, and configure the build provider for the corresponding file extension within the application configuration file.
The add element specifies the file extension for supported files, and whether the build provider supports code files, Web files, resource files or all files. Use the type attribute to specify the fully qualified type name of the build provider implementation. Use the System.Web.Compilation.BuildProviderAppliesToAttribute class to specify whether the build provider applies to files in the App_Code directory, to files in a Web content directory, to global or local resources, or to all files. Use the extension attribute to specify the file extension used to identify files that the System.Web.Compilation.BuildProvider class supports. Use the System.Web.Configuration.BuildProviderCollection class to examine build providers in a configuration file. For more information about configuring a build provider, see buildproviders Element for compilation (ASP.NET Settings Schema).
To implement a build provider that generates source code for a custom file type, derive a class from System.Web.Compilation.BuildProvider, and override the BuildProvider.GenerateCode(AssemblyBuilder) method to generate source code for the supported file type. The generated source is added to the System.Web.Compilation.AssemblyBuilder object in the form of a CodeDOM graph, or as content that represents a physical source code file. If the build provider requires a specific programming language, override the BuildProvider.CodeCompilerType property to return a System.Web.Compilation.CompilerType object for the supported programming language. If the build provider does not require a specific programming language, do not override the BuildProvider.CodeCompilerType property; use the base class implementation, which indicates that the build provider can use any .NET Framework language, such as Visual Basic or C#.
To implement a build provider that generates source code for Web content, derive a class from System.Web.Compilation.BuildProvider and override the BuildProvider.GetGeneratedType(System.CodeDom.Compiler.CompilerResults) method to return the Type for the class generated by System.Web.Compilation.BuildProvider. Override the BuildProvider.GenerateCode(AssemblyBuilder) method to generate source code for the type provided by the supported file.
Adding a customized System.Web.Compilation.BuildProvider class to the Web.config file works in an ASP.NET Web site but does not work in an ASP.NET Web application project. In a Web application project, the code that is generated by the System.Web.Compilation.BuildProvider class cannot be included in the application. For more information, see Compiling Web Application Projects.