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:
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.
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:
- Create a new Repo in VSO. Clone it locally.
- Add your solution
- Connect to your VSO repo in Visual Studio.
- Create the PreBuild.ps1 script you see below, to install ReSharper's command line tools
- Create the TeamBuild.proj script you see below, to run InspectCode and build your solution
- Team Explorer -> Builds -> New Build Definition. Select the Process tab
- Set Build Process Template to GitTemplate.12.xaml
- Projects = TeamBuild.proj
- Pre-build script path = Tools\PreBuild.ps1
- Run the script once on your machine to establish a baseline. Add it to Git.
- Push
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |
<PropertyGroup> | |
<SolutionPath>InspectCodeExample\InspectCodeExample.sln</SolutionPath> | |
</PropertyGroup> | |
<PropertyGroup> | |
<!-- keep this in synch with Tools\PreBuild.ps1 --> | |
<ResharperCltVersion>8.2.0.2151</ResharperCltVersion> | |
</PropertyGroup> | |
<!--=====================================================================--> | |
<Target Name="Build"> | |
<MSBuild Projects="@(SolutionPath)" /> | |
<CallTarget Targets="InspectCode" /> | |
</Target> | |
<!--=====================================================================--> | |
<Target Name="InspectCode"> | |
<!--I found that this approach caused InspectCode to crash with cryptic errors --> | |
<!--<InspectCode SolutionFile="$(SolutionPath)" OutputFile="$(TEMP)\InspectCodeOutput.xml" NoMSBuildOutput="true" />--> | |
<Exec Command="C:\Chocolatey\bin\InspectCode /o=$(TEMP)\InspectCodeOutput.xml $(SolutionPath)" /> | |
<Exec Command="fc.exe InspectCodeBaseline.xml $(TEMP)\InspectCodeOutput.xml" /> | |
</Target> | |
<!-- Required if you use the InspectCode target above --> | |
<!--<Import Project="C:\Chocolatey\lib\resharper-clt.portable.$(ResharperCltVersion)\tools\InspectCode.MsBuild.Targets"/>--> | |
</Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# keep this in synch with TeamBuild.proj | |
# | |
$ResharperCltVersion='8.2.0.2151' | |
# UseBasicParsing is required if IE has never been run on the machine. | |
wget -UseBasicParsing chocolatey.org/install.ps1 | iex | |
if (!$?) { throw "failed to install chocolatey"} | |
cinst resharper-clt.portable -version $ResharperCltVersion | |
if (!$?) { throw "failed to install R# CLT"} |
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.