简体   繁体   English

resharper是否有asp.net mvc的问题?

[英]Does resharper have problems with asp.net mvc?

I'm using the latest release of resharper. 我正在使用最新版本的resharper。 Just downloaded and installed last week so I'm new to using it. 刚刚下载并安装在上周,所以我是新手使用它。 The problem I'm having is that in my ASP.NET MVC application all of my controllers say they are never used and all the methods within the controller say they are never used. 我遇到的问题是,在我的ASP.NET MVC应用程序中,我的所有控制器都说它们从未使用过,控制器中的所有方法都说它们从未使用过。

Is there a way to suppress the messages or for resharper to understand they are used? 有没有办法抑制消息或resharper理解它们被使用?

You can turn on/off the various warnings and hints that Resharper gives you. 您可以打开/关闭Resharper为您提供的各种警告和提示。

HOWEVER, if you write unit tests then they WILL be used and Resharper will be happy. 但是,如果你编写单元测试,那么它们将被使用,Resharper会很高兴。

update 更新

You could consider telling Resharper to ignore the unused members of your controller by doing this at the top and bottom of your controller class... 您可以考虑通过在控制器类的顶部和底部执行此操作来告诉Resharper忽略控制器中未使用的成员...

public class MyController: Controller
{
    // ReSharper disable UnusedMember.Global

    ...        

    // ReSharper restore UnusedMember.Global
}

... or, at least put these comments around the public methods on your controller (I use StyleCop and so all the public methods will be grouped together anyway. This is reasonably unobtrusive, and would get rid of this warning from Resharper. ...或者,至少将这些注释放在控制器上的公共方法上(我使用StyleCop,所以所有的公共方法都会被组合在一起。这是相当不显眼的,并且会从Resharper中删除这个警告。

Yep, current ReSharper version doesn't place references on MVC controllers (although, next one will). 是的,当前的ReSharper版本没有在MVC控制器上放置引用(尽管下一个将会)。

In meantime you can mark controller class and action methods with ImplicitUse attribute. 在此期间,您可以使用ImplicitUse属性标记控制器类和操作方法。 You can find it in JetBrains.Annotations assembly. 您可以在JetBrains.Annotations程序集中找到它。 If you don't want external dependency, you can add necessary annotations attributes to your project, you will find them in ReSharper->Options->Code Inspection->Code Annotation->Copy default implementation. 如果您不想要外部依赖,可以向项目添加必要的注释属性,您可以在ReSharper-> Options-> Code Inspection-> Code Annotation-> Copy default implementation中找到它们。

There's no way I know of that will force Resharper to "know" that a method is used (I've never experienced this problem with Resharper). 我无法知道这将迫使Resharper“知道”使用了一种方法(我从来没有遇到过Resharper的这个问题)。

If you don't want to globally turn on/off various inspection options, you can choose to suppress specific inspection messages with a comment. 如果您不想全局打开/关闭各种检查选项,则可以选择使用注释来抑制特定检查消息。 Like so... 像这样......

// ReSharper disable UnusedPrivateMember
private void NotUsed ()
{
    // ... Code ...
}
// ReSharper restore UnusedPrivateMember

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM