【问题标题】:VSTS+ SonarQube + DotNetCore 2.0 + Unit TestsVSTS+ SonarQube + DotNetCore 2.0 + 单元测试
【发布时间】:2017-09-29 18:03:35
【问题描述】:

任何人都知道 VS 任务、参数和命令行的正确组合,以使这 4 件事一起发挥得很好?

我可以让 SonarQube 对以下代码进行分析:

  • 用于 MSBuild 的 SonarQube 扫描仪 - 开始分析
  • Visual Studio 构建
  • 用于 MSBuild 的 SonarQube 扫描仪 - 结束分析

但 Visual Studio 测试任务找不到我编写的任何 dotnetcore 2.0 测试(尝试了 MSTest 和 xUnit 框架,以及一大堆参数)

我可以让 dotnet 构建/测试任务正常工作,但我无法让 SonarQube Scanner CLI 执行任何操作,但会出现以

开头的错误
    2017-09-29T17:38:40.6401974Z ##[error]ERROR: Error during SonarQube Scanner execution
2017-09-29T17:38:40.6401974Z ##[error]java.lang.IllegalStateException: Unable to load component class org.sonar.scanner.scan.ProjectLock
2017-09-29T17:38:40.6401974Z ##[error]at org.sonar.core.platform.ComponentContainer$ExtendedDefaultPicoContainer.getComponent(ComponentContainer.java:71)

正在寻找一些关于如何让 VS-Task“Visual Studio 测试”运行 dotnetcore 2.0 构建测试或让 SonarQube CLI 与 VSTS 托管代理配合使用的建议......

更新:第一个答案中的说明使构建工作(感谢您提供有关如何运行 .NET Core 2.0 测试的提示!我在任何地方都找不到该框架密钥... SonarQube 现在正在吹快结束了.. 这是来自 VSTS 的步骤的日志(带调试)

==============================================================================
Task         : SonarQube  Scanner for MSBuild - End Analysis (new)
Description  : Complete the SonarQube analysis of your solution
Version      : 3.0.2
Author       : SonarSource
Help         : Version: 3.0.2. [More Information](http://redirect.sonarsource.com/doc/install-configure-scanner-tfs-ts.html)
==============================================================================
Preparing task execution handler.
Executing the powershell script: d:\a\_tasks\SonarQubeScannerMsBuildEnd_6d01813a-9589-4b15-8491-8164aeb38055\3.0.2\SonarQubePostTest.ps1
PowerShellHandler.Execute - AddCommand(d:\a\_tasks\SonarQubeScannerMsBuildEnd_6d01813a-9589-4b15-8491-8164aeb38055\3.0.2\SonarQubePostTest.ps1)
PowerShellHandler.Execute - Invoke
Starting SonarQube PostBuild Step
Loading module from path 'C:\LR\mms\Services\Mms\Provisioner\TaskAgent\agents\2.123.0\externals\vstshost\Microsoft.TeamFoundation.DistributedTask.Task.Common\Microsoft.TeamFoundation.DistributedTask.Task.Common.psd1'.
Loading module from path 'C:\LR\mms\Services\Mms\Provisioner\TaskAgent\agents\2.123.0\externals\vstshost\Microsoft.TeamFoundation.DistributedTask.Task.Common\Microsoft.TeamFoundation.DistributedTask.Task.Common.psm1'.
Loading module from path 'C:\LR\mms\Services\Mms\Provisioner\TaskAgent\agents\2.123.0\externals\vstshost\Microsoft.TeamFoundation.DistributedTask.Task.LegacySDK.dll'.
Importing cmdlet 'Invoke-ResultPublisher'.
Importing cmdlet 'Publish-TestResults'.
Importing cmdlet 'Add-BuildArtifactLink'.
Importing cmdlet 'Add-BuildAttachment'.
Importing cmdlet 'Convert-String'.
Importing cmdlet 'Copy-BuildArtifact'.
Importing cmdlet 'Get-JavaDevelopmentKitPath'.
Importing cmdlet 'Get-MSBuildLocation'.
Importing cmdlet 'Get-ServiceEndpoint'.
Importing cmdlet 'Get-TaskVariable'.
Importing cmdlet 'Get-TfsClientCredentials'.
Importing cmdlet 'Get-ToolPath'.
Importing cmdlet 'Get-VisualStudioPath'.
Importing cmdlet 'Get-VssConnection'.
Importing cmdlet 'Invoke-Ant'.
Importing cmdlet 'Invoke-BatchScript'.
Importing cmdlet 'Invoke-Maven'.
Importing cmdlet 'Invoke-MSBuild'.
Importing cmdlet 'Invoke-Tool'.
Importing cmdlet 'Invoke-VSTest'.
Importing cmdlet 'Publish-BuildArtifact'.
Importing cmdlet 'Register-XamarinLicense'.
Importing cmdlet 'Unregister-XamarinLicense'.
Importing cmdlet 'Get-X509Certificate'.
Importing cmdlet 'Invoke-DeployTestAgent'.
Importing cmdlet 'Invoke-RunDistributedTests'.
Importing cmdlet 'Invoke-BlockEnvironment'.
Importing cmdlet 'Copy-FilesToAzureBlob'.
Importing cmdlet 'Copy-FilesToTargetMachine'.
Importing cmdlet 'Copy-ToAzureMachines'.
Importing cmdlet 'Remove-Environment'.
Importing cmdlet 'Remove-EnvironmentResources'.
Importing cmdlet 'Complete-EnvironmentOperation'.
Importing cmdlet 'Complete-EnvironmentResourceOperation'.
Importing cmdlet 'Complete-ResourceOperation'.
Importing cmdlet 'Get-Environment'.
Importing cmdlet 'Get-EnvironmentProperty'.
Importing cmdlet 'Get-EnvironmentResources'.
Importing cmdlet 'Get-ExternalIpAddress'.
Importing cmdlet 'Get-ParsedSessionVariables'.
Importing cmdlet 'Get-ProviderData'.
Importing cmdlet 'Invoke-EnvironmentOperation'.
Importing cmdlet 'Invoke-ResourceOperation'.
Importing cmdlet 'Invoke-PsOnRemote'.
Importing cmdlet 'New-OperationLog'.
Importing cmdlet 'Copy-FilesToRemote'.
Importing cmdlet 'Register-Environment'.
Importing cmdlet 'Register-EnvironmentDefinition'.
Importing cmdlet 'Register-Provider'.
Importing cmdlet 'Register-ProviderData'.
Importing cmdlet 'Invoke-UnblockEnvironment'.
Importing cmdlet 'Add-TaskIssue'.
Importing cmdlet 'Complete-Task'.
Importing cmdlet 'Find-Files'.
Importing cmdlet 'Get-LocalizedString'.
Importing cmdlet 'Set-TaskProgress'.
Importing cmdlet 'Set-TaskVariable'.
Importing cmdlet 'Write-TaskDetail'.
Importing cmdlet 'Enable-CodeCoverage'.
Importing cmdlet 'Publish-CodeCoverage'.
Exporting cmdlet 'Add-TaskIssue'.
Exporting cmdlet 'Complete-Task'.
Exporting cmdlet 'Find-Files'.
Exporting cmdlet 'Get-LocalizedString'.
Exporting cmdlet 'Set-TaskProgress'.
Exporting cmdlet 'Set-TaskVariable'.
Exporting cmdlet 'Write-TaskDetail'.
Importing cmdlet 'Add-TaskIssue'.
Importing cmdlet 'Complete-Task'.
Importing cmdlet 'Find-Files'.
Importing cmdlet 'Get-LocalizedString'.
Importing cmdlet 'Set-TaskProgress'.
Importing cmdlet 'Set-TaskVariable'.
Importing cmdlet 'Write-TaskDetail'.
Importing cmdlet 'Invoke-ResultPublisher'.
Importing cmdlet 'Publish-TestResults'.
Importing cmdlet 'Add-BuildArtifactLink'.
Importing cmdlet 'Add-BuildAttachment'.
Importing cmdlet 'Convert-String'.
Importing cmdlet 'Copy-BuildArtifact'.
Importing cmdlet 'Get-JavaDevelopmentKitPath'.
Importing cmdlet 'Get-MSBuildLocation'.
Importing cmdlet 'Get-ServiceEndpoint'.
Importing cmdlet 'Get-TaskVariable'.
Importing cmdlet 'Get-TfsClientCredentials'.
Importing cmdlet 'Get-ToolPath'.
Importing cmdlet 'Get-VisualStudioPath'.
Importing cmdlet 'Get-VssConnection'.
Importing cmdlet 'Invoke-Ant'.
Importing cmdlet 'Invoke-BatchScript'.
Importing cmdlet 'Invoke-Maven'.
Importing cmdlet 'Invoke-MSBuild'.
Importing cmdlet 'Invoke-Tool'.
Importing cmdlet 'Invoke-VSTest'.
Importing cmdlet 'Publish-BuildArtifact'.
Importing cmdlet 'Register-XamarinLicense'.
Importing cmdlet 'Unregister-XamarinLicense'.
Importing cmdlet 'Get-X509Certificate'.
Importing cmdlet 'Invoke-DeployTestAgent'.
Importing cmdlet 'Invoke-RunDistributedTests'.
Importing cmdlet 'Invoke-BlockEnvironment'.
Importing cmdlet 'Copy-FilesToAzureBlob'.
Importing cmdlet 'Copy-FilesToTargetMachine'.
Importing cmdlet 'Copy-ToAzureMachines'.
Importing cmdlet 'Remove-Environment'.
Importing cmdlet 'Remove-EnvironmentResources'.
Importing cmdlet 'Complete-EnvironmentOperation'.
Importing cmdlet 'Complete-EnvironmentResourceOperation'.
Importing cmdlet 'Complete-ResourceOperation'.
Importing cmdlet 'Get-Environment'.
Importing cmdlet 'Get-EnvironmentProperty'.
Importing cmdlet 'Get-EnvironmentResources'.
Importing cmdlet 'Get-ExternalIpAddress'.
Importing cmdlet 'Get-ParsedSessionVariables'.
Importing cmdlet 'Get-ProviderData'.
Importing cmdlet 'Invoke-EnvironmentOperation'.
Importing cmdlet 'Invoke-ResourceOperation'.
Importing cmdlet 'Invoke-PsOnRemote'.
Importing cmdlet 'New-OperationLog'.
Importing cmdlet 'Copy-FilesToRemote'.
Importing cmdlet 'Register-Environment'.
Importing cmdlet 'Register-EnvironmentDefinition'.
Importing cmdlet 'Register-Provider'.
Importing cmdlet 'Register-ProviderData'.
Importing cmdlet 'Invoke-UnblockEnvironment'.
Importing cmdlet 'Add-TaskIssue'.
Importing cmdlet 'Complete-Task'.
Importing cmdlet 'Find-Files'.
Importing cmdlet 'Get-LocalizedString'.
Importing cmdlet 'Set-TaskProgress'.
Importing cmdlet 'Set-TaskVariable'.
Importing cmdlet 'Write-TaskDetail'.
Importing cmdlet 'Enable-CodeCoverage'.
Importing cmdlet 'Publish-CodeCoverage'.
Exporting cmdlet 'Add-BuildArtifactLink'.
Exporting cmdlet 'Add-BuildAttachment'.
Exporting cmdlet 'Convert-String'.
Exporting cmdlet 'Copy-BuildArtifact'.
Exporting cmdlet 'Get-JavaDevelopmentKitPath'.
Exporting cmdlet 'Get-MSBuildLocation'.
Exporting cmdlet 'Get-ServiceEndpoint'.
Exporting cmdlet 'Get-TaskVariable'.
Exporting cmdlet 'Get-TfsClientCredentials'.
Exporting cmdlet 'Get-ToolPath'.
Exporting cmdlet 'Get-VisualStudioPath'.
Exporting cmdlet 'Get-VssConnection'.
Exporting cmdlet 'Invoke-Ant'.
Exporting cmdlet 'Invoke-BatchScript'.
Exporting cmdlet 'Invoke-Maven'.
Exporting cmdlet 'Invoke-MSBuild'.
Exporting cmdlet 'Invoke-Tool'.
Exporting cmdlet 'Invoke-VSTest'.
Exporting cmdlet 'Publish-BuildArtifact'.
Exporting cmdlet 'Register-XamarinLicense'.
Exporting cmdlet 'Unregister-XamarinLicense'.
Exporting cmdlet 'Get-X509Certificate'.
Processed: ##vso[task.setprogress value=-1;]
Invoke - Get-TaskVariable cmdlet
Variable read: MSBuild.SonarQube.Internal.BootstrapperPath = D:\a\_tasks\SonarQubeScannerMsBuildBegin_15b84ca1-b62f-4a2a-a403-89b77a063157\3.0.2\SonarQubeScannerMsBuild\MSBuild.SonarQube.Runner.exe
bootstrapperPath: D:\a\_tasks\SonarQubeScannerMsBuildBegin_15b84ca1-b62f-4a2a-a403-89b77a063157\3.0.2\SonarQubeScannerMsBuild\MSBuild.SonarQube.Runner.exe
Invoke - Get-TaskVariable cmdlet
Variable read: MSBuild.SonarQube.ServerUsername = ********
Invoke - Get-TaskVariable cmdlet
Variable read: MSBuild.SonarQube.ServerPassword =
Invoke - Get-TaskVariable cmdlet
Variable read: MSBuild.SonarQube.DbUsername =
Invoke - Get-TaskVariable cmdlet
Variable read: MSBuild.SonarQube.DbPassword =
Running batch script.
Path: D:\a\_tasks\SonarQubeScannerMsBuildBegin_15b84ca1-b62f-4a2a-a403-89b77a063157\3.0.2\SonarQubeScannerMsBuild\MSBuild.SonarQube.Runner.exe
Arguments: end /d:sonar.login=********
WorkingFolder:
Entering ProcessWrapper.CreateStartInfo
workingFolder = D:\a\_tasks\SonarQubeScannerMsBuildBegin_15b84ca1-b62f-4a2a-a403-89b77a063157\3.0.2\SonarQubeScannerMsBuild
filename = cmd.exe
arguments = /c ""D:\a\_tasks\SonarQubeScannerMsBuildBegin_15b84ca1-b62f-4a2a-a403-89b77a063157\3.0.2\SonarQubeScannerMsBuild\MSBuild.SonarQube.Runner.exe" end /d:sonar.login=********"
Leaving ProcessWrapper.CreateStartInfo
ProcessWrapper.Start - enter
ProcessWrapper.Start - starting process
ProcessWrapper.Start - process started
ProcessWrapper.Start - leave
Unhandled Exception: System.ComponentModel.Win32Exception: The directory name is invalid
at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start()
at SonarQube.Common.ProcessRunner.Execute(ProcessRunnerArguments runnerArgs)
at SonarQube.TeamBuild.Integration.CoverageReportConverter.ConvertBinaryToXml(String converterExeFilePath, String inputBinaryFilePath, String outputXmlFilePath, ILogger logger)
at SonarQube.TeamBuild.Integration.CoverageReportConverter.ConvertToXml(String inputFilePath, String outputFilePath, ILogger logger)
at SonarQube.TeamBuild.Integration.CoverageReportProcessorBase.ProcessBinaryCodeCoverageReport(String binaryCoverageFilePath)
at SonarQube.TeamBuild.Integration.CoverageReportProcessorBase.ProcessCoverageReports()
at SonarQube.TeamBuild.PostProcessor.CoverageReportProcessor.ProcessCoverageReports()
at SonarQube.TeamBuild.PostProcessor.MSBuildPostProcessor.Execute(String[] args, AnalysisConfig config, ITeamBuildSettings settings)
at SonarQube.Bootstrapper.BootstrapperClass.PostProcess()
at SonarQube.Bootstrapper.BootstrapperClass.Execute()
at SonarQube.Bootstrapper.Program.Execute(String[] args, ILogger logger)
at SonarQube.Bootstrapper.Program.Main(String[] args)
at SonarQube.Old.Bootstrapper.Program.Main(String[] args)
SonarQube Scanner for MSBuild 3.0.2
Default properties file was found at D:\a\_tasks\SonarQubeScannerMsBuildBegin_15b84ca1-b62f-4a2a-a403-89b77a063157\3.0.2\SonarQubeScannerMsBuild\SonarQube.Analysis.xml
Loading analysis properties from D:\a\_tasks\SonarQubeScannerMsBuildBegin_15b84ca1-b62f-4a2a-a403-89b77a063157\3.0.2\SonarQubeScannerMsBuild\SonarQube.Analysis.xml
Post-processing started.
16:18:14.455  Fetching code coverage report information from TFS...
16:18:14.456  Attempting to locate a test results (.trx) file...
16:18:14.594  Looking for TRX files in: d:\a\1\TestResults, d:\a\1\s\TestResults
16:18:14.594  Located a test results file: d:\a\1\s\TestResults\buildguest_FACTORYVM-AZ203_2017-10-02_16_18_07.trx
System.Exception: Unexpected exit code received from batch file: -532462766
Processed: ##vso[task.logissue type=error;]System.Exception: Unexpected exit code received from batch file: -532462766
   at Microsoft.TeamFoundation.DistributedTask.Task.Internal.InvokeBatchScriptCmdlet.ProcessRecord()
   at System.Management.Automation.CommandProcessor.ProcessRecord()
The build was not triggered by a Pull Request, not processing code analysis comments
Invoke - Get-TaskVariable cmdlet
Variable read: MSBuild.SonarQube.Internal.IncludeFullReport = true
Invoke - Get-TaskVariable cmdlet
Variable read: MSBuild.SonarQube.Internal.ServerVersion =
Calling InvokeGetRestMethod "/api/server/version"
Invoke - Get-TaskVariable cmdlet
Variable read: MSBuild.SonarQube.HostUrl = http://13.65.82.206/
Invoke - Get-TaskVariable cmdlet
Variable read: MSBuild.SonarQube.ServerUsername = ********
Invoke - Get-TaskVariable cmdlet
Variable read: MSBuild.SonarQube.ServerPassword =
GET http://13.65.82.206/api/server/version with 0-byte payload
received 11-byte response of content type text/plain
Processed: ##vso[task.setvariable variable=MSBuild.SonarQube.Internal.ServerVersion;]6.5.0.27846
The SonarQube server version is 6.5.0.27846
Waiting on the SonarQube server to finish processing in order to determine the quality gate status.
Invoke - Get-TaskVariable cmdlet
Variable read: Agent.BuildDirectory = d:\a\1
Could not find the task details file at d:\a\1\.sonarqube\out\.sonar\report-task.txt
System.Management.Automation.RuntimeException: Cannot determine if the analysis has finished. Possible cause: your SonarQube server version is lower than 5.3 - for more details see https://go.microsoft.com/fwlink/?LinkId=722407 ---> System.Management.Automation.RuntimeException: Cannot determine if the analysis has finished. Possible cause: your SonarQube server version is lower than 5.3 - for more details see https://go.microsoft.com/fwlink/?LinkId=722407
Processed: ##vso[task.logissue type=error;]System.Management.Automation.RuntimeException: Cannot determine if the analysis has finished. Possible cause: your SonarQube server version is lower than 5.3 - for more details see https://go.microsoft.com/fwlink/?LinkId=722407 ---> System.Management.Automation.RuntimeException: Cannot determine if the analysis has finished. Possible cause: your SonarQube server version is lower than 5.3 - for more details see https://go.microsoft.com/fwlink/?LinkId=722407
   --- End of inner exception stack trace ---
   at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
   at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
   at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)
   at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
   at Microsoft.TeamFoundation.DistributedTask.Handlers.LegacyVSTSPowerShellHost.VSTSPowerShellHost.Main(String[] args)
LegacyVSTSPowerShellHost.exe completed with return code: -1.

【问题讨论】:

标签: sonarqube azure-devops asp.net-core-2.0 vstest.console.exe


【解决方案1】:

请参考以下步骤通过 Visual Studio 测试任务运行 DotNet Core Test:

  1. 添加 Visual Studio 测试任务
  2. 在执行选项部分选择具有C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\Extensions\TestPlatform 值的特定位置选项
  3. 在其他控制台选项中指定/framework:".NETCoreApp,Version=v2.0"

【讨论】:

  • 所以它运行了测试!耶!!!!然后 SonarQube 结束分析爆炸了 :-(.. (boo).. 我有它抛出的错误会用新日志更新问题..
  • @JoshHandel 新问题与SonarQube有关,能不能在SonarQube community或者stackoverflow中开新帖?
  • @JoshHandel 用一个简单的项目试试,结果如何?
  • 1) 是的,我确实打开了代码覆盖。我会尝试关闭它。2) 这是一个简单的项目,它是来自 asp.net 核心的一小部分调整生成的 React 模板.. 3) 我可以把它移到 SonarQube 社区。​​span>
  • 它在没有代码覆盖的情况下成功了。这有好有坏。将把它移到社区电子邮件列表,因为现在它是支持代码覆盖的“请求”:)。
猜你喜欢
  • 1970-01-01
  • 2013-12-29
  • 1970-01-01
  • 2010-09-27
  • 1970-01-01
  • 2018-06-03
  • 2016-10-27
  • 1970-01-01
  • 2016-03-22
相关资源
最近更新 更多