1

We added SonarCloud to the build pipeline of a large solution. Only one project in our solution is analyzed but we see this warning

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...
D:\a\1\s\MyApp\MyApp.Entities\MyApp.Entities.csproj, D:\a\1\s\MyApp\MyApp.Core\MyApp.Core.csproj, D:\a\1\s\MyApp\MyApp.Mobile.Backend\MyApp.Mobile.Backend.csproj, D:\a\1\s\MyApp\MyApp.Entities\MyApp.Entities.csproj, D:\a\1\s\MyApp\MyApp.Core\MyApp.Core.csproj, D:\a\1\s\MyApp\MyApp.Web\MyApp.Web.csproj
WARNING: Duplicate ProjectGuid: "00000000-0000-0000-0000-000000000000". The project will not be analyzed by SonarQube. Project file: "D:\a\1\s\MyApp\MyApp.Entities\MyApp.Entities.csproj"
WARNING: Duplicate ProjectGuid: "00000000-0000-0000-0000-000000000000". The project will not be analyzed by SonarQube. Project file: "D:\a\1\s\MyApp\MyApp.Core\MyApp.Core.csproj"
WARNING: Duplicate ProjectGuid: "00000000-0000-0000-0000-000000000000". The project will not be analyzed by SonarQube. Project file: "D:\a\1\s\MyApp\MyApp.Mobile.Backend\MyApp.Mobile.Backend.csproj"
WARNING: Duplicate ProjectGuid: "00000000-0000-0000-0000-000000000000". The project will not be analyzed by SonarQube. Project file: "D:\a\1\s\MyApp\MyApp.Web\MyApp.Web.csproj"

The project structure is

enter image description here

Mathias Rönnlund
  • 4,078
  • 7
  • 43
  • 96
  • Do you build using a solution or building the list of projects? – Amaury Levé Apr 27 '18 at 07:21
  • We are building two projects in the solution **/MyApp.Web.csproj **/MyApp.Mobile.Backend.csproj – Mathias Rönnlund Apr 27 '18 at 10:35
  • Could the problem be that e.g. MyApp.Entities is referenced by MyApp.Web both through MyApp.Core and directly? – Mathias Rönnlund Apr 27 '18 at 11:16
  • 2
    The Sonar build tasks need a unique stable id for each MSBuild project, and they use the property for this. However, the new MSBuild 15 format used by NETCore projects does not specify a ProjectGuid, so if you are building new-style .csproj files directly the ProjectGuid will be empty. If you are building a .sln that references NETCore projects then the Sonar tasks will use the GUIDs from the .sln as identifiers for the project. However, I'd expect the error message to say "missing guid" rather than "duplicate 0000 etc". Which version of the Scanner for MSBuild are you using? – duncanp Apr 30 '18 at 16:49
  • @duncanp How does building with a sln file help the Sonar scanner to find the guids in the proper file? For example in my build I run "dotnet build TheSolution.sln" which is sandwiched between the VSTS "Prepare analysis on SonarQube" and the "Run Code Analysis" task? How can I tell the scanner to use the sln for Project Guids? – Travis Jun 20 '18 at 21:00
  • You don't need to. The scanner injects targets into the build, so as each .csproj is built the scanner targets are called and they collect data about the project. MSBuild passes in information about the solution file, so the scanner can look in the sln file to work out which guid to use for the project. – duncanp Jun 21 '18 at 09:49

1 Answers1

1

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
     <ProjectGuid>{fc2f0da6-ddfe-67b2-8dae-eb292f55436f}</ProjectGuid>
  </PropertyGroup>

You need to do the following: --> Add tag or label 'ProjectGuid ' to your files with .csproj extension with a different Guid for each file.

VIEW CODE (this code is not executable)

--> And for generate Guid, you can do it from https://www.guidgenerator.com/online-guid-generator.aspx

Community
  • 1
  • 1
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Zain Arshad Apr 17 '19 at 21:27