How to debug T-SQL Static Code Analysis Rules in Visual Studio 2010
I tried to create T-SQL Static Code Analysis Rules in Visual Studio 2010 to analyze T-SQL code in Visual Studio 2010 database project. But I couldn’t find a way to debug them.
Does anyone know how to debu开发者_C百科g these rules?
You need to run another instance of VS2010 and open a dbproj to debug. You can do this by setting Debug option to "Start External Program" and point it to VS2010 exe (C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe). Hope this is what you are looking for..
I found this blog post which covers how to make and debug tsql static code analysis. Good luck! http://blogs.msdn.com/b/gertd/archive/2009/01/01/creating-t-sql-static-code-analysis-rules.aspx
Here are the important bits in a nutshell:
Start with a project that builds and works I'd hope
From a working project, create post build tasks:
copy "$(TargetDir)$(TargetName)$(TargetExt)" "$(ProgramFiles)\Microsoft Visual Studio 10.0\VSTSDB\Extensions\$(TargetName)$(TargetExt)" /y copy "$(ProjectDir)$(TargetName).Extensions.xml" "$(ProgramFiles)\Microsoft Visual Studio 10.0\VSTSDB\Extensions\$(TargetName).Extensions.xml" /y
(the article mentions copying these files to your GAC, but I didn't need to do that)
- Build, open a new db project, and ensure that your rules got copied and work
- Set some break points (like creating a default constructor for the rules, and setting a break point there so you can se it gets loaded, then again inside of the rule)
- Under debug settings go to:
Start Action – Start external program “C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe”
- Start debugging, a new VS will load
- In the new VS, open the db project, you should see your break points in the constructors getting hit. This means that your files coped and you are correctly debugging your code
- Now build the db, this should trigger the rest of your debug points.
Peace.
精彩评论