# -refonly (C# Compiler Options)

The -refonly option indicates that a reference assembly should be output instead of an implementation assembly, as the primary output. The -refonly parameter silently disables outputting PDBs, as reference assemblies cannot be executed. This option corresponds to the ProduceOnlyReferenceAssembly project property of MSBuild.

## Syntax

-refonly


## Remarks

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 so that PEVerify could run and pass (thus validating the completeness of the metadata).

Reference assemblies include an assembly-level ReferenceAssembly attribute. This attribute may be specified in source (then the compiler won't need to synthesize it). Because of this attribute, runtimes will refuse to load reference assemblies for execution (but they can still be loaded in reflection-only mode). Tools that reflect on assemblies need to ensure they load reference assemblies as reflection-only, otherwise they will receive a typeload error from the runtime.

• A reference assembly only has references for what it needs in the API surface. The real assembly may have additional references related to specific implementations. For instance, the reference assembly for class C { private void M() { dynamic d = 1; ... } } does not reference any types required for dynamic.
The -refonly and -refout options are mutually exclusive.