admin管理员组

文章数量:1315357

Our team is developing a WPF project in Visual Studio 2022, it utilizes Entity Framework Core and Microsoft Dependency Injection. Whenever somebody implements a new class accessing our database context, they will have the issue that ToListAsync(), AnyAsync(), FirstOrDefaultAsync() and so on aren't known, because those are extension methods in the namespace Microsoft.EntityFrameworkCore. When we use the shortcut CTRL+., we would expect to be able to add the missing using entry.

using Microsoft.EntityFrameworkCore;

But in our project we also use DevExpress and since it comes first alphabetically, this using sneaks in every now and then.

using DevExpress.Xpo;

We don't use DevExpress.Xpo at all, it's just included inside of DevExpress.Wpf.Core.Extensions which on the other hand is included inside of DevExpress.Wpf which we use. Every now and then, it still sneaks in when we try to add missing usings for our database operations. It's not always just us fetting to select the second entry instead of just hitting Enter, sometimes IntelliSense takes some time loading more suggestions and resets to the topmost item last second when it's done.

The same keeps happening when we try to resolve services from our IServiceProvider. We would need Microsoft.Extensions.DependencyInjection for GetService() or GetRequiredService() which also exists inside of DevExpress.Mvvm.POCO. This namespace is implemented inside of DevExpress.Mvvm which we use.

Instead of

using Microsoft.Extensions.DependencyInjection;

this one sneaks in.

using DevExpress.Mvvm.POCO;

Both namespaces lead to strange runtime exceptions when testing and can become very time consuming when not instantly identified. I am now looking for a way to either remove those from the suggestion list, even when available inside of the project or at least prioritize the suggested namespaces.

Is there some option or plugin that could help me with that?

Our team is developing a WPF project in Visual Studio 2022, it utilizes Entity Framework Core and Microsoft Dependency Injection. Whenever somebody implements a new class accessing our database context, they will have the issue that ToListAsync(), AnyAsync(), FirstOrDefaultAsync() and so on aren't known, because those are extension methods in the namespace Microsoft.EntityFrameworkCore. When we use the shortcut CTRL+., we would expect to be able to add the missing using entry.

using Microsoft.EntityFrameworkCore;

But in our project we also use DevExpress and since it comes first alphabetically, this using sneaks in every now and then.

using DevExpress.Xpo;

We don't use DevExpress.Xpo at all, it's just included inside of DevExpress.Wpf.Core.Extensions which on the other hand is included inside of DevExpress.Wpf which we use. Every now and then, it still sneaks in when we try to add missing usings for our database operations. It's not always just us fetting to select the second entry instead of just hitting Enter, sometimes IntelliSense takes some time loading more suggestions and resets to the topmost item last second when it's done.

The same keeps happening when we try to resolve services from our IServiceProvider. We would need Microsoft.Extensions.DependencyInjection for GetService() or GetRequiredService() which also exists inside of DevExpress.Mvvm.POCO. This namespace is implemented inside of DevExpress.Mvvm which we use.

Instead of

using Microsoft.Extensions.DependencyInjection;

this one sneaks in.

using DevExpress.Mvvm.POCO;

Both namespaces lead to strange runtime exceptions when testing and can become very time consuming when not instantly identified. I am now looking for a way to either remove those from the suggestion list, even when available inside of the project or at least prioritize the suggested namespaces.

Is there some option or plugin that could help me with that?

Share Improve this question edited Jan 31 at 8:24 Clemens 128k13 gold badges159 silver badges286 bronze badges asked Jan 30 at 9:36 E4estE4est 951 silver badge10 bronze badges 2
  • usually you can chose which of the suggested options you want to apply. So if a name was found in two different namespaces, you should be able to chose between them. – MakePeaceGreatAgain Commented Jan 30 at 9:40
  • 2 did you consider global usings? stackoverflow/questions/75170808/… – ASh Commented Jan 30 at 9:40
Add a comment  | 

2 Answers 2

Reset to default 1

You can configure IntelliSense to show or hide items from unimported namespaces.

Go to Tools > Options > Text Editor > C# > IntelliSense and look for the option Show items from unimported namespaces. Disabling this might help reduce the unwanted suggestions.

If you are using C# 10, you can import the correct namespace once and for all:

global using Microsoft.EntityFrameworkCore;
global using Microsoft.Extensions.DependencyInjection;

This will make the namespace available in entire project. If you have multiple projects, you'd have to repeat it once in each project.

本文标签: cVisual Studio Preventblacklist or reorder namespace suggestionsStack Overflow