Un-using #7303
Replies: 3 comments 1 reply
-
@wrexbe you might be interested in the Banned API Analyzers. It won't filter things out of completion, but it will give you an error if you use any of the types you specify. |
Beta Was this translation helpful? Give feedback.
-
I was recently been thinking about something like this. It would be nice if we could "ban" or "exclude" some namespaces, similarly to the global usings. exclude using System.Windows.Input; // ban whole namespace
exclude using System.Windows.Input.ICommand; // ban single class Or in csproj : <ItemGroup>
<Using Exclude="System.Windows.Input"/>
</ItemGroup> In my case i am writing apps with CQRS and we have the |
Beta Was this translation helpful? Give feedback.
-
If your compilation doesn't need to directly reference any of the types from Newtonsoft.Json, you can add this to your .csproj to remove Newtonsoft.Json.dll as a compiler reference, while keeping Newtonsoft.Json.dll in your build output since the library you're using needs it: <Target Name="RemoveCompileTimeReferences" AfterTargets="ResolvePackageAssets" BeforeTargets="ResolveLockFileReferences">
<ItemGroup>
<ResolvedCompileFileDefinitions Remove="@(ResolvedCompileFileDefinitions)" Condition="'%(NuGetPackageId)' == 'Newtonsoft.Json'" />
</ItemGroup>
</Target> |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
So my project currently has System.Text.Json, and Newtonsoft which is coming indirectly from a Nuget I am using. The IDE is being annoying, by suggesting Newtonsoft all the time. This is probably more of an IDE thing, but in the project, or in C# I want the ability to globally say not to use anything from a namespace, the opposite of a using. This would improve "Add missing references", and also add a guard against someone using a similarly named type by accident.
Beta Was this translation helpful? Give feedback.
All reactions