13

I realized that I can't use ctrl + . shortcut to import other C# classes. This shortcut works just fine for other file types like typescript.

I have uninstalled and installed back again. I also installed old version of VS code too. But nothing worked.

enter image description here As I shown above, there is no import feature shows up when I do ctrl + .. Those are only the choices I was given. It's fine using without it but it's also annoying to import those files manually typed.

Cœur
  • 37,241
  • 25
  • 195
  • 267
GoGo
  • 2,727
  • 5
  • 22
  • 34

4 Answers4

28

The C# language features in VS Code are provided by a service called OmniSharp .

A couple of things you could try:

A) Restart OmniSharp

  1. Open the Command Palette (Ctrl + Shift + P)
  2. Type Omnisharp: Restart OmniSharp

    Command Palette > OmniSharp

B) View OmniSharp Logs

  1. Open Output Panel (Ctrl + ')
  2. Select OmniSharp Log from the dropdown)

    Output Panel > OmniSharp

C) Enable OmniSharp Logging

  1. Enabling C# debugger logging in Omnisharp

    "configurations": [
        {
            "...": "...",
            "logging": {
                "engineLogging": true
            }
        },
        { "...": "..." }
    ]
    
KyleMit
  • 30,350
  • 66
  • 462
  • 664
Stewart_R
  • 13,764
  • 11
  • 60
  • 106
  • Update: Here is `[fail]` message: `OmniSharp.Roslyn.CSharp.Services.Refactoring.V2.GetCodeActionsService Error registering code fixes for Microsoft.CodeAnalysis.CSharp.AddImport.CSharpAddImportCodeFixProvider` – GoGo Jan 30 '18 at 18:33
  • Got it working. The issue was my dotnet framework. I repaired my dotnet framework it started to work. `OmniSharp` error log led me there. – GoGo Jan 30 '18 at 18:59
2

I faced into a similar situation. In My case I had several .csproj files and one solution file. Make sure to add all .csproj file to .sln file.

dotnet sln add <.csproj file path>.

Make sure to restart omnisharp. In Mac -> (command + shift + p => select Omnisharp: Restart OmniSharp)

Jeevan
  • 518
  • 3
  • 8
1

Something that solved it in my case was, in Unity, to set the Edit -> Project Settings -> Player -> Other Settings -> Api Compatibility Level to .NET 4.x.

Probably not appropriate in some cases, and indiciative of another issue in my Omnisharp/ VS Code setup, but just in case it helps someone.

Philipp Lenssen
  • 8,818
  • 13
  • 56
  • 77
0

Have you tried clearing out Visual Studio cache by any chance? Make sure Visual Studio is closed before attempting this. It is typically located at: C:\Users\Your User Name\AppData\Local\Microsoft\VisualStudio\

This cache could easily get corrupted and usually doesn't get cleared between re-installations.

Also, if previous doesn't work, try clearing temp directory as well - C:\Users\Your user name\AppData\Local\Temp

Few more additions to check

  • Check if Keyboard layout settings in Tools-> Options -> Environment -> Keyboard is set to Visual C# 2005

  • Check for IntelliSense settings in Tools -> Options -> Text Editor -> C# -> Formatting, for anything that may have caused the defaults to change

Hope this helps!

Diablo
  • 169
  • 1
  • 8
  • I don't see any files to clear. I have `14.0, 15.0, 15.0_.., Packages, SettingsLogs, vshub`. Seems like these are Visual Studio folders not Visual Studio Code. – GoGo Jan 30 '18 at 18:25
  • Great that you figured out the issue!!! Just a FYI - these folders contain any setting related to the Visual Studio version you are using. It is very unlikely that there's no files at all here because the moment you open VS the first time, it would create a bunch of files here (that includes user preferences and setting). Good luck! – Diablo Jan 30 '18 at 19:08
  • 2
    The question relates to visual studio **code** - completely different from visual studio hence the missing files – Stewart_R Oct 03 '19 at 06:50