Skip to content

Commit 8e8d015

Browse files
authored
Document new reference assembly compiler options (dotnet#2857)
* Document new reference assembly compiler options Generate reference assemblies along with primary assembly, or instead of primary assembly. * updates per initial feedback * respond to feedback. * respond to feedback
1 parent e0271ba commit 8e8d015

File tree

5 files changed

+106
-0
lines changed

5 files changed

+106
-0
lines changed

docs/csharp/language-reference/compiler-options/listed-alphabetically.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ The following compiler options are sorted alphabetically. For a categorical list
7979
|[/preferreduilang](../../../csharp/language-reference/compiler-options/preferreduilang-compiler-option.md)|Specifies the language to be used for compiler output.|
8080
|[/recurse](../../../csharp/language-reference/compiler-options/recurse-compiler-option.md)|Includes all files in the current directory and subdirectories according to the wildcard specifications.|
8181
|[/reference](../../../csharp/language-reference/compiler-options/reference-compiler-option.md)|References metadata from the specified assembly files.|
82+
|[/refout](refout-compiler-option.md)|Generate a reference assembly in addition to the primary assembly.|
83+
|[/refonly](refonly-compiler-option.md)|Generate a reference assembly instead of a primary assembly.|
8284
|[/resource](../../../csharp/language-reference/compiler-options/resource-compiler-option.md)|Embeds the specified resource.|
8385
|/ruleset:\<file>|Specify a ruleset file that disables specific diagnostics.|
8486
|[/subsystemversion](../../../csharp/language-reference/compiler-options/subsystemversion-compiler-option.md)|Specifies the minimum version of the subsystem that the executable file can use.|

docs/csharp/language-reference/compiler-options/listed-by-category.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ The following compiler options are sorted by category. For an alphabetical list,
4949
|[/pdb](../../../csharp/language-reference/compiler-options/pdb-compiler-option.md)|Specifies the file name and location of the .pdb file.|
5050
|[/platform](../../../csharp/language-reference/compiler-options/platform-compiler-option.md)|Specify the output platform.|
5151
|[/preferreduilang](../../../csharp/language-reference/compiler-options/preferreduilang-compiler-option.md)|Specify a language for compiler output.|
52+
|[/refout](refout-compiler-option.md)|Generate a reference assembly in addition to the primary assembly.|
53+
|[/refonly](refonly-compiler-option.md)|Generate a reference assembly instead of a primary assembly.|
5254
|[/target](../../../csharp/language-reference/compiler-options/target-compiler-option.md)|Specifies the format of the output file using one of five options: [/target:appcontainerexe](../../../csharp/language-reference/compiler-options/target-appcontainerexe-compiler-option.md), [/target:exe](../../../csharp/language-reference/compiler-options/target-exe-compiler-option.md), [/target:library](../../../csharp/language-reference/compiler-options/target-library-compiler-option.md), [/target:module](../../../csharp/language-reference/compiler-options/target-module-compiler-option.md), [/target:winexe](../../../csharp/language-reference/compiler-options/target-winexe-compiler-option.md), or [/target:winmdobj](../../../csharp/language-reference/compiler-options/target-winmdobj-compiler-option.md).|
5355
|/modulename:\<string>|Specify the name of the source module|
5456

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
title: "-refonly (C# Compiler Options)"
3+
ms.date: "2017-07-08"
4+
ms.prod: .net
5+
ms.technology:
6+
- "devlang-csharp"
7+
ms.topic: "article"
8+
f1_keywords:
9+
- "/refonly"
10+
dev_langs:
11+
- "CSharp"
12+
helpviewer_keywords:
13+
- "/refonly compiler option [C#]"
14+
- "-refonly compiler option [C#]"
15+
author: "BillWagner"
16+
ms.author: "wiwagn"
17+
---
18+
19+
# /refonly (C# Compiler Options)
20+
21+
The **/refonly** 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.
22+
23+
## Syntax
24+
25+
```console
26+
/refonly
27+
```
28+
29+
## Remarks
30+
31+
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).
32+
33+
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.
34+
35+
Reference assemblies further remove metadata (private members) from metadata-only assemblies:
36+
37+
- 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`.
38+
- Private function-members (methods, properties, and events) are removed. If there are no `InternalsVisibleTo` attributes, do the same for internal function-members.
39+
- But all types (including private or nested types) are kept in reference assemblies. All attributes are kept (even internal ones).
40+
- 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).
41+
- All fields of a struct are kept. (This is a candidate for post-C#-7.1 refinement)
42+
43+
The `/refonly` and [`/refout`](refout-compiler-option.md) options are mutually exclusive.
44+
45+
## See also
46+
[C# Compiler Options](../../../csharp/language-reference/compiler-options/index.md)
47+
[Managing Project and Solution Properties](/visualstudio/ide/managing-project-and-solution-properties)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
---
2+
title: "-refout (C# Compiler Options)"
3+
ms.date: "2017-08-08"
4+
ms.prod: .net
5+
ms.technology:
6+
- "devlang-csharp"
7+
ms.topic: "article"
8+
f1_keywords:
9+
- "/refout"
10+
dev_langs:
11+
- "CSharp"
12+
helpviewer_keywords:
13+
- "refout compiler option [C#]"
14+
- "/refout compiler option [C#]"
15+
- "-refout compiler option [C#]"
16+
author: "BillWagner"
17+
ms.author: "wiwagn"
18+
---
19+
20+
# /refout (C# Compiler Options)
21+
22+
The **/refout** option specifies a file path where the reference assembly should be output. This translates to `metadataPeStream` in the Emit API.
23+
24+
## Syntax
25+
26+
```console
27+
/refout:filepath
28+
```
29+
30+
## Arguments
31+
32+
`filepath`
33+
The filepath for the reference assembly. It 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.
34+
35+
## Remarks
36+
37+
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).
38+
39+
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.
40+
41+
Reference assemblies further remove metadata (private members) from metadata-only assemblies:
42+
43+
- 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`.
44+
- Private function-members (methods, properties, and events) are removed. If there are no `InternalsVisibleTo` attributes, do the same for internal function-members.
45+
- But all types (including private or nested types) are kept in reference assemblies. All attributes are kept (even internal ones).
46+
- 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).
47+
- All fields of a struct are kept. (This is a candidate for post-C#-7.1 refinement)
48+
49+
The `/refout` and [`/refonly`](refonly-compiler-option.md) options are mutually exclusive.
50+
51+
## See Also
52+
[C# Compiler Options](../../../csharp/language-reference/compiler-options/index.md)
53+
[Managing Project and Solution Properties](/visualstudio/ide/managing-project-and-solution-properties)

docs/csharp/language-reference/compiler-options/toc.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
### [-preferreduilang (C# Compiler Options)](preferreduilang-compiler-option.md)
4141
### [-recurse (C# Compiler Options)](recurse-compiler-option.md)
4242
### [-reference (C# Compiler Options)](reference-compiler-option.md)
43+
### [-refout (C# Compiler Options)](refout-compiler-option.md)
44+
### [-refonly (C# Compiler Options)](refonlye-compiler-option.md)
4345
### [-resource (C# Compiler Options)](resource-compiler-option.md)
4446
### [-subsystemversion (C# Compiler Options)](subsystemversion-compiler-option.md)
4547
### [-target (C# Compiler Options)](target-compiler-option.md)

0 commit comments

Comments
 (0)