IAssemblyPostProcessor.PostProcessAssembly(String) 方法     
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
在加载程序集之前调用,可允许实现类对程序集进行修改。
public:
 void PostProcessAssembly(System::String ^ path);public void PostProcessAssembly(string path);abstract member PostProcessAssembly : string -> unitPublic 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 编译程序集后调用此方法。 在加载程序集之前要执行的任何操作都应包含在此方法中。