Sonar and TFS 2013 : No ProjectInfo.xml files were found

萝らか妹 提交于 2019-12-01 13:30:23

Troubleshooting issues with the MSBuild.Runner v0.9

The following information is provided to help troubleshooting issues with version 0.9 of the MSBuild.Runner. The behaviour may change in later versions.

Most serious configuration issues will result in warnings or errors that will appear on the Build Summary page. In cases in which there are no errors or warnings reported, check the TFS TeamBuild diagnostic output (click on "Diagnostics" link at the top of the build summary report in Visual Studio). Both the pre- and post-processor steps log quite a lot of information to help diagnose issues.

1. Check the SonarQube Analysis Summary section appears in the Build Summary Report

The section should look like this:

SonarQube Analysis Summary
Analysis failed for SonarQube project "Simple console app", version 1.0
  Product projects: 4, test projects: 2
  Invalid projects: 0, skipped projects: 0, excluded projects: 0

If the section does not appear on the build summary page then there are configuration issues with the build agent, build definition, or both. Read the steps below to diagnose these further.

1.1 Check the number of projects that are reported in the summary

If no projects were found then it suggests that the integration targets are not being imported and used during the build.

If all of the projects are marked as invalid, it is likely that you are building more than one configuration e.g. [release or debug] | [x86 or x64]. You should also get an error saying no ProjectInfo.xml files could be found.

You can only analyse one configuration at a time. If you want to analyze both release and debug builds, then you will need to create a separate build definition for each, using different SonarQube project ids.

The diagnostic log will contain more infomation about why a project was invalid, which is normally because the project doesn't have a guid, or the guid is not unique. The normal reason for a non-unique guid is that you are building multiple configurations e.g. release and debug.

2. Check that the pre-build step is being executed

The diagnostic output should contain output similar to the following:

Run optional script before MSBuild

C:\SonarQube\bin\SonarQube.MSBuild.Runner.exe /key:MyProject /name:"My Project" /version:1.0

Pre-processing (3 arguments passed)

If it doesn't, check that the you are correctly calling SonarQube.MSBuild.Runner.exe in the "Pre-build script" step in the build definition. An easy mistake is to put the script parameters in the wrong box by setting the "Post-build" properties instead (unhelpfully, the Post-build fields in the UI appear before the Pre-build fields).

2. Check that the post-build step is being executed

The diagnostic output should contain output similar to the following:

Run optional script after Test Runner

C:\SonarQube\bin\SonarQube.MSBuild.Runner.exe

Post-processing (no arguments passed)

If it doesn't, check that the you are correctly calling SonarQube.MSBuild.Runner.exe in the "Post-test script" step in the build definition.

3. Check the rest of the diagnostic log

If the pre- and post- build steps are being executed correctly, check the rest of the diagnostic output for any clues as to what isn't working. Pay particular attention to messages from the pre- and post-processor about the directories and files they are writing to.

4. Check the files that have been created on the build agent

The analysis process creates temporary files under the build directory under a folder called SQTemp in v0.9. Examining the contents of the folders can help determine the stage at which the analysis is failing.

The expected folders are as follows:

  • bin: this folder contains the analysis targets and binaries. It is created by the SonarQube.MSBuild.Runner.exe which downloads the files from the SonarQube server. If this folder does not exist or is empty then the analysis failed at a very early stage and there should warnings or errors. Check that the C# plugin v4 is installed correctly on the SonarQube server, and that the SonarQube has been restarted since the plugin was installed.

  • conf: this folder is created during pre-processing and contains the settings downloaded from the SonarQube server. If there are any FxCop rules active in the SonarQube the folder should contain an FxCop ruleset.

  • out: this folder is populated during the MSBuild phase. It should contain one folder per project being built. It will also contain the generated sonar-project.properties file that is passed to the sonar-runner. If the folder is empty then it is possible the SonarQube.Integration.targets are not being imported correctly. The error message "No ProjectInfo.xml files were found" will normally appear in this case. The ProjectInfo.xml files are generated by the target "WriteSonarQubeData" in the SonarQube.Integration.targets, so the next thing to check is that SonarQube.Integration.targets are being imported correctly and the expected targets are being executed.

5. Checking the SonarQube.Integration.targets are imported and called

Firstly, double-check the installation of the SonarQube.Integration.ImportBefore.targets file:

  • check it is in the correct folder for the version of MSBuild you are using i.e. %ProgramFiles(x86)%\MSBuild\[12.0 or 14.0]\Microsoft.Common.Targets\ImportBefore
  • check for typos in the folder name "ImportBefore" (should be singular, not plural) (Thanks to Richard from BlackMarble for this tip).

If the targets are installed correctly then you will need to increase the verbosity of the MSBuild logging to diagnostic and build again so you can check the detailed MSBuild output. Unfortunately, there doesn't seem to be a simple way to increase the verbosity of the MSBuild logs when running under TeamBuild 2013. You can produce an additional log file with more detail, but you will need access to the build agent machine to pick up the log file.

To create an MSBuild log with more detailed info:

  • select "Queue New Build" from the BUILD menu in Visual Studio
  • click on the "Parameters" tab.
  • Expand the "2. Build" section and the "5. Advanced" sections
  • Set the "MSBuild arguments" property to the following: /m:1 /fl2 /flp2:"verbosity=diagnostic" The "/m:1" tells MSBuild not to build in parallel which can make the log easier to read. The other two parameters tell MSBuild to log to a file. See the MSBuild command line help for more info.
  • Click "Queue" and wait for the build to finish.
  • Find and open the log on the build agent. It should be called msbuild2.log and be under the source directory for your build definition.

If the SonarQube.Intergration.ImportBefore.targets are being executed, there will be a log entry saying the "SonarQubeImportBeforeInfo" target was executed. There should be some output message saying whether the file "SonarQube.Integration.targets" was located or not.

The ProjectInfo.xml files are written by the target "WriteSonarQubeProjectData". The log should show that this target has been executed, and the "WriteProjectInfoFile" task has executed. If not, the log should give an idea of why the targets were skipped.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!