Implementing StyleCop MSBUILD From NuGet Package

半腔热情 提交于 2019-12-03 07:32:02

I'm posting the solution I came across for anyone in a similar position.

Firstly I followed this excellent guide on debugging MSBuild operations, which helped me to iron out some of the logic and variables:

http://blogs.msdn.com/b/visualstudio/archive/2010/07/06/debugging-msbuild-script-with-visual-studio.aspx

Following this I checked the StyleCopViolations.xml which was in my /obj/Debug/ folder. This however always returned 0 results, with just the following XML:

<StyleCopViolations/>

I did some research on this and found that I needed to include StyleCop.CSharpRules.dll in to my NuGet/lib/net40/ folder with the StyleCop.dll, StyleCop.CSharp.dll and StyleCop.Settings files.

My project didn't needed references to any of the aforementioned assemblies, but I realised that my NuGet package had a dependency on the StyleCop NuGet package which did not include StyleCop.CSharpRules.dll.

After adding this assembly I was still seeing 0 results, so I did a manual override of all 3 assemblies and the .Settings file from a fresh install of the StyleCop C:\Program Files\StyleCop\ installer (from CodePlex). After overwriting the NuGet package assemblies this started working!

So to wrap up, debug your MSBuild (with the link at the top of this post) and don't use the NuGet package just yet!

Cheers

Sherin Mathew

Use StyleCop.MSBuild instead of StyleCop as suggested by Dmitry Lobanov.

i.e use the command install-package stylecop.msbuild in the package manager console.

You can use combination of nuget packages StyleCop.MSBuild and StyleCop.Error.MSBuild to enable stylecop warnings as errors.

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