Enabling StyleCop.Analyzers on ASP.NET Core projects

送分小仙女□ 提交于 2019-12-08 02:26:27

问题


According to the docs I've read online all you need to do is add the following to the dependencies in project.json:

  "version": "1.0.0-*",

  "dependencies": {
    "DependencyA": "1.0.0-*",
    "DependencyB": "1.0.0-*",
    "StyleCop.Analyzers": {
      "version": "1.0.0",
      "type": "build"
    }
  },

  "frameworks": {
    "net46": { }
  }

(where DependencyA and DependencyB are two .NET Core projects from the same solution) and then StyleCop.Analyzers will run with the default rule set upon building the project. It doesn't. I get no warnings or anything and I'm pretty sure the code at the moment violates a lot of rules. Did anyone successfully get this working?


回答1:


My .NET Core version was apparently too old. After upgrading to the latest one it now works.




回答2:


I was able to get this working with Visual Studio 2015 Update 3 using the following steps:

  1. Create a new project from the ASP.NET Core Application (.NET Core) template.
  2. Add the StyleCop.Analyzers build dependency as you described in your question.
  3. Build the project in Visual Studio and make sure the Error List output is set to Build + IntelliSense.

This is what I get:

I've confirmed that this also works for projects targeting net451 instead of netcoreapp1.0, as well as Class Library projects targeting netstandard1.X.



来源:https://stackoverflow.com/questions/40379981/enabling-stylecop-analyzers-on-asp-net-core-projects

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!