IAssemblyPostProcessor.PostProcessAssembly(String) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
在載入組合語言前呼叫,讓實作類別修改該組合語言。
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.config 檔案中。
程式碼範例的第一部分建立一個名為 Samples.Process.postProcessTest class 的類別,實作介面。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
將類別編譯成一個 .dll 檔案,指令為 csc /target:library postProcessTest.cs。 將產生的 .dll 檔案加入 ASP.NET 應用程式的 Bin 資料夾,並在 Web.config 檔案中註冊該 .dll,如下程式碼所示。
<compilation debug="true" assemblyPostProcessorType="Samples.Process.postProcessTest" />
當使用者造訪網站時,網頁應用程式會被動態編譯,檔案 MyTest.txt 會寫入 C:\compile。
備註
AssemblyBuilder類別在組合語言編譯完成後呼叫此方法。 裝填組件前應採取的任何操作都應包含在此方法中。