Visual Studio Code is detecting wrongly that I don't need a using C# / .NET Core

217 Views Asked by At

I'm using Visual Studio Code with C# Microsoft Extension. I also have the following setting to format and fix all issues each time I save a file:

"editor.codeActionsOnSave": {
    "source.fixAll": true,
    "source.organizeImports": true,
    "source.sortMembers": true
},

I'm working on a .NET Core project and I don't know why Visual Studio Code is detecting that some usings are not being used which is wrong. Because of that, each time I save a file, the usings are being removed. I'm positive about this because the compiler let me know that I'm missing usings each time I run dotnet build.

Does anyone know how to solve this issue without changing the codeActionsOnSave setting that I have in place?

Software versions:

1

There are 1 best solutions below

0
Ricardo Rocha On

I found a workaround that fixed my issues but compromises having "source.fixAll" on c# files:

  1. Open your settings.json file. click here to learn how to do it
  2. Add the following code:

{
  "[csharp]": {
    "editor.codeActionsOnSave": {
      "source.organizeImports": true,
      "source.fixAll": true,
      "source.sortMembers": true
    }
  }
}