.net-core - SonarQube dotnet 核心 : how to avoid the duplicate guid error without altering the default build task

标签 .net-core sonarqube azure-devops azure-pipelines

我先说我目前对此的解决方案非常简单,但我不想继续实现。

问题

您将在下面看到一张概述我当前构建步骤的图像。其中每个都包含默认设置,带有 Prepare analysis on SonarQube设置指向我的端点。

当我运行它时,再次只是默认设置,出现以下错误

WARNING: Duplicate ProjectGuid: "00000000-0000-0000-0000-000000000000". The project will not be analyzed by SonarQube. Project file: "D:\a\1\s\API.Tests.csproj"
WARNING: Duplicate ProjectGuid: "00000000-0000-0000-0000-000000000000". The project will not be analyzed by SonarQube. Project file: "D:\a\1\s\API.csproj"

这是因为 dotnet core 的构建步骤默认查找 **/*.csproj使用链接设置 (Parameters.RestoreBuildProjects) - 随着 csproj 格式的更新,项目 guid 不再存储在 csproj 文件中。我怀疑正在发生的是 SonarQube 只是在没有发现任何默认值时默认 guid 000...然后抛出这个错误。

修复

取消链接 Path to project(s)参数并指向 **/.*.sln修复了这个问题,因为现在 SonarQube 可以看到项目 guids(定义了 .sln)

问题,终于

在冗长的解释之后,我问是否有更好的方法让 SonarQube 识别 dotnet 核心项目。

我不想在每次创建项目时更改默认构建任务以满足 SonarQube 的要求。

Sonarqube with a dotnet core project

最佳答案

$paths = Get-ChildItem -include *.csproj -Recurse
foreach($pathobject in $paths) 
{
    $path = $pathobject.fullname
    $doc = New-Object System.Xml.XmlDocument
    $doc.Load($path)
    $child = $doc.CreateElement("ProjectGuid")
    $child.InnerText = [guid]::NewGuid().ToString().ToUpper()
    $node = $doc.SelectSingleNode("//Project/PropertyGroup")
    $node.AppendChild($child)
    $doc.Save($path)
}

关于.net-core - SonarQube dotnet 核心 : how to avoid the duplicate guid error without altering the default build task,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51230892/

相关文章:

c# - 当前 .Net SDK 不支持以 .Net Core 2.2 为目标 以 .Net Core 2.1 或更低版本为目标

c# - ServiceStack JSON 在 dotnet 核心上序列化为小写?

c# - 无法开始调试。启动项目无法启动

git - Visual Studio Team Explorer + VS 在线同步错误

git - 如何阻止用户推送所有标签 (git push --tags)?

c# - 如何在 Blazor 服务器端的 CircuitHandler 中调用方法?

php - 多团队整体应用程序开发中的 SonarQube 使用案例

c# - 不允许 Sonarqube.project.properties 文件

sonarqube - 使用 SonarQube 5.2 构建 Breaker 插件

.net-core - Azure Devops 管道 - 使用 DotNetCoreCLI@2 指定目标框架