AssemblyBuilder 클래스

정의

ASP.NET 프로젝트 내에서 하나 이상의 가상 경로를 사용하여 어셈블리를 빌드하기 위한 컨테이너를 제공합니다.

public ref class AssemblyBuilder
public class AssemblyBuilder
type AssemblyBuilder = class
Public Class AssemblyBuilder
상속
AssemblyBuilder

예제

다음 코드 예제에서는 추상에서 상속 하는 간단한 빌드 공급자 구현 BuildProvider 기본 클래스입니다. 빌드 공급자를 재정의 합니다 CodeCompilerType, GetGeneratedType, 및 GenerateCode 기본 클래스의 멤버입니다.

GenerateCode 사용 하 여 어셈블리 컴파일 생성된 된 코드를 추가 하는 메서드 구현 하는 빌드 공급자를 CreateCodeFile 메서드. 예제 구현의 포함 되지 않습니다는 SampleClassGenerator 클래스입니다. 자세한 내용은 CodeCompileUnit를 참조하세요.

using System;
using System.Collections;
using System.IO;
using System.Text;
using System.Web;
using System.Web.Compilation;
using System.CodeDom.Compiler;
using System.CodeDom;
using System.Security;
using System.Security.Permissions;

// Define a simple build provider implementation.
[PermissionSet(SecurityAction.Demand, Unrestricted = true)]
public class SampleBuildProvider : BuildProvider
{
    // Define an internal member for the compiler type.
    protected CompilerType _compilerType = null;

    public SampleBuildProvider()
    {
        // Set the compiler to use Visual Basic.
        _compilerType = GetDefaultCompilerTypeForLanguage("C#");
    }

    // Return the internal CompilerType member 
    // defined in this implementation.
    public override CompilerType CodeCompilerType
    {
        get { return _compilerType; }
    }

    // Define a method that returns details for the 
    // code compiler for this build provider.
    public string GetCompilerTypeDetails()
    {
        StringBuilder details = new StringBuilder("");

        if (_compilerType != null)
        {
            // Format a string that contains the code compiler
            // implementation, and various compiler details.

            details.AppendFormat("CodeDomProvider type: {0}; \n",
                _compilerType.CodeDomProviderType.ToString());
            details.AppendFormat("Compiler debug build = {0}; \n",
                _compilerType.CompilerParameters.IncludeDebugInformation.ToString());
            details.AppendFormat("Compiler warning level = {0}; \n",
                _compilerType.CompilerParameters.WarningLevel.ToString());

            if (_compilerType.CompilerParameters.CompilerOptions != null)
            {
                details.AppendFormat("Compiler options: {0}; \n",
                    _compilerType.CompilerParameters.CompilerOptions.ToString());
            }
        }
        return details.ToString();
    }

    // Define the build provider implementation of the GenerateCode method.
    public override void GenerateCode(AssemblyBuilder assemBuilder)
    {
        // Generate a code compile unit, and add it to
        // the assembly builder.

        TextWriter tw = assemBuilder.CreateCodeFile(this);
        if (tw != null)
        {
            try
            {
                // Generate the code compile unit from the virtual path.
                CodeCompileUnit compileUnit = SampleClassGenerator.BuildCompileUnitFromPath(VirtualPath);

                // Generate the source for the code compile unit, 
                // and write it to a file specified by the assembly builder.
                CodeDomProvider provider = assemBuilder.CodeDomProvider;
                provider.CreateGenerator().GenerateCodeFromCompileUnit(compileUnit, tw, null);
            }
            finally
            {
                tw.Close();
            }
        }
    }

    public override System.Type GetGeneratedType(CompilerResults results)
    {
        string typeName = SampleClassGenerator.TypeName;

        return results.CompiledAssembly.GetType(typeName);
    }
}
Imports System.Collections
Imports System.IO
Imports System.Text
Imports System.Web
Imports System.Web.Compilation
Imports System.CodeDom.Compiler
Imports System.CodeDom
Imports System.Security
Imports System.Security.Permissions

<PermissionSet(SecurityAction.Demand, Unrestricted := true)> _
Public Class SampleBuildProvider
    Inherits BuildProvider

    Protected _compilerType As CompilerType = Nothing

    Public Sub New()
        _compilerType = GetDefaultCompilerType()
    End Sub

    ' Return the internal CompilerType member 
    ' defined in this implementation.
    Public Overrides ReadOnly Property CodeCompilerType() As CompilerType
        Get
            CodeCompilerType = _compilerType
        End Get
    End Property

    ' Define a method that returns details for the 
    ' code compiler for this build provider.
    Public Function GetCompilerTypeDetails() As String
        Dim details As StringBuilder = New StringBuilder("")

        If Not _compilerType Is Nothing Then
            ' Format a string that contains the code compiler
            ' implementation, and various compiler details.

            details.AppendFormat("CodeDomProvider type: {0}; ", _
                _compilerType.CodeDomProviderType.ToString())
            details.AppendFormat("Compiler debug build = {0}; ", _
                _compilerType.CompilerParameters.IncludeDebugInformation.ToString())
            details.AppendFormat("Compiler warning level = {0}; ", _
                _compilerType.CompilerParameters.WarningLevel.ToString())

            If Not _compilerType.CompilerParameters.CompilerOptions Is Nothing Then
                details.AppendFormat("Compiler options: {0}; ", _
                    _compilerType.CompilerParameters.CompilerOptions.ToString())
            End If
        End If
        Return details.ToString()
    End Function

    ' Define the build provider implementation of the GenerateCode method.
    Public Overrides Sub GenerateCode(ByVal assemBuilder As AssemblyBuilder)
        ' Generate a code compile unit, and add it to
        ' the assembly builder.

        Dim tw As TextWriter = assemBuilder.CreateCodeFile(Me)
        If Not tw Is Nothing Then
            Try
                ' Generate the code compile unit from the virtual path.
                Dim compileUnit As CodeCompileUnit = _
                        SampleClassGenerator.BuildCompileUnitFromPath(VirtualPath)

                ' Generate the source for the code compile unit, 
                ' and write it to a file specified by the assembly builder.
                Dim provider As CodeDomProvider = assemBuilder.CodeDomProvider
                provider.CreateGenerator().GenerateCodeFromCompileUnit(compileUnit, tw, Nothing)
            Finally
                tw.Close()
            End Try

        End If
    End Sub

    Public Overrides Function GetGeneratedType(ByVal results As CompilerResults) As System.Type
        Dim typeName As String = SampleClassGenerator.TypeName

        Return results.CompiledAssembly.GetType(typeName)
    End Function

End Class

설명

인스턴스를 AssemblyBuilder 클래스와 함께 사용 됩니다 BuildProvider 클래스 메서드를 컴파일된 어셈블리에 하나 이상의 파일을 빌드해야 합니다.

합니다 BuildProvider 개별 파일에 대 한 빌드 기능을 정의 하는 클래스 및 AssemblyBuilder 클래스는 각 소스 코드를 결합 BuildProvider 인스턴스를 단일 어셈블리로 합니다. ASP.NET 빌드 환경을 AssemblyBuilder 개체를 BuildProvider 메서드 하나 이상의 파일에서 어셈블리를 빌드할 때 하므로 각 BuildProvider 인스턴스에서 해당 파일을 전체 어셈블리에 대 한 소스 코드를 제공할 수입니다.

ASP.NET 빌드 환경의 언어 및 컴파일러에 따라 프로젝트 내의 파일에 필요한 결정을 BuildProvider.CodeCompilerType 속성입니다. 빌드 환경 그룹 해당 컴파일러 설정에 따라 파일과 동일한 컴파일러를 필요로 하는 파일에서 어셈블리를 빌드합니다.

합니다 CodeDomProvider 속성을 나타냅니다는 CodeDomProvider 구현은 소스 코드에서 어셈블리를 컴파일하려면는 ASP.NET 빌드 환경의 각 제공한 BuildProvider 구현 합니다.

A BuildProvider 사용 하 여 CodeDOM 그래프의 형태로 소스 코드를 적용 하는 개체는 AddCodeCompileUnit 메서드. A BuildProvider 사용 하는 물리적 파일에 저장 된 소스 코드를 적용 하는 개체는 CreateCodeFile 메서드.

BuildProvider 개체가 사용 하 여 적절 한 소스 코드 기여 AssemblyBuilder 메서드는 ASP.NET 빌드 환경 사용의 AssemblyBuilder 수집된 된 소스 코드를 어셈블리로 컴파일하는 데 클래스.

속성

CodeDomProvider

소스 코드를 어셈블리로 빌드하는 데 사용되는 컴파일러를 가져옵니다.

메서드

AddAssemblyReference(Assembly)

파일에 대해 생성된 소스 코드에서 참조하는 어셈블리를 추가합니다.

AddCodeCompileUnit(BuildProvider, CodeCompileUnit)

CodeDOM 그래프 형식으로 어셈블리에 대한 소스 코드를 추가합니다.

CreateCodeFile(BuildProvider)

빌드 공급자에서 임시 소스 파일을 만들고 어셈블리 컴파일에 소스 파일을 포함할 수 있도록 합니다.

CreateEmbeddedResource(BuildProvider, String)

빌드 공급자가 어셈블리 컴파일에 포함할 리소스 파일을 만들 수 있도록 합니다.

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GenerateTypeFactory(String)

형식에 대한 빠른 개체 팩터리 템플릿을 컴파일된 어셈블리에 삽입합니다.

GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetTempFilePhysicalPath(String)

임시 파일 경로를 생성합니다.

GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상

추가 정보