Skip to content

Commit 2b917e0

Browse files
CopilotBillWagnergewarren
authored
Update CS0518 documentation with actionable guidance for modern .NET projects (#47685)
* Initial plan * Update CS0518 documentation with modern .NET project guidance Co-authored-by: BillWagner <[email protected]> * Update docs/csharp/language-reference/compiler-messages/cs0518.md --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: BillWagner <[email protected]> Co-authored-by: Genevieve Warren <[email protected]>
1 parent 190605b commit 2b917e0

File tree

1 file changed

+26
-9
lines changed
  • docs/csharp/language-reference/compiler-messages

1 file changed

+26
-9
lines changed

docs/csharp/language-reference/compiler-messages/cs0518.md

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@ ms.assetid: b0b61cbb-c9a7-48c9-9e60-7cdd5ecb3e6c
1111
# Compiler Error CS0518
1212

1313
Predefined type 'type' is not defined or imported
14-
15-
The main cause for this problem is that the project is not importing mscorlib.dll, which defines the entire System namespace. This can be caused by one of the following:
14+
15+
> [!NOTE]
16+
> The resolution for this error depends on whether you're using a modern SDK-style project (`.csproj` files that start with `<Project Sdk="Microsoft.NET.Sdk">`) or legacy project formats. SDK-style projects manage runtime references automatically through the `<TargetFramework>` property.
17+
18+
The main cause for this problem is that the project cannot access the predefined types from the .NET runtime library. In modern SDK-style projects, this is typically due to an incorrect or missing `<TargetFramework>` specification. In legacy projects, this issue is caused by not importing mscorlib.dll, which defines the entire <xref:System> namespace. This can be caused by one of the following:
1619

1720
[!INCLUDE[csharp-build-only-diagnostic-note](~/includes/csharp-build-only-diagnostic-note.md)]
1821

@@ -25,13 +28,27 @@ The main cause for this problem is that the project is not importing mscorlib.dl
2528
- Residual components from an earlier installation that are incompatible with the latest installation remain.
2629

2730
To resolve this problem, take one of the following actions:
28-
31+
2932
- Do not specify the /nostdlib option from the command line compiler.
30-
31-
- Make sure that the project refers to the correct mscorlib.dll.
32-
33-
- Reinstall the .NET Framework common language runtime (if the previous solutions do not solve the problem).
3433

35-
Optionally
34+
- For modern SDK-style projects, ensure the project targets the correct .NET runtime. In your `.csproj` file, verify the `<TargetFramework>` property specifies the intended runtime:
35+
36+
```xml
37+
<PropertyGroup>
38+
<TargetFramework>net8.0</TargetFramework>
39+
</PropertyGroup>
40+
```
41+
42+
For multi-targeting projects, use `<TargetFrameworks>` (plural):
43+
44+
```xml
45+
<PropertyGroup>
46+
<TargetFrameworks>net8.0;net48</TargetFrameworks>
47+
</PropertyGroup>
48+
```
49+
50+
- For legacy project formats, make sure that the project refers to the correct mscorlib.dll.
51+
52+
- Reinstall the .NET Framework common language runtime (if the previous solutions do not solve the problem).
3653

37-
- Reload the project in the Visual Studio.
54+
- Reload the project in Visual Studio.

0 commit comments

Comments
 (0)