13

I am using Visual Studio Code to develop an ASP.NET 5 application on Mac. In order to use new classes (framework or third-party) in my .cs file, I need to

  1. Manually add a NuGet dependency in project.json and then
  2. Manually add a using statement to my .cs file.

It seems that there should be a better way to import new functionality that doesn't involve searching for the right NuGet and the correct namespace. Any suggestions?

Nikolai Samteladze
  • 7,699
  • 6
  • 44
  • 70

2 Answers2

12

Well, once I got my IntelliSense issues figured out (Visual Studio Code on Mac), I don't have to type using statements anymore. OmniSharp-based IntelliSense is smart enough to suggest (Cmd + . on Mac) adding them for me:

enter image description here

I still have to add a NuGet dependency manually, but I think this is the default behavior in the full Visual Studio too and you need ReSharper to get smarter than that.

enter image description here

Community
  • 1
  • 1
Nikolai Samteladze
  • 7,699
  • 6
  • 44
  • 70
  • Just fwiw, on Windows, I had autosuggest stop working until I **updated** OmniSharp. Thanks for the heads up. – ruffin Feb 16 '18 at 18:16
3

Unfortunately, as far as I know of, the short answer is no.

Visual Studio Code is meant to be a light weight editor, so does not have support for the kind of feature you are describing out of the box. The full Visual Studio on Windows does have support for that. When you type the name of a class/type you want to use, eg. JsonConvert, it will detect that the missing type is available on NuGet and offer you the ability to download the correct package and add the using statement. (In the screenshot I already have the NuGet package installed, so it only needs to add the using statement)

Roslyn Codefix

This feature is available in the Community edition of Visual Studio, which you can download for free from the visualstudio.com website. This does require you to run Windows, so I'm not sure if you consider this an option.

Now on the wishful thinking side: VS Code does support extensions these days and it has the power of the Roslyn engine, so theoretically someone could write an extension that will offer this functionality in the future. You could also try getting it added to the core editor, by opening an issue on GitHub: https://github.com/Microsoft/vscode/issues I'm afraid neither of these will really help you in the short term though.

ruffin
  • 16,507
  • 9
  • 88
  • 138
Christiaan Rakowski
  • 322
  • 2
  • 7
  • 15