所以我试图运行一堆规则定义在一个规则集。RuleSet文件实际上是使用Sonarqube生成的-我已经选择了其中的所有规则,包括FxCop, ReSharper和StyleCop规则。我像这样启动FxCop:
C:/FxCop/FxCopCmd.exe /file:C:TestProjectbinTestProject.dll /ruleset:=C:TestProjecttestproject.ruleset /out:C:TestProjectfxcop-report.xml /outxsl:none /forceoutput /searchgac /aspnet
它正确启动,但我得到以下消息:
初始化内省引擎…分析
,
初始化凤凰引擎…
分析……
分析完成。
* 1个分析引擎异常
XML输出包含以下内容:
<Exception Keyword="CA0001" Kind="Engine">
<Type>Phx.FatalError</Type>
<ExceptionMessage>Exception of type 'Phx.FatalError' was thrown.</ExceptionMessage>
<StackTrace> at Phx.FatalError.Dispatch()
at Phx.Logging.Diagnostics.DiagnosticMessage.LogMessage(Severity severity, DiagnosticInfo diagnosticInfo, SourceContext sourceContext, String descriptionString)
at Phx.PE.PEUtilities.UserError(String infoMessage)
at Phx.Pdb.ReaderImplementation.Open(Boolean loadTypeOnly)
at Phx.PEModuleUnit.LoadPdb()
at Phx.PE.ReaderPhase.CheckSymbolicInformation()
at Phx.PEModuleUnit.LoadGlobalSymbols()
at Phx.PEModuleUnit.LoadEncodedIRUnitList()
at Phx.PEModuleUnit.GetEnumerableContributionUnit(ContributionUnitEnumerationKind contributionUnitEnumerationKind)
at Phx.PEModuleUnit.GetEnumerableContributionUnit()
at Microsoft.FxCop.Engines.Phoenix.PreScanPass.GetFunctionUnits(PEModuleUnit peModuleUnit)
at Microsoft.FxCop.Engines.Phoenix.PreScanPass.Execute(ModuleUnit moduleUnit)
at Phx.Passes.Pass.DoPass(ModuleUnit moduleUnit)
at Phx.Passes.PassList.DoPassList(ModuleUnit moduleUnit)
at Microsoft.FxCop.Engines.Phoenix.PhoenixAnalysisEngine.Host.ExecutePasses(PEModuleUnit peModuleUnit)
at Microsoft.FxCop.Engines.Phoenix.PhoenixAnalysisEngine.AnalyzeInternal()
at Microsoft.FxCop.Engines.Phoenix.PhoenixAnalysisEngine.Analyze()
at Microsoft.FxCop.Common.EngineManager.Analyze(Project project, Boolean verboseOutput)
</StackTrace>
</Exception>
如果我在没有/aspnet
标志的情况下运行相同的命令,我仍然会得到相同的错误,但我确实在XML输出文件中得到了实际的消息。
我的最终目标是从Sonarqube运行这个(使用Sonarqube在TeamCity中的运行器),但我在那里也得到了完全相同的问题。从Teamcity开始,我得到了以下内容:
18:19:46][Step 4/4] INFO: ------------------------------------------------------------------------
[18:19:46][Step 4/4] INFO: EXECUTION FAILURE
[18:19:46][Step 4/4] INFO: ------------------------------------------------------------------------
[18:19:46][Step 4/4] Total time: 24.122s
[18:19:46][Step 4/4] ERROR: Error during Sonar runner execution
[18:19:46][Step 4/4] org.sonar.runner.impl.RunnerException: Unable to execute Sonar
[18:19:46][Step 4/4] at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:91)
[18:19:46][Step 4/4] at org.sonar.runner.impl.BatchLauncher$1.run(BatchLauncher.java:75)
[18:19:46][Step 4/4] at java.security.AccessController.doPrivileged(Native Method)
[18:19:46][Step 4/4] at org.sonar.runner.impl.BatchLauncher.doExecute(BatchLauncher.java:69)
[18:19:46][Step 4/4] at org.sonar.runner.impl.BatchLauncher.execute(BatchLauncher.java:50)
[18:19:46][Step 4/4] at org.sonar.runner.api.EmbeddedRunner.doExecute(EmbeddedRunner.java:102)
[18:19:46][Step 4/4] at org.sonar.runner.api.Runner.execute(Runner.java:90)
[18:19:46][Step 4/4] at org.sonar.runner.Main.executeTask(Main.java:70)
[18:19:46][Step 4/4] at org.sonar.runner.Main.execute(Main.java:59)
[18:19:46][Step 4/4] at org.sonar.runner.Main.main(Main.java:41)
[18:19:46][Step 4/4] Caused by: java.lang.IllegalStateException: The execution of "C:/FxCop/FxCopCmd.exe" failed and returned 1 as exit code. See http://msdn.microsoft.com/en-us/library/bb429400(v=vs.80).aspx for details.
[18:19:46][Step 4/4] at com.google.common.base.Preconditions.checkState(Preconditions.java:145)
[18:19:46][Step 4/4] at org.sonar.plugins.fxcop.FxCopExecutor.execute(FxCopExecutor.java:63)
[18:19:46][Step 4/4] at org.sonar.plugins.fxcop.FxCopSensor.analyse(FxCopSensor.java:102)
[18:19:46][Step 4/4] at org.sonar.plugins.fxcop.FxCopSensor.analyse(FxCopSensor.java:87)
[18:19:46][Step 4/4] at org.sonar.batch.phases.SensorsExecutor.executeSensor(SensorsExecutor.java:59)
[18:19:46][Step 4/4] at org.sonar.batch.phases.SensorsExecutor.execute(SensorsExecutor.java:51)
[18:19:46][Step 4/4] at org.sonar.batch.phases.DatabaseModePhaseExecutor.execute(DatabaseModePhaseExecutor.java:120)
[18:19:46][Step 4/4] at org.sonar.batch.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:264)
[18:19:46][Step 4/4] at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:92)
[18:19:46][Step 4/4] at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:77)
[18:19:46][Step 4/4] at org.sonar.batch.scan.ProjectScanContainer.scan(ProjectScanContainer.java:235)
[18:19:46][Step 4/4] at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:230)
[18:19:46][Step 4/4] at org.sonar.batch.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:228)
[18:19:46][Step 4/4] at org.sonar.batch.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:220)
[18:19:46][Step 4/4] Final Memory: 20M/428M
[18:19:46][Step 4/4] INFO: ------------------------------------------------------------------------
[18:19:46][Step 4/4] at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:92)
[18:19:46][Step 4/4] at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:77)
[18:19:46][Step 4/4] at org.sonar.batch.scan.ScanTask.scan(ScanTask.java:57)
[18:19:46][Step 4/4] at org.sonar.batch.scan.ScanTask.execute(ScanTask.java:45)
[18:19:46][Step 4/4] at org.sonar.batch.bootstrap.TaskContainer.doAfterStart(TaskContainer.java:135)
[18:19:46][Step 4/4] at org.sonar.api.platform.ComponentContainer.startComponents(ComponentContainer.java:92)
[18:19:46][Step 4/4] at org.sonar.api.platform.ComponentContainer.execute(ComponentContainer.java:77)
[18:19:46][Step 4/4] at org.sonar.batch.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:158)
[18:19:46][Step 4/4] at org.sonar.batch.bootstrapper.Batch.executeTask(Batch.java:95)
[18:19:46][Step 4/4] at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:67)
[18:19:46][Step 4/4] at org.sonar.runner.batch.IsolatedLauncher.execute(IsolatedLauncher.java:45)
[18:19:46][Step 4/4] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[18:19:46][Step 4/4] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[18:19:46][Step 4/4] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[18:19:46][Step 4/4] at java.lang.reflect.Method.invoke(Method.java:497)
[18:19:46][Step 4/4] at org.sonar.runner.impl.BatchLauncher$1.delegateExecution(BatchLauncher.java:87)
[18:19:46][Step 4/4] ... 9 more
[18:19:46][Step 4/4] Process exited with code 1
[18:19:46][Step 4/4] Step SonarQube (SonarQube Runner) failed
这是使用安装在没有Visual Studio的盒子上的FxCop v12,以防有任何重要性…
编辑
问题肯定是在Phoenix分析部分——在禁用这里描述的DFA规则后,它成功了。
在网上搜索" phx . fatalerror ";错误,我发现了这篇博客文章,其中作者基本上说做一个
regsrv32.exe msdia100.dll
(在他的情况下显然是VS2010),为他修复了这个问题。
这使我得到了必要的提示,这可能是我的机器出现错误的原因。
我在我的DEV盒子上用Visual Studio Standalone Profiler设置[1]搞砸了。我安装了分析工具,这导致%ProgramFiles(x86)%Microsoft Visual Studio 12.0Team ToolsPerformance Tools
(来自原始VS安装)的内容被替换,当时我不知道。但是,上述设置也会创建(或替换)%ProgramFiles(x86)%Microsoft Visual Studio 12.0Common7PackagesDebuggermsdia120.dll
文件。该文件是一个COM服务器,并在安装期间注册(Visual Studio或Standalone Profiler包),我也不知道。
卸载上述独立分析器包,卸载上述目录中的文件,同时注销msdia1xx.dll。
所以,在我的情况下,最简单的修复是重新安装在独立的Profiler包(在我的情况下是x64),一切又工作了。
你也可以成功注册你的msdia1xx.dll版本[可能需要以管理员身份运行]:
Visual Studio 2010:
regsvr32 "%ProgramFiles(x86)%Microsoft Visual Studio 10.0Common7PackagesDebuggermsdia100.dll"
Visual Studio 2012:
regsvr32 "%ProgramFiles(x86)%Microsoft Visual Studio 11.0Common7PackagesDebuggermsdia110.dll"
Visual Studio 2013:
regsvr32 "%ProgramFiles(x86)%Microsoft Visual Studio 12.0Common7PackagesDebuggermsdia120.dll"
For Visual Studio 2015:
regsvr32 "%ProgramFiles(x86)%Microsoft Visual Studio 14.0Common7PackagesDebuggermsdia140.dll"
For Visual Studio 2019 Enterprise:
regsvr32 "%ProgramFiles(x86)%Microsoft Visual Studio2019EnterpriseCommon7PackagesDebuggermsdia140.dll"
[1]位于您的VS安装介质<drive>:Standalone Profiler
下或您的VS安装目录%ProgramFiles(x86)%Microsoft Visual Studio <version>Team ToolsPerformance ToolsSetup
中。
这里张贴的答案很好地解释了问题和解决方案。这是为了给问题如何显示添加上下文,以防将来的读者像我一样遇到Phx.FatalError
异常:
在我的情况下,我仍然使用VS 2017专业版,但一直在使用社区版探索VS 2019。我从使用VS 2017创建的客户端回购中克隆了一个相当大的WPF解决方案。该解决方案在VS 2017中运行良好,使用默认的调试和发布配置。相同的解决方案在VS 2019中使用发布配置构建良好,但抛出Phx.FatalError
异常,试图使用默认调试配置重建。按照我在这里找到的指导,下面的命令(以管理员身份运行)解决了这个问题:
regsvr32 "%ProgramFiles(x86)%Microsoft Visual Studio2019CommunityCommon7PackagesDebuggermsdia140.dll
感谢OP对问题的详细描述和那些提供彻底答案的人。
这个适合我regsvr32 "%ProgramFiles(x86)%Microsoft Visual Studio2019EnterpriseCommon7PackagesDebuggermsdia140.dll"