This documentation is archived and is not being maintained.

AssemblyBuilder::CreateCodeFile Method

Allows a build provider to create a temporary source file, and include the source file in the assembly compilation.

Namespace:  System.Web.Compilation
Assembly:  System.Web (in System.Web.dll)

public:
TextWriter^ CreateCodeFile(
	BuildProvider^ buildProvider
)

Parameters

buildProvider
Type: System.Web.Compilation::BuildProvider

The build provider generating the code source file.

Return Value

Type: System.IO::TextWriter
An open TextWriter that can be used to write source code to a temporary file.

A BuildProvider implementation calls the CreateCodeFile method when generating a source file for a virtual path. Source code added with CreateCodeFile is included in the assembly compilation.

Typically, a build provider GenerateCode method implementation reads the VirtualPath property, parses the contents, and then adds the generated source code to the specified AssemblyBuilder object. The build provider uses the CreateCodeFile method to add source code as a physical file to the assembly. Alternately, the build provider can use the AddCodeCompileUnit method to add source code as a CodeDOM graph to the assembly.

After calling CreateCodeFile, the build provider writes the source file contents using the returned TextWriter object. After writing the source file, the BuildProvider object must use the Close method to close the TextWriter object and free associated system resources.

The following code example illustrates a simple build provider implementation, inheriting from the abstract BuildProvider base class. The build provider overrides the CodeCompilerType, GetGeneratedType, and GenerateCode members of the base class.

In the GenerateCode method implementation, the build provider adds the generated code for the assembly compilation using the CreateCodeFile method. The example does not include the implementation of the SampleClassGenerator class. For more information, see CodeCompileUnit.

No code example is currently available or this language may not be supported.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0
Show: