bmw0128
bmw0128

Reputation: 13698

Can ReSharper automatically add missing references?

I just started using VS2008 and ReSharper. I have a line:

Microsoft.Office.Server.Diagnostics.PortalLog.LogString("*** BOO Feature activating ***");

VS shows "Office" as red because it cannot resolve symbol "Office".

Can I make ReSharper just add the reference automatically, or do I need to manually surf to the reference and add it?

Upvotes: 2

Views: 3698

Answers (3)

Nick Craver
Nick Craver

Reputation: 630419

If you think about how large the framework is, plus any potential third party assemblies in the GAC...you start to see why when a type's not found Resharper looking through them all for it is a really bad idea for performance.

A typo would leave you with a coffee break while it looks. Also, what if it did find the type, nothing says 2 third party assemblies couldn't define it, or 2 or more versions of that assembly in the GAC, etc.

It's better to leave the decision up to you to reference exactly what you want, and that's what it does, for performance and explicitness.

Upvotes: 1

Bronumski
Bronumski

Reputation: 14272

To get the best out of resharper in relation to referencing assemblies and adding using statements don't plan ahead. When coding don't put in any references our using statements just start typing the code:

public class MyClass
{
    Foo foo = new Foo();
}

Initially "Foo" will be highlighted to indicate it cannot resolve the symbol, place your caret on "Foo" and either hit your short cut for the resharper hot fix (Alt + Enter) or click on the red light bulb.

  1. If any of the other projects in your solution reference the assembly that contains "Foo" or it is in the core .net library you will get the option to "Reference '{Foo's Assembly}' and use '{Foo's namespace}.Foo'".
  2. If your project already contains the reference you will get the option to use {Foo's namespace}.Foo.

If it cannot resolve the assembly you will need to add it the once but after that either option 1 or 2 will apply.

Upvotes: 1

Otávio Décio
Otávio Décio

Reputation: 74270

R# will not add the reference automatically but once you do it (manually) it will suggest the correct namespaces for you.

Upvotes: 2

Related Questions