Export (0) Print
Expand All

IAssemblyPostProcessor Interface

Defines the method a class implements to process an assembly after the assembly has been built.

Namespace:  System.Web.Compilation
Assembly:  System.Web (in System.Web.dll)

[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.High)]
[AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.High)]
public interface IAssemblyPostProcessor : IDisposable

The IAssemblyPostProcessor type exposes the following members.

  NameDescription
Public methodDisposePerforms application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. (Inherited from IDisposable.)
Public methodPostProcessAssemblyCalled before the assembly is loaded to allow the implementing class to modify the assembly.
Top

A class implementing this interface can access an assembly after it has been compiled. The AssemblyBuilder class compiles assemblies and then checks to see whether an IAssemblyPostProcessor interface has been registered in the Web configuration file. 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.

When an IAssemblyPostProcessor interface is registered, the ASP.NET application and its assemblies will always be compiled in debug mode.

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()
        {

        }
    }
}

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.

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft