I'm programmatically able to call MsBuild.SonarQube.Runner begin
(by making calls into referenced assemblies directly), Microsoft.Build.BuildManager.Build
and MsBuild.SonarQube.Runner end
. But, the issue is Runner end
reports that No ProjectInfo.xml files were found. Possible causes: you specified an invalid build configuration or the custom MSBuild analysis targets were not imported.
Is MsBuild.SonarQube.Runner tightly coupled with MSBuild.exe commandline tool? I'm not clear on how exactly the runner gets details of build events.
Is it even possible what I'm trying to achieve?
I must add that runner begin
and build are succeeding. bin\Debug folder is populated with built binaries.
You can build projects programmatically using the MSBuild API and have SonarQube analysis performed as part of the build. The SonarQube Scanner for MSBuild is not tightly coupled to the MSBuild.exe command line.
ImportBefore functionality is implemented in the standard Microsoft targets files. For example, have a look at %ProgramFiles(x86)%\MSBuild\14.0\Bin\Microsoft.Common.CurrentVersion.targets which contains the following line:
<Import Project="$(MSBuildUserExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.targets\ImportBefore\*" Condition="'$(ImportUserLocationsByWildcardBeforeMicrosoftCommonTargets)' == 'true' and exists('$(MSBuildUserExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.targets\ImportBefore')"/>
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.targets\ImportBefore\*" Condition="'$(ImportByWildcardBeforeMicrosoftCommonTargets)' == 'true' and exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.targets\ImportBefore')"/>
All these lines do is import any target files that exist in well-known locations. This mechanism can be used to automatically include targets into every project, without having to explicitly include the targets file in the project. This mechanism is independent of MSBuild.exe. However, it does matter which version of standard targets files you are using: the v4.0 standard target files don't include this mechanism, but the v12.0 and v14.0 versions do.
The simplest way to trigger a build programmatically is to use MSBuild v12.0 or v14.0 and rely on the standard ImportBefore behaviour.
Alternatively, you could do one of the following:
manually edit your project files to explicitly include the required SonarQube targets, or
programmatically import the required SonarQube targets using the MSBuild API before triggering the build (by adding an "Item" of type "Import" with the include parameter pointing to the location of the targets file to import). The SonarQube Scanner for MSBuild integration tests use this approach.