Saturday, May 31, 2014

Automating ReSharper's Inspect Code

If you write C#, I hope you have ReSharper.

If you have ReSharper, I hope you have tried its "Code Issues" feature. It has lots of good suggestions, and I need all the help I can get.

Staying clean requires running the analyzer over your whole solution. ReSharper doesn't update its results automatically: you have to explicitly click to make it happen. I hate explicitly clicking. It's also slow.

I decided to see if I could run it automatically in a Continuous Integration build server. I have figured out how to do so using TeamBuild on Visual Studio Online (VSO). Here's how:
  1. Create a new Repo in VSO. Clone it locally.
  2. Add your solution
  3. Connect to your VSO repo in Visual Studio.
  4. Create the PreBuild.ps1 script you see below, to install ReSharper's command line tools
  5. Create the TeamBuild.proj script you see below, to run InspectCode and build your solution
  6. Team Explorer -> Builds -> New Build Definition. Select the Process tab
    1. Set Build Process Template to GitTemplate.12.xaml
    2. Projects = TeamBuild.proj
    3. Pre-build script path = Tools\PreBuild.ps1
  7. Run the script once on your machine to establish a baseline. Add it to Git.
  8. Push
Now, when  the set of Code Issues changes, you'll get notified by the build.

Loading TeamBuild.proj from Gist 1d0e58acb2aeda163df3

Loading PreBuild.ps1 from Gist d5a71230d524965057be

I'd like to find a way to do this in Travis-CI, which would require running these tools on Mono. Let me know if you get it to work.


1 comment:

Alan Wales said...

Agree very much with the sentiments regarding Resharper inspection value, so I created a build task you can use with Visual Studio Online:

https://marketplace.visualstudio.com/items?itemName=alanwales.resharper-code-analysis