I’m using Visual Studio 2010, and the project targets .NET 3.5. The same approach would work fine if the project was targeting .NET 4.0.
I’m using NuGet to manage dependencies. The first thing I did was add node-jshint as a dependency of the project.
I opened the project’s file (something.csproj). I added a target:
Make BeforeBuild depend on jshint:
<Target Name=”BeforeBuild” DependsOnTargets=”jshint”>
Add a new text file to the root of project called “jshintrc.json” If the file is included in the Visual Studio project, make sure the build action is “None” so Visual Studio doesn’t try to do anything with it. The file contents should look like this. The latest available version of node-json at this time, 0.5.5, doesn’t deal with a Byte Order Markers (BOM) in the jshintrc.json file, so when saving it, be sure the BOM isn’t included.
Now whenever Visual Studio builds the project, JSHint errors will appear in the VS error list just like all other types of errors. It runs JSHint on all .js files included in your project as content (the way .js should be included in your project).
jshint in msbuild by Craig Andrews is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.
3 thoughts on “jshint in msbuild”
Wonder how hard it would be to write a NuGet package to make all projects auto reference a .targets file with that msbuild target in it.
Similar project mentioned on the NuGet Project uncovered: http://elegantcode.com/2012/02/16/nuget-project-uncovered-jsvalidator/