AssemblyBuilder.AddAssemblyReference(Assembly) 方法

定义

添加为文件生成的源代码所引用的程序集。Adds an assembly that is referenced by source code generated for a file.

public:
 void AddAssemblyReference(System::Reflection::Assembly ^ a);
public void AddAssemblyReference (System.Reflection.Assembly a);
member this.AddAssemblyReference : System.Reflection.Assembly -> unit
Public Sub AddAssemblyReference (a As Assembly)

参数

a
Assembly

包含在程序集编译中的代码编译单元或源文件所引用的程序集。An assembly referenced by a code compile unit or source file included in the assembly compilation.

注解

BuildProvider AddAssemblyReference 生成引用输入程序集内的类型的源代码时,实现使用方法。A BuildProvider implementation uses the AddAssemblyReference method when generating source code that references types within the input assembly.

ASP.NET 生成环境初始化可在属性中通过生成提供程序引用的程序集的默认集合 BuildProvider.ReferencedAssembliesThe ASP.NET build environment initializes the default collection of assemblies available for reference through the build provider in the BuildProvider.ReferencedAssemblies property. 如果生成提供程序生成引用其他程序集的源代码,则生成提供程序使用方法添加其他程序集 AddAssemblyReferenceIf the build provider generates source code that references additional assemblies, the build provider adds the additional assemblies using the AddAssemblyReference method. ASP.NET 生成环境使用由生成提供程序添加的引用的程序集和可供引用的程序集的默认集合来解析程序集编译过程中的外部类型。The ASP.NET build environment resolves external types during assembly compilation using both the referenced assemblies added by build providers and the default collection of assemblies available for reference.

通常, BuildProvider 对象会将源代码添加到 AssemblyBuilder 方法中的对象 GenerateCodeTypically, a BuildProvider object adds source code to the AssemblyBuilder object in the GenerateCode method. 如果生成提供程序生成使用外部类型的源代码,则生成提供程序使用方法添加该类型的程序集 AssemblyBuilder.AddAssemblyReferenceIf a build provider generates source code that uses an external type, the build provider adds the type's assembly using the AssemblyBuilder.AddAssemblyReference method.

使用 AddAssemblyReference 方法可添加 BuildProvider 特定文件类型的实例所生成的源代码中所需的引用程序集。Use the AddAssemblyReference method to add a referenced assembly required in source code generated by a BuildProvider instance for a specific file type. 使用 assembly 元素进行编译 (ASP.NET 设置架构) 配置元素,以配置程序集以在项目中跨多个文件类型进行引用。Use the assemblies Element for compilation (ASP.NET Settings Schema) configuration element to configure an assembly for reference across multiple file types in a project.

适用于

另请参阅