我先说我目前对此的解决方案非常简单,但我不想继续实现。
问题
您将在下面看到一张概述我当前构建步骤的图像。其中每个都包含默认设置,带有 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 的要求。
最佳答案
$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/