The -refout option specifies a file path in which the reference assembly should be output. This translates to metadataPeStream in the Emit API.
-refout:filepath
filepath | The name and path of the output file created by the compiler. |
The filename should generally match that of the primary assembly. The recommended convention (used by MSBuild) is to place the reference assembly in a "ref/" sub-folder relative to the primary assembly.
Metadata-only assemblies have their method bodies replaced with a single throw null body, but include all members except anonymous types. The reason for using throw null bodies, as opposed to no bodies, is to enable PEVerify to run and pass, thereby validating the completeness of the metadata.
Reference assemblies include an assembly-level ReferenceAssembly attribute. This attribute may be specified in source, in which case the compiler will not need to synthesize it. Because of this attribute, runtimes will refuse to load reference assemblies for execution, although they can still be loaded in reflection-only mode. Tools that reflect on assemblies should ensure they load reference assemblies as reflection-only; otherwise, they will receive a typeload error from the runtime.
Reference assemblies further remove metadata (private members) from metadata-only assemblies:
•A reference assembly contains references only for elements required by the API surface. The real assembly might include additional references for implementation-specific purposes.
•Private function members (methods, properties, and events) are removed if their removal does not impact compilation observably. If no InternalsVisibleTo attributes are present, the same applies to internal function members.
•However, all types, including private or nested ones, are retained in reference assemblies. All attributes, including internal ones, are preserved.
•All virtual methods are kept. Explicit interface implementations are kept. Explicitly implemented properties and events are kept, as their accessors are virtual (and are therefore kept).
•All fields within a structure are retained.
The -refout and -refonly options are mutually exclusive.