IAssemblyPostProcessor 介面

定義

定義類別實作的方法,用來在已建置組件後處理組件。

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

範例

下列程式碼範例示範如何建立 介面的 IAssemblyPostProcessor 實作,並在 Web 應用程式的 Web.config 檔案中註冊它。

程式碼範例的第一個部分會建立名為 Samples.Process.postProcessTest 的類別,以實作 IAssemblyPostProcessor 介面。 呼叫 方法時 PostProcessAssembly ,這個類別會執行撰寫檔案的簡單動作。

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 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

使用 命令 csc /target:library postProcessTest.cs 將 類別編譯成.dll檔案。 將產生的.dll檔案新增至 ASP.NET 應用程式的 Bin 資料夾,並在Web.config檔案中註冊.dll,如下列程式碼所示。

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

當使用者流覽網站時,會動態編譯 Web 應用程式,並將檔案MyTest.txt寫入 C:\compile。

備註

實作此介面的類別可以在編譯之後存取元件。 類別 AssemblyBuilder 會編譯元件,然後檢查 IAssemblyPostProcessor 是否已在 Web 組態檔中註冊介面。 如果是,實例會 AssemblyBuilder 呼叫 PostProcessAssembly 方法,讓 IAssemblyPostProcessor 介面在編譯之後和載入元件之前執行任何動作。 例如,分析工具工具可以實作此介面,以在元件中建立探查。

IAssemblyPostProcessor註冊介面時,ASP.NET 應用程式和其元件一律會在偵錯模式中編譯。

方法

Dispose()

執行與釋放 (Free)、釋放 (Release) 或重設 Unmanaged 資源相關聯之應用程式定義的工作。

(繼承來源 IDisposable)
PostProcessAssembly(String)

在載入組件之前呼叫,以允許實作的類別修改組件。

適用於