tags:

views:

51

answers:

3
+1  Q: 

Resharper Question

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 b/c 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?

+1  A: 

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

Otávio Décio
+1  A: 

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.

Nick Craver
i see your point, thx
bmw0128
A: 

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.

Bronumski

related questions