Scott Hanselman

Visual Studio 2017 can automatically recommend NuGet packages for unknown types

March 24, '17 Comments [9] Posted in VS2017
Sponsored By

There's a great feature in Visual Studio 2015.3 and Visual Studio 2017 that is turned off by default. It does use about ~10 megs of memory but it makes me so happy that I turn it on.

It's under C# | Advanced in Tools Options. Or you can just type "Advanced" in the Quick Launch Bar (via Ctrl+Q if you like) to jump there.

I turn on "Suggest usings for types in NuGet packages" and "Suggest usings for types in reference assemblies."

I turn on "Suggest usings for types in NuGet packages" and "Suggest usings for types in reference assemblies."

For example, if I am typing some code and start referencing a Type that isn't in my project but could be...you know how sometimes you just need a using statement to bring in a namespace? In this Web App, I already have Json.NET so it recommends a using statement to bring it into scope.

Can't find JSON

But in this Console App, I have no packages beyond the defaults. When I start using a type like JObject from a popular NuGet, Visual Studio can offer to install Json.NET for me!

Find and install latest version

Or another example:

XmlDocument

And then I can immediately continue typing with intellisense. If I know what I'm doing, I can bring in something like this without ever using the mouse or leaving the line.

JObject is now usable

Good stuff! 


Sponsor: Check out JetBrains Rider: a new cross-platform .NET IDE. Edit, refactor, test, build and debug ASP.NET, .NET Framework, .NET Core, or Unity applications. Learn more and get access to early builds!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb
Friday, 24 March 2017 11:20:36 UTC
This is one of my favorites in VS2017. But I've been enjoying 'move type to matching file' the most and 'go to all' almost as much.
Friday, 24 March 2017 12:56:54 UTC
it's really helpful in .xml.
Friday, 24 March 2017 20:48:43 UTC
This is great; time I installed VS2017. Judging from this and Daniel Crabtree's comment, it looks like vanilla VS is catching up with Resharper which is good because it means JetBrains will keep adding more cool stuff (I hope, having just renewed my license).
Saturday, 25 March 2017 19:09:47 UTC
Doesn't VS2015 do the same?
Monday, 27 March 2017 11:16:12 UTC
Also under 'Basic | Advanced' in 'Tools | Options' ;)
AT
Thursday, 30 March 2017 14:49:11 UTC
I would love to see this feature on by default. It also assists when people want to use the new ValueTuples for the first time in a project too.
Thursday, 30 March 2017 18:03:09 UTC
Nuget consolidate would probably have saved me a man-year of dll hell. Thank god it's here!
640k
Wednesday, 05 April 2017 12:20:46 UTC
Scott,

Thanks for the tip. Initially I was disappointed that the same functionality wasn't avaiable in VS2017! I would be nice to have this info in the release notes.
Thursday, 06 April 2017 11:17:04 UTC
How is it decided whats popular and whats shown and whats isn't? Or is this based on you local package cache? It would be great if it shows suggestions from internal feeds as well.
Patrick
Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.