Show/Hide Toolbars

XSharp

The -refonly option indicates that the primary output should be a reference assembly rather than an implementation assembly. The -refonly parameter silently disables outputting PDBs, as reference assemblies cannot be executed.

Syntax

-refonly

Metadata-only assemblies replace method bodies with a single throw null body but include all members except anonymous types. The use of throw null bodies (rather than having no bodies) ensures that PEVerify can 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 does not need to synthesize it. Due to this attribute, runtimes refuse to execute reference assemblies, though they can still be loaded in reflection-only mode. Tools reflecting on assemblies must load reference assemblies in reflection-only; otherwise, the runtime will throw a type-load error.

 

Reference assemblies also remove metadata (private members) from metadata-only assemblies, with the following distinctions:

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. (This aspect may be subject to refinement in future versions post-C#-7.1).

 

The -refonly and -refout options are mutually exclusive.