I will preface this that my current solution to this is very easy but one I do not want to keep implementing.
Below you will see an image outlining my current build steps. Each of these contain the default settings, with the Prepare analysis on SonarQube
setup to point to my endpoint.
When I run this, again just default settings, I am presented with the following errors
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"
This is because the build step for dotnet core, by default, looks for **/*.csproj
using the linked setting (Parameters.RestoreBuildProjects)
- with the update to the csproj format the project guid is no longer stored in the csproj files. What I suspect is happening is that SonarQube just defaults the guids when it finds nothing defaults to 000...
and then throws this error.
Unlinking the Path to project(s)
parameter and pointing to **/.*.sln
fixed the issue, because now SonarQube can see the project guids (defined the .sln
)
After that long winded explanation I am lead to ask if there is a better way to get SonarQube to recognise dotnet core projects.
I do not want to change the default build task every time I create a project to satisfy SonarQube's requirements.
$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)
}
Building on Artur Mustafin solution, I took that and put it inside a powershell step. I also check for the node incase you have a mix of .net and core
- powershell: |
$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")
if ($node)
{
$node.AppendChild($child)
$doc.Save($path)
}
}
workingDirectory: '$(Build.SourcesDirectory)'
displayName: 'Add Project GUIDs'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With