-1

So i was building a web api in vs 2022 RC with the ASP.net Core Web Empty template with net 6.

and i noticed that in the program.cs it doesn't show Using system.io etc... It seems to compile and run so im interested in why it is doing this. is this a setting? is this new to the IDE? I cant find it on google maybe i don't know what to search for. Any ideas how to re enable the generating of Using in code it or what is causing it?

var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();

if (app.Environment.IsDevelopment())
{
    app.UseDeveloperExceptionPage();
}

app.MapGet("/", () => "Hello World!");

app.Run();

No using in code picture

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
kdekok
  • 1
  • 1
  • Ignore the file. it was to test to see if it also worked with system.io it seems to recognize it without adding Using system.io; – kdekok Nov 01 '21 at 12:23
  • There are now some [implicit global usings](https://dotnetcoretutorials.com/2021/08/31/implicit-using-statements-in-net-6/) in .NET 6./C# 10. – Uwe Keim Nov 01 '21 at 12:24
  • If you're used to writing .NET code before .NET 6, then it would be a good idea to [familiarize yourself with the new features](https://rubikscode.net/2021/08/30/net-6-top-6-new-features-in-the-upcoming-net-6-version/) so that you're not surprised and so you don't miss out on taking advantage of the new stuff. – mason Nov 01 '21 at 13:45

1 Answers1

1

See docs ("Implicit Namespaces"):

.NET 6 introduces implicit namespace support for C# projects. To reduce the amount of using directives boilerplate in .NET C# project templates, namespaces are implicitly included by utilizing the global using feature introduced in C# 10.

[...]

The default namespaces are included by adding global using directives to a generated file in the project's obj directory. The default namespaces are as follows:

SDK Default namespaces
Microsoft .NET Sdk System, System.Collections.Generic, System.IO, System.Linq, System.Net.Http, System.Threading, System.Threading.Tasks

Emphasis mine.

CherryDT
  • 25,571
  • 5
  • 49
  • 74