sonarqube - VSTS+ SonarQube + DotNetCore 2.0 + 单元测试

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

有人知道 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 Test”运行 dotnetcore 2.0 内置测试或让 SonarQube CLI 与 VSTS 托管代理良好配合的建议...

更新:第一个答案中的说明使构建正常工作(感谢您提供有关如何运行 .NET Core 2.0 测试的提示!我在任何地方都找不到该框架 key ...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.

最佳答案

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

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

关于sonarqube - VSTS+ SonarQube + DotNetCore 2.0 + 单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46494603/

相关文章:

c# - MS Graph - 401 未经授权,看似具有适当的 token 和访问权限

c# - 从 Controller 获取 JsonOptions

c# - UPDATE 语句与 EF Core 中的 FOREIGN KEY 约束冲突

java - 更改 sonar.java.binaries 属性中的行为

java - 我们怎么能忽略Java中的一些SonarQube规则呢?

java - SonarQube:请提供您项目的已编译类

java - 为什么鱿鱼:S1166 not accept exception messages only when logging caught exceptions?

docker - 正确保持docker VSTS/Azure Devops build代理干净但已缓存

azure - 如何通过API在Azure Devops中添加团队成员? Groups API 也不起作用

azure-devops - 如何获取 Azure DevOps 中正在进行的管道的构建 ID