You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/core/project-sdk/msbuild-props.md
+5-3Lines changed: 5 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -835,16 +835,18 @@ The `DisableImplicitNamespaceImports` property can be used to disable [implicit
835
835
836
836
### ImplicitUsings
837
837
838
-
The `ImplicitUsings` property can be used to enable and disable implicit `global using` directives in C# projects that target .NET 6 or a later version and C# 10.0 or a later version. When the feature is enabled, the .NET SDK adds `global using` directives for a set of default namespaces based on the type of project SDK. Set this property to `true` or `enable` to enable implicit `global using` directives. To disable implicit `global using` directives, remove the property or set it to `false` .
838
+
The `ImplicitUsings` property can be used to enable and disable implicit `global using` directives in C# projects that target .NET 6 or a later version and C# 10.0 or a later version. When the feature is enabled, the .NET SDK adds `global using` directives for a set of default namespaces based on the type of project SDK. Set this property to `true` or `enable` to enable implicit `global using` directives. To disable implicit `global using` directives, remove the property or set it to `false`or `disable`.
839
839
840
840
```xml
841
841
<PropertyGroup>
842
-
<ImplicitUsings>true</ImplicitUsings>
842
+
<ImplicitUsings>enable</ImplicitUsings>
843
843
</PropertyGroup>
844
844
```
845
845
846
846
> [!NOTE]
847
-
> For new C# projects that target .NET 6 or later, `ImplicitUsings` is set to `true` by default.
847
+
> The templates for new C# projects that target .NET 6 or later have `ImplicitUsings` set to `enable` by default.
848
+
849
+
To define an explicit `global using` directive, add a [Using](#using) item.
Copy file name to clipboardExpand all lines: docs/core/tutorials/top-level-templates.md
+24-6Lines changed: 24 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -42,20 +42,38 @@ The features that make the new program simpler are *top-level statements*, *glob
42
42
43
43
[Top-level statements](../../csharp/fundamentals/program-structure/top-level-statements.md) means the compiler generates the namespace, class, and method elements for your main program. You can look at the code for the new application and imagine that it contains the statements inside the `Main` method generated by earlier templates. You can add more statements to the program, just like you can add more statements to your `Main` method in the traditional style. You can even add functions. They're created as local functions nested inside the generated `Main` method.
44
44
45
-
*Global `using` directives* means the compiler automatically imports a set of [`using` directives](../../csharp/language-reference/keywords/using-directive.md) based on the project type. For console applications, the following directives are implicitly included in every source file in the application:
45
+
Both top-level statements and [implicit `using` directives](#implicit-using-directives) simplify the code that makes up your application. To follow an existing tutorial, add any new statements to the *Program.cs* file generated by the template. You can imagine that the statements you write are between the open and closing braces in the `Main` method in the instructions of the tutorial.
46
+
47
+
If you'd prefer to use the older format, you can copy the code from the second example in this article, and continue the tutorial as before.
48
+
49
+
You can learn more about top-level statements in the tutorial exploration on [top-level statements](../../csharp/whats-new/tutorials/top-level-statements.md).
50
+
51
+
## Implicit `using` directives
52
+
53
+
*Implicit `using` directives* mean the compiler automatically adds a set of [`using` directives](../../csharp/language-reference/keywords/using-directive.md) based on the project type. For console applications, the following directives are implicitly included in the application:
46
54
47
55
-`using System;`
56
+
-`using System.IO;`
48
57
-`using System.Collections.Generic;`
49
58
-`using System.Linq;`
50
59
-`using System.Net.Http;`
51
-
-`using System.Net.Http.Json;`
60
+
-`using System.Threading;`
61
+
-`using System.Threading.Tasks;`
52
62
53
63
Other application types include more namespaces that are common for those application types.
54
64
55
-
These two features simplify the code that makes up your application. To follow an existing tutorial, add any new statements to the *Program.cs* file generated by the template. You can imagine that the statements you write are between the open and closing braces in the `Main` method in the instructions of the tutorial.
65
+
### Disable implicit `using` statements
56
66
57
-
If you'd prefer to use the older format, you can copy the code from the second example in this article, and continue the tutorial as before.
67
+
If you want to remove this behavior and manually control all namespaces in your project, add [`<ImplicitUsings>disable</ImplicitUsings>`](../project-sdk/msbuild-props.md#implicitusings) in the project file.
68
+
69
+
## Global `using` directives
58
70
59
-
You can learn more about top-level statements in the tutorial exploration on [top level statements](../../csharp/whats-new/tutorials/top-level-statements.md).
71
+
A *global `using` directive* imports a namespace for your whole application instead of a single file. These global directives can be added either by adding a [`<Using>`](../project-sdk/msbuild-props.md#using) item to the project file, or by adding the `global using` directive to a code file.
60
72
61
-
If you want to opt-out of that behavior and manually control all namespaces in your project, add [`<DisableImplicitNamespaceImports>true</DisableImplicitNamespaceImports>`](../project-sdk/msbuild-props.md#disableimplicitnamespaceimports) in the project file.
73
+
You can also add a [`<Using>`](../project-sdk/msbuild-props.md#using) item in your project file to remove a specific [implicit `using` directive](#implicit-using-directives). For example, if the implicit usings feature is turned on with [`<ImplicitUsings>enable</ImplicitUsings>`](../project-sdk/msbuild-props.md#implicitusings), adding the following `<Using>` item removes the `System.Net.Http` namespace from those that are implicitly imported:
0 commit comments