tcartwright / SqlServer.Rules

SQL Server static code analysis rules for SSDT database projects
MIT License
39 stars 11 forks source link
analysis sql-server static-analysis

Yet Another Rule-set for SQL Server DataTools

Overview

Just what it says on the box: A library of SQL best practices as extended database code analysis rules checked at build. The rules can be installed locally as well as on the build server.

For a complete list of the current rules we have implemented see here. For example code see here

Organization

Debug / Test

1) Ensure SqlServer.Rules.SolutionGenerator is "Set as Startup Project" 1) Set Command line arguments: 1) Open up the properties for the SqlServer.Rules.SolutionGenerator project 1) Select the Debug tab 1) Enter one of the following scenarios: 1) To debug the test harness db: --build --reportDirectory ".\Files" --solution "..\..\..\TestDatabase\TestDatabase.sln" 1) To debug a Sql project: --build --reportDirectory ".\Files" --solution "{path}.sln" 1) Add a break point in the SqlServer.Rules project in any of the rules you wish to debug

Note: if you need to debug the loading of the library see here

Install

An Install.bat is provided that will copy out the rules to all of the appropriate folder destinations. Or you can optionally follow these instructions:

Follow the instructions on MS Docs Install Static Code Analysis Rule.

The build should be installed to the template path %VSBIN%\Common7\IDE\Extensions\Microsoft\SQLDB\DAC\{SqlEngine}\Extensions So for Visual Studio 2017 with DAC version 150 the path might be

C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\Extensions\Microsoft\SQLDB\DAC\150\Extensions\SqlServer.Rules

NOTES:

Project Configuration