簡體   English   中英

C#包裝程序中的StyleCop無法檢測到違規

[英]StyleCop from C# wrapper not detecting violations

我正在使用 GitHub存儲庫嘗試從CMD運行StyleCop。 我下載了GitHub存儲庫,並使用VS2017在本地計算機上構建了它。 我試圖運行批處理腳本,這是我到目前為止所做的:

  • 下載為ZIP並解壓縮到一個文件夾中。
  • 在VS2017中打開了解決方案並進行了構建(無錯誤)。

然后,我嘗試運行'sample.bat' (.. \\ source \\ StyleCopCmdLine \\ bin \\ Debug \\ sample.bat) ,該操作將執行以下操作(由源所有者創建以測試存儲庫):

  • 加載源文件.. \\ source \\ StyleCopWrapper.Tests \\ Testfiles \\ FileWith7Errors.cs
  • 加載設置文件.. \\ source \\ StyleCopWrapper.Tests \\ TestFiles \\ AllSettingsEnabled.StyleCop

然后,批處理腳本運行StyleCopCmdLine並返回以下內容:

C:\Users\X\Desktop\Test\StyleCopCmdLine- 
master\source\StyleCopCmdLine\bin\Debug>Rem Runs the command line with 
reasonable parameters

C:\Users\X\Desktop\Test\StyleCopCmdLine- 
master\source\StyleCopCmdLine\bin\Debug>StyleCopCmdLine -- 
SourceFiles="..\..\..\StyleCopWrapper.Tests\TestFiles\FileWith7Errors.cs" -- 
s=@"..\..\..\StyleCopWrapper.Tests\TestFiles\AllSettingsEnabled.StyleCop"
StyleCopCmdLine 1.0.0.0
Copyright ©  2017

  -f, --SourceFiles                    Required. The files or folders to scan.
                                       Multiple files or folders can be listed

  -s, --SettingsFile                   Required. The settings to use.

  --AdditionalAddInPaths               (Default: System.String[]) The paths to
                                       rules files. Multiple folders can be
                                       listed

  --ShowOutput                         (Default: False) Show the addin of files
                                       to scan output in the log.

  --CacheResults                       (Default: False) Cache scan results.

  --XmlOutputFile                      (Default: .\stylecop.xml) Xml Output
                                       File.

  --LogFile                            (Default: .\stylecop.log) Log File.

  --ForceFullAnalysis                  (Default: True) Force a full analysis.

  --TreatViolationsErrorsAsWarnings    (Default: True) Treat violation errors
                                       as warnings.

  --MaximumViolationCount              (Default: 1000) Maximum violations
                                       before the scan is stopped.

  -v, --verbose                        (Default: True) Prints the configuration
                                       messages to standard output.

  --help                               Display this help screen.


SourceFiles: ..\..\..\StyleCopWrapper.Tests\TestFiles\FileWith7Errors.cs
SettingsFile: 
@..\..\..\StyleCopWrapper.Tests\TestFiles\AllSettingsEnabled.StyleCop
MaximumViolationCount: 1000
ShowOutput: False
CacheResults: False
ForceFullAnalysis: True
XmlOutputFile: .\stylecop.xml
LogFile: .\stylecop.log
TreatViolationsErrorsAsWarnings: True
AdditionalAddInPaths: C:\Program Files (x86)\StyleCop 4.7


No violations encountered
Succeeded [True]
Violation count [0]

C:\Users\X\Desktop\Test\StyleCopCmdLine-master\source\StyleCopCmdLine\bin\Debug>pause

如您所見,該腳本未返回任何違規,但是當我打開StyleCopCmdLine解決方案時,導航至文件“ FileWith7Errors”,右鍵單擊並單擊“運行StyleCop”,它將返回7個違規。

我還嘗試創建自己的使用StyleCopConsole的StyleCop模塊(來自官方StyleCop存儲庫),但是當我在任何有違規行為的文件上運行它(我確保選擇了正確的設置文件)時,我永遠也不會得到違規...

刪除C:\\ Program Files(x86)\\ StyleCop 4.7可獲得完全相同的結果。

我嘗試過的其他存儲庫可能會出現錯誤或相同的問題:

  • StyleCopCLI
  • StyleCopCmd
  • StyleCop-Runner
  • StyleCopConsole

為什么到目前為止我嘗試過的所有方法都不能復制簡單的“ RightClick-> Run StyleCop”

對於某些背景,我試圖從CMD或PowerShell運行StyleCop分析,以便可以將其作為TFSBuild 2015中的構建步驟來運行。

編輯 -已在多台具有相同問題的計算機上進行了測試。

編輯2-將所有源代碼文件加載到StyleCop分析器中,然后開始分析之后,分析似乎運行了<0.1秒-顯然不正確,對所有源代碼文件的分析應該比這更長。 我的想法是,在StyleCop DLL內的某個地方捕獲了一個錯誤,但未記錄該錯誤,然后分析完成,但是它仍然返回“ true”,表明分析成功,即使它顯然未正確運行。 。

因此,事實證明,實際上未正確運行分析的原因是由於我使用了插件路徑。

初始化StyleCopConsole類時,它需要以下參數:

StyleCopConsole(string settings, 
                bool writeResultsCache, 
                string outputFile, 
                ICollection<string> addInPaths, 
                bool loadFromDefaultPath);

之前,我要么將'addInPaths'定義為null,要么顯式傳遞兩個StyleCop CSharp DLL路徑。 解決方法是改為將外接程序路徑定義為系統上StyleCop的安裝:

var addInPath = @"C:\Program Files (x86)\StyleCop 4.7";

然后,StyleCopConsole將本身獲取所有必需的DLL。 現在可以使用這些設置運行分析

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM