Edit

Share via


IAssemblyPostProcessor.PostProcessAssembly(String) Method

Definition

Called before the assembly is loaded to allow the implementing class to modify the assembly.

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

Parameters

path
String

The path to the assembly.

Examples

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.

The first part of the code example creates a class named Samples.Process.postProcessTest that implements the IAssemblyPostProcessor interface. 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 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

Compile the class into a .dll file with the command csc /target:library postProcessTest.cs. 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" />  

When a user visits the Web site, the Web application is dynamically compiled and the file MyTest.txt will be written to C:\compile.

Remarks

The AssemblyBuilder class calls this method after the assembly has been compiled. Any actions to be taken before loading the assembly should be included in this method.

Applies to