-
Notifications
You must be signed in to change notification settings - Fork 10k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add default global usings to Microsoft.NET.Sdk.Web #32451
Comments
Also |
Those shouldn't be in the ASP.NET one. |
Do these play well if a file already includes these usings? |
I think it's interesting to discuss whether we want this in each project on on by default. Assuming we can stop the warning, I think we'd want a subset of namespaces in there by default. |
Are we attempting to optimize for the top-level statements file or all files in the project? Today I feel the most friction is the amount of namespaces needed just to bootstrap a basic app in its We also need to consider how this impacts existing apps that are simply used with the new SDK or just updated to target |
I would like to optimize for all files in a common ASP.NET Core project. I don't think there's a way to limit it to certain files. |
Triage: We should consider having an msbuild property you can put in your csproj to disable the default usings. Or opt-in. |
In the meeting we also discussed the idea of an extensibility model. There would be a mechanism in the SDK, likely a well known item group, that specifies additional global usings which will be added by the SDK to the project's obj directory. This way, additional packages, such as EF can opt into adding global usings to a project directory when the package is referenced by including a props/target file. |
I've added a POC for this at dotnet/sdk#18459. To see how this looks in a Minimal API web app, checkout https://github.com/JunTaoLuo/GlobalUsings. One of the annoying things is that the global using now conflicts with other generated cs files and create these warnings:
I'm not sure the best way to get rid of these warnings. I'm not a fan of ignoring all CS0105 warnings. |
It's going to be fixed by the compiler. |
Also, I'm a little concerned with the serviceability of this feature. After we ship the first set of global usings, any addition or removal of using statements will be breaking right? |
Removal is adding isn't |
Adding could introduce type conflicts no? |
Yes that is a good point, though there's guidance on how to avoid that generally. This could make the problem worse. |
As discussed today in sync, any changes in the future should be behind a TFM version check so that simply getting a new SDK would not introduce issues. New platform (TFM) versions for apps typically involve changes and caveats beyond the TFM change itself which is why there are migration docs for each version change and a change to default global usings would be one such change that's called out, with mitigations detailed such as disabling the feature via an MSBuild property, etc. |
Current list of usings: global using global::System;
global using global::System.Collections.Generic;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Net.Http.Json;
global using global::System.Threading.Tasks;
global using global::Microsoft.AspNetCore.Builder;
global using global::Microsoft.AspNetCore.Hosting;
global using global::Microsoft.AspNetCore.Http;
global using global::Microsoft.AspNetCore.Mvc;
global using global::Microsoft.AspNetCore.Routing;
global using global::Microsoft.Extensions.Configuration;
global using global::Microsoft.Extensions.DependencyInjection;
global using global::Microsoft.Extensions.Hosting;
global using global::Microsoft.Extensions.Logging; |
I suggest making this set an |
For API review: Current list of global usings: //Sdk.Web
global using global::System;
global using global::System.Collections.Generic;
global using global::System.Linq;
global using global::System.Net.Http;
global using global::System.Net.Http.Json;
global using global::Microsoft.AspNetCore.Builder;
global using global::Microsoft.AspNetCore.Hosting;
global using global::Microsoft.AspNetCore.Http;
global using global::Microsoft.AspNetCore.Routing;
global using global::Microsoft.Extensions.Configuration;
global using global::Microsoft.Extensions.DependencyInjection;
global using global::Microsoft.Extensions.Hosting;
global using global::Microsoft.Extensions.Logging; //Sdk.Worker
global using global::Microsoft.Extensions.Configuration;
global using global::Microsoft.Extensions.DependencyInjection;
global using global::Microsoft.Extensions.Hosting;
global using global::Microsoft.Extensions.Logging; These usings will be generated by the .NET SDK in the obj folder by default for C# projects > net6.0. This feature can be disabled completely via |
This is one of the bullet points from #30580. A long list of mostly the same
using
statements at the top of every ASP.NET Core is intimidating and ultimately unhelpful noise for the most point.We should consider a set of name spaces that will be imported by default into all cs file in
net6.0
projects targetingMicrosoft.NET.Sdk.Web
.Here's a strawman proposal for the possible default namespaces to use:
[Edit: updated list as of 6/23]
It's kinda crazy seeing .cs files without usings but I like it a lot.
We of course do need to be careful not to overdo this and introduce a bunch of conflicts or make intellisense too confusing. It's possible the strawman proposal is already a bit much, but I need to play with it more to get a good feeling for how convenient and/or annoying it is.
The text was updated successfully, but these errors were encountered: