IAssemblyPostProcessor.PostProcessAssembly(String) 方法

定義

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

public:
 void PostProcessAssembly(System::String ^ path);
public void PostProcessAssembly (string path);
abstract member PostProcessAssembly : string -> unit
Public Sub PostProcessAssembly (path As String)

參數

path
String

組件的路徑。

範例

下列程式碼範例示範如何建立 介面的 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 編譯元件之後呼叫這個方法。 載入元件之前應採取的任何動作都應該包含在此方法中。

適用於