我在用
this
GitHub repo尝试从CMD运行StyleCop。我下载了GitHub repo,并使用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',右键单击并单击'Run StyleCop',它将返回7个冲突。
我还试图创建自己的StyleCop模块,它使用StyleCopConsole(来自官方StyleCop repo),但是当我在任何有冲突的文件上运行它时(我确保选择了正确的设置文件),我永远不会得到任何冲突。。。
删除
C:\程序文件(x86)\样式副本4.7
得到完全相同的结果。
我尝试过的其他回购要么出错,要么是同一个问题:
-
StyleCopCLI公司
-
样式命令
-
StyleCop跑步者
-
样式控制台
为什么到目前为止我尝试的方法都没有复制
'右键单击->运行StyleCop'
?
对于某些背景,我尝试从CMD或PowerShell运行StyleCop分析,以便在TFSBuild 2015中作为构建步骤运行它。
编辑
-这已经在同一问题的多台机器上进行了测试。
编辑2
-在我将所有源代码文件加载到StyleCop分析器中,然后开始分析之后,分析似乎会运行~<0.1秒-这显然不对,对所有源代码文件的分析应该比这需要更长的时间。我的想法是,在StyleCop DLL中的某个地方,错误被捕获,但没有被记录,然后分析完成,但是它仍然返回“true”,表明分析成功,即使它显然没有正常运行。。。