本文主要介绍.NET Core项目时报ProjectGuid无效的问题解决方法,错误信息:WARNING: The following projects do not have a valid ProjectGuid and were not built using a valid solution (.sln) thus will be skipped from analysis。

1、手动添加<ProjectGuid>

.NET Core项目()(.csproj)中没有<ProjectGuid>...</ProjectGuid>来指定默认的模板,需要手动来添加。编辑修改.csproj文件如下:

<PropertyGroup>
<!-- other properties here -->
<!-- SonarQube needs this -->
<ProjectGuid>{E2CEBBAF-6DF7-41E9-815D-9AD4CF90C844}</ProjectGuid>

确保将项目正确的GUID放在<ProjectGuid>...</ProjectGuid>

2、在PowerShell中添加

下面是在PowerShell中添加缺少的XML元素:

$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)
}


推荐文档