Source Monitor

TeamCity整合Source Monitor報表

Source Monitor是用來分析程式碼度量的工具,先到[官網](http://www.campwoodsw.com/sourcemonitor.html)下載[![](http://1.bp.blogspot.com/-aUW-QXGVCtE/U1drxYfiw4I/AAAAAAAABSk/phO8_RBI2Os/s1600/01.%E4%B8%8B%E8%BC%89.png)](http://1.bp.blogspot.com/-aUW-QXGVCtE/U1drxYfiw4I/AAAAAAAABSk/phO8_RBI2Os/s1600/01.%E4%B8%8B%E8%BC%89.png) 安裝後的預設路徑為C:\Program Files (x86)\SourceMonitor[![](http://4.bp.blogspot.com/-MKLglO_Layc/U1dr6iQoHSI/AAAAAAAABSs/JSEVH5l68VE/s1600/02.%E5%AE%89%E8%A3%9D%E8%B7%AF%E5%BE%91.png)](http://4.bp.blogspot.com/-MKLglO_Layc/U1dr6iQoHSI/AAAAAAAABSs/JSEVH5l68VE/s1600/02.%E5%AE%89%E8%A3%9D%E8%B7%AF%E5%BE%91.png) 先淮備一個用來產生報告的設定檔SourceMonitorCommands.xml <?xml version="1.0" encoding="utf-8"?> <sourcemonitor_commands> <write_log>true</write_log> <command> <project_file>SourceMonitor.smp</project_file> <checkpoint_name>Baseline</checkpoint_name> <project_language>C#</project_language> <!-- 要分析專案的相對路徑 --> <source_directory>..</source_directory> <source_subdirectory_list> <exclude_subdirectories>true</exclude_subdirectories> <source_subtree>bin\</source_subtree> <source_subdirectory>obj\</source_subdirectory> </source_subdirectory_list> <parse_utf8_files>True</parse_utf8_files> <ignore_headers_footers>True</ignore_headers_footers> <export> <!-- 最後輸出的檔名 --> <export_file>SourceMonitorReport.xml</export_file> <export_type>2</export_type> </export> </command> </sourcemonitor_commands> 因為輸出的是XML格式,所以需要透過XSL轉成HTML格式 先下載轉換的工具[msxsl.exe](http://www.microsoft.com/en-us/download/details.aspx?id=21714)[![](http://4.bp.blogspot.com/-1zIhVE-ezj0/U1dsCkgZ1AI/AAAAAAAABS0/CSALVxR5RMw/s1600/03.%E4%B8%8B%E8%BC%89msxsl.png)](http://4.bp.blogspot.com/-1zIhVE-ezj0/U1dsCkgZ1AI/AAAAAAAABS0/CSALVxR5RMw/s1600/03.%E4%B8%8B%E8%BC%89msxsl.png) SourceMonitor.xsl<?xml version="1.0" encoding="utf-8" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/TR/xhtml1/strict"> <xsl:output method="html"/> <xsl:template match=”/"> <html> <head> <style type="text/css”> /* Web20 Table Style written by Netway Media, http://www.netway-media.com */ table { border-collapse: collapse; border: 1px solid #666666; font: normal 11px verdana, arial, helvetica, sans-serif; color: #363636; background: #f6f6f6; text-align: left; } caption { text-align: center; font: bold 16px arial, helvetica, sans-serif; background: transparent; padding: 6px 4px 8px 0px; color: #CC00FF; text-transform: uppercase; } thead, tfoot { background: url(bg1.