IAssemblyPostProcessor IAssemblyPostProcessor IAssemblyPostProcessor IAssemblyPostProcessor Interface

定義

定義類別實作的方法,用來在已建置組件後處理組件。Defines the method a class implements to process an assembly after the assembly has been built.

public interface class IAssemblyPostProcessor : IDisposable
public interface IAssemblyPostProcessor : IDisposable
type IAssemblyPostProcessor = interface
    interface IDisposable
Public Interface IAssemblyPostProcessor
Implements IDisposable
實作

範例

下列程式碼範例示範如何建立實作IAssemblyPostProcessor介面,並在 Web 應用程式的 Web.config 檔案中註冊它。The following code example demonstrates how to create an implementation of the IAssemblyPostProcessor interface, and register it in the Web.config file of a Web application.

在程式碼範例的第一個部分會建立名為類別Samples.Process.postProcessTest實作IAssemblyPostProcessor介面。The first part of the code example creates a class named Samples.Process.postProcessTest that implements the IAssemblyPostProcessor interface. 這個類別會執行寫入檔案的簡單動作時PostProcessAssembly呼叫方法。This class performs the simple action of writing a file when the PostProcessAssembly method is called.

using System;
using System.Web.Compilation;
using System.IO;

namespace Samples.Process
{
    public class postProcessTest : IAssemblyPostProcessor
    {
        public static void Main(String[] args)
        {
        }

        public void PostProcessAssembly(string path)
        {
            StreamWriter sw = File.CreateText(@"c:\compile\MyTest.txt");
            sw.WriteLine("Compiled assembly:");
            sw.WriteLine(path);
            sw.Close();
        }

        public void Dispose()
        {

        }
    }
}
Imports Microsoft.VisualBasic
Imports System
Imports System.Web.Compilation
Imports System.IO

Namespace Samples.Process
    Public Class postProcessTest
        Implements IAssemblyPostProcessor

        Sub Main()

        End Sub

        Public Sub PostProcessAssembly(ByVal path As String) _
            Implements IAssemblyPostProcessor.PostProcessAssembly
            Dim sw As StreamWriter
            sw = File.CreateText("c:\compile\MyTest.txt")
            sw.WriteLine("Compiled assembly:")
            sw.WriteLine(path)
            sw.Close()
        End Sub

        Public Sub Dispose() Implements IDisposable.Dispose

        End Sub
    End Class
End Namespace

將類別編譯成.dll 檔案,使用命令csc /target:library postProcessTest.csCompile the class into a .dll file with the command csc /target:library postProcessTest.cs. 將產生的.dll 檔案新增至 ASP.NET 應用程式的 Bin 資料夾,並在 Web.config 檔案中,登錄此.dll 檔,如下列程式碼所示。Add the resulting .dll file to the Bin folder of an ASP.NET application and register the .dll in the Web.config file, as shown in the following code.

<compilation debug="true" assemblyPostProcessorType="Samples.Process.postProcessTest" />  

當使用者造訪網站時,動態編譯的 Web 應用程式和檔案會以 C:\compile 寫入 MyTest.txt。When a user visits the Web site, the Web application is dynamically compiled and the file MyTest.txt will be written to C:\compile.

備註

已編譯之後,實作此介面的類別可以存取組件。A class implementing this interface can access an assembly after it has been compiled. AssemblyBuilder類別會編譯組件,然後檢查是否IAssemblyPostProcessor介面已註冊的 Web 組態檔中。The AssemblyBuilder class compiles assemblies and then checks to see whether an IAssemblyPostProcessor interface has been registered in the Web configuration file. 如果是的話AssemblyBuilder執行個體呼叫PostProcessAssembly方法IAssemblyPostProcessor介面來執行編譯後再載入組件的任何動作。If so, the AssemblyBuilder instance calls the PostProcessAssembly method for the IAssemblyPostProcessor interface to perform any action after the compilation and before loading the assembly. 例如,分析工具可以實作這個介面來建立組件中的探查。For example, a profiler tool could implement this interface to establish probes in the assembly.

IAssemblyPostProcessor介面註冊、 ASP.NET 應用程式和其組件將一律會編譯偵錯模式中。When an IAssemblyPostProcessor interface is registered, the ASP.NET application and its assemblies will always be compiled in debug mode.

方法

Dispose() Dispose() Dispose() Dispose()

執行與釋放 (Free)、釋放 (Release) 或重設 Unmanaged 資源相關聯之應用程式定義的工作。Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

(Inherited from IDisposable)
PostProcessAssembly(String) PostProcessAssembly(String) PostProcessAssembly(String) PostProcessAssembly(String)

在載入組件之前呼叫,以允許實作的類別修改組件。Called before the assembly is loaded to allow the implementing class to modify the assembly.

適用於