Can ReSharper automatically add missing references? - resharper

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?

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

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.
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'".
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.

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.

Related

How do I disable a specific Resharper inspection across an entire project?

Resharper alerts me about public functions that are never accessed. This is useful in most areas in my code, but I have a project that contains classes that function as a public API (actually Hot-Chocolate GraphAPI functions), so, naturally, there are no calls to them elsewhere in the code. I don't need Resharper to tell me about them.
I know it's possible to disable these kinds of warnings per file by including a comment. I'm wondering if there is a way to disable this warning across an entire project.
N.B. I don't want to disable Resharper itself in this project (as described in this answer). Resharper is still providing value to me and it's just this specific warning that I want to disable.
ReSharper's help lists various ways to disable a specific inspection. You can disable a specific inspection in a scope either using an .editorconfig file, or with a ReSharper settings file.
Following the link provided (thanks #IgorAkhmetov) I created an .editorSettings file in the scope I wanted (the root of the single project) with the following contents:
resharper_unused_member_global_highlighting = none
resharper_class_never_instantiated_global_highlighting = none
Outcome: Resharper stopped telling me about unused public members, or uninstantiated public classes, in that project only. It carries on telling me about those problems in the rest of my codebase.
Option "Solution-wide inspections" can be turned off in project's properties:

Resharper naming convention exception for specific word

Our customer has a terminology called A2b, not A2B, exactly A2b.
We want to have the same name in our source code.
However, Resharper always gives warnings and proposes to use A2B.
For example: We would like to have LoadA2bData, CheckA2bAvailability instead of LoadA2BData, CheckA2BAvailability.
Is there any workaround for this?
I saw this question Resharper Naming Exception for "iPhone". But it cannot be applied for our case because A2i is not only used as prefix or postfix, but also in the middle of the names.
You can change the regex off resharper 7 this means that you can enter a custom inspection regex. You can make a new naming style for your current project.

CodeContracts and resharper vs2012 not working

I have Resharper and it's a fantastic tool
Starting a projects and I need to use CodeContracts. However Resharper ignores them.
After checking a few blogs I came across this one:
http://www.infinitec.de/post/2010/11/18/Using-Code-Contracts-Visual-Studio-and-with-Resharper.aspx
However I get an error
Error 2
The command ""C:\Program Files (x86)\Microsoft\Contracts\Bin\ccrewrite"
"#MyProject.Coreccrewrite.rsp"" exited with code 1.
Has anybody managed to have codecontracts and resharper to work together?
Edited
What I am doing is
Trying to use codeContract and resharper gives a Method invocation is skipped etc..
Googled and found lots of people with same problem and no solution.
As you can see I attached a link that should have done the trick but didnt
Create a new project in vs2012 and try to use code contract and resharper will not let you.
It will be disabled and if you enable it you get another error
Comment from Resharper team on
http://youtrack.jetbrains.com/issue/RSRP-182553#comment=27-200330
ReSharper will not support "Code Contracts" as is in the mid-term
future. There are 2 main reasons for this:
CodeContracts are written in the code block, and, moreover, in the separate assembly. ReSharper requires contracts to be at the
metadata level
Current contract are too complex and are not supposed to be analyzed in real-time.
During ReSharper development, we analyze CodeContracts and building
corresponding ReSharper code annotation marks. We are going to extent
our annotations, and always keep them in-sync with contracts.
I am stuffed!!!

How do I make Resharper stop flagging my test function as not used?

I'm using xUnit for unit testing and in one of my test classes I have 65 tests. Resharper is flagging one of them as not used and is keeping the file flagged yellow/orange until I delete it. I don't want to delete it. I want to keep that test method.
I assume that you have xunitcontrib for ReSharper installed, since other test methods are not marked as unused. I also assume that your method is public and has the same test attributes as other test methods (e.g., Fact or Theory). If that is not the case, you might check that you have external annotations for attributes of this method (they are provided with xunitcontrib for ReSharper).
One of possible reasons for incorrect issue reporting by ReSharper is that some of its caches have not been updated. If you can reproduce the problem (given that almost a month passed since you asked your question, it seems to be unlikely), try clearing caches via menu RESHARPER -> Options -> General -> Clear Caches and then restart Visual Studio.
It could also be that the ReSharper annotations are turned off.
You could verify this via RESHARPER > Options > Code Inspection - Code Annotations.

ILMerged Classes Not Visible To Resharper

I have ILMerged some assemblies. For example:
Foo.Bar
Bar.Foo
Foo.Baz
Into one assembly. For example:
FooBarBaz.Merged
And it works. That is, when I reference FooBarBaz.Merged and use something like Foo.Bar.MyClass in code it compiles just fine.
However Resharper (v5) does not work. Usages of any type from the merged assembly are bloody red. What's worse, I get no intellisense for these types either. Basically this assembly cannot coexist with Resharper.
I wonder if there's some ILMerge param that can cure this. ILMerge documentation is pretty well hidden, but I found this. I have hacked at various switches...to no avail.
Alternately, is there some Resharper setting I can change. I really prefer not to have to do this because this is an OSS project.
I have solved this. It's a bug in Resharper, I beleive. However it's not a bug that matters to me.
It seems that Resharper has trouble seeing types of an ILMerged assembly if the project that references that assembly is inside a solution that contains some of the assemblies that got merged. This is not a case that I care about.
I learned this from this thread.
For anyone who wants this fixed please go here to vote up support for ILMerged assemblies in R#: http://youtrack.jetbrains.com/issue/RSRP-192616

Resources