Skip to content

Commit d1b856c

Browse files
CopilotBillWagner
andcommitted
Add build-only diagnostic note to all relevant CS error documentation
Co-authored-by: BillWagner <493969+BillWagner@users.noreply.github.com>
1 parent 38c5e75 commit d1b856c

File tree

10 files changed

+19
-2
lines changed

10 files changed

+19
-2
lines changed

docs/csharp/misc/cs0017.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ ms.assetid: 5e2a3eb3-6f6e-485d-8293-ceabea4d6905
1313
Program 'output file name' has more than one entry point defined. Compile with /main to specify the type that contains the entry point.
1414

1515
A program can only have one [Main](../fundamentals/program-structure/main-command-line.md) method.
16+
17+
[!INCLUDE[csharp-build-only-diagnostic-note](~/includes/csharp-build-only-diagnostic-note.md)]
1618

1719
To resolve this error, you can either delete all Main methods in your code, except one, or you can use the [**StartupObject**](../language-reference/compiler-options/advanced.md#mainentrypoint-or-startupobject) compiler option to specify which Main method you want to use.
1820

docs/csharp/misc/cs0028.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ ms.assetid: 47df919f-01fa-45ae-a4b7-912445e679e2
1313
'function declaration' has the wrong signature to be an entry point
1414

1515
The method declaration for `Main` was invalid: it was declared with an invalid signature. `Main` must be declared as static and it must return either [int](../language-reference/builtin-types/integral-numeric-types.md) or [void](../language-reference/builtin-types/void.md). For more information, see [Main() and Command-Line Arguments](../fundamentals/program-structure/main-command-line.md).
16+
17+
[!INCLUDE[csharp-build-only-diagnostic-note](~/includes/csharp-build-only-diagnostic-note.md)]
1618

1719
The following sample generates CS0028:
1820

docs/csharp/misc/cs0067.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ ms.assetid: df75220b-0b93-45ec-8655-98d9333b0bb7
1313
The event 'event' is never used
1414

1515
An [event](../language-reference/keywords/event.md) was declared but never used in the class in which it was declared.
16+
17+
[!INCLUDE[csharp-build-only-diagnostic-note](~/includes/csharp-build-only-diagnostic-note.md)]
1618

1719
The following sample generates CS0067:
1820

docs/csharp/misc/cs0169.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ The private field 'class member' is never used
1414

1515
A private variable was declared but never referenced. A common way to generate this warning is when you declare a private member of a class and do not use it.
1616

17-
> [!NOTE]
18-
> This warning is only reported during explicit **Build** or **Rebuild** operations. It does not appear during typing in the IDE as part of IntelliSense diagnostics. This means that if you fix the warning by using the field or removing it, the warning might persist in the error list until you build or rebuild the project again.
17+
[!INCLUDE[csharp-build-only-diagnostic-note](~/includes/csharp-build-only-diagnostic-note.md)]
1918

2019
The following sample generates CS0169:
2120

docs/csharp/misc/cs0279.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ ms.assetid: 5e5faa8f-3d5b-4999-aa62-ff7f131a3e04
1313
'type name' does not implement the 'pattern name' pattern. 'method name' is either static or not public.
1414

1515
There are several statements in C# that rely on defined patterns, such as `foreach` and `using`. For example, `foreach` relies on the collection class implementing the enumerable pattern. This error occurs when the compiler is unable to make the match due to a method being declared `static` or not `public`. Methods in patterns are required to be instances of classes, and to be public.
16+
17+
[!INCLUDE[csharp-build-only-diagnostic-note](~/includes/csharp-build-only-diagnostic-note.md)]
1618

1719
## Example
1820

docs/csharp/misc/cs0402.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ ms.assetid: 5a252c95-18c7-4569-bae0-e1f7b582cf6a
1313
'identifier' : an entry point cannot be generic or in a generic type
1414

1515
The entry point was found in a generic type. To remove this warning, implement Main in a non-generic class or struct.
16+
17+
[!INCLUDE[csharp-build-only-diagnostic-note](~/includes/csharp-build-only-diagnostic-note.md)]
1618

1719
```csharp
1820
// CS0402.cs

docs/csharp/misc/cs0414.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ ms.assetid: 6a0a80be-799b-4d9c-a7e0-6b91e9ce7be0
1212

1313
The private field 'field' is assigned but its value is never used
1414

15+
[!INCLUDE[csharp-build-only-diagnostic-note](~/includes/csharp-build-only-diagnostic-note.md)]
16+
1517
This warning can occur in several scenarios in which the compiler can verify that a variable is never referenced:
1618

1719
- A private field is assigned a constant value but is never subsequently read. The unnecessary assignment could effect performance. Consider removing the field.

docs/csharp/misc/cs0649.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ ms.assetid: 37137b18-12ed-4a0f-92e6-ee5fb0532ef3
1313
Field 'field' is never assigned to, and will always have its default value 'value'
1414

1515
The compiler detected an uninitialized private or internal field declaration that is never assigned a value.
16+
17+
[!INCLUDE[csharp-build-only-diagnostic-note](~/includes/csharp-build-only-diagnostic-note.md)]
1618

1719
The following sample generates CS0649:
1820

docs/csharp/misc/cs5001.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Program does not contain a static 'Main' method suitable for an entry point
1414

1515
This error occurs when no static `Main` method with a correct signature is found in the code that produces an executable file. It also occurs if the entry point function, `Main`, is defined with the wrong case, such as lower-case `main`. For information about the rules that apply to the `Main` method, see [Main() and Command-Line Arguments](../fundamentals/program-structure/main-command-line.md).
1616

17+
[!INCLUDE[csharp-build-only-diagnostic-note](~/includes/csharp-build-only-diagnostic-note.md)]
18+
1719
If the `Main` method has an `async` modifier, make sure that the [selected C# language version](../language-reference/configure-language-version.md) is 7.1 or higher and to use `Task` or `Task<int>` as the return type.
1820

1921
The `Main` method is only required when compiling an executable file, that is, when the **exe** or **winexe** element of the [**TargetType**](../language-reference/compiler-options/output.md#targettype) compiler option is specified. The following Visual Studio project types specify one of these options by default:
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
> [!NOTE]
2+
> This warning is only reported during explicit **Build** or **Rebuild** operations. It does not appear during typing in the IDE as part of IntelliSense diagnostics. This means that if you fix the warning by using the field or removing it, the warning might persist in the error list until you build or rebuild the project again.

0 commit comments

Comments
 (0)