Running MSBuild from a nant script

317 views
Skip to first unread message

Simona Avornicesei

unread,
Feb 13, 2018, 6:04:35 AM2/13/18
to SonarQube
Hi all,

We have a complex build process done through nant scripts. I'm not familiar to the way msbuild sonar scanner attaches itself to the msbuild process but it does not work with the nant scripts. I'm getting:

The SonarQube MSBuild integration failed: SonarQube was unable to collect the required information about your projects.
Possible causes:
  1. The project has not been built - the project must be built in between the begin and end steps
  2. An unsupported version of MSBuild has been used to build the project. Currently MSBuild 14.0 upwards are supported
  3. The begin, build or end steps have not all been launched from the same folder
Generation of the sonar-properties file failed. Unable to complete SonarQube analysis.

One of our nant targets actually executes MSBuild on a given solution so there should be no difference between running msbuild directly or through nant scripts.

Any insights into the process are highly appreciate .

Thanks,
Simo

Amaury Leve

unread,
Feb 13, 2018, 10:11:16 AM2/13/18
to Simona Avornicesei, SonarQube
Hi Simo,

I haven't made any test with nant but the scanner for msbuild begin step is pushing some targets to the ImportBefore folder of MSBuild so that they are automatically picked up by the build.

Are you using MSBuild 14/15 or a lower version? Are you correctly calling the begin step before the end step? Are you running the build under the Local System account or through another account?

Cheers,
Amaury

--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/bc557931-0bcb-46a3-8f4e-0132f0bc150a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--

Amaury Levé | SonarSource

Software Developer - .Net Team

http://sonarsource.com


Are you using SonarLint in your IDE? 

Simona Avornicesei

unread,
Feb 14, 2018, 5:07:50 AM2/14/18
to SonarQube
Hi Amaury,

We're using MSBuild 14. I changed it to MSBuild 15 but I got the same message.

I raised sonar scanner and MSBuild verbosity and in the log I can see:
Removing the existing directory: c:\Programe\jenkins-data\workspace\some_project\.sonarqube
Creating directory: c:\Programe\jenkins-data\workspace\some_project\.sonarqube
18:58:21.284  18:58:21.277  Loading analysis properties from C:\Programe\sonar-scanner-msbuild-4.0.2.892\SonarQube.Analysis.xml
18:58:21.284  18:58:21.284  sonar.verbose=true was specified - setting the log verbosity to 'Debug'
18:58:21.285  Updating build integration targets...
18:58:21.288  Installed SonarQube.Integration.ImportBefore.targets to C:\Users\CIUser\AppData\Local\Microsoft\MSBuild\15.0\Microsoft.Common.targets\ImportBefore
18:58:21.289  Installed SonarQube.Integration.ImportBefore.targets to C:\Users\CIUser\AppData\Local\Microsoft\MSBuild\14.0\Microsoft.Common.targets\ImportBefore
18:58:21.292  Installed SonarQube.Integration.targets to c:\Programe\jenkins-data\workspace\some_project\.sonarqube\bin\targets
18:58:21.293  Creating config and output folders...
18:58:21.293  Creating directory: c:\Programe\jenkins-data\workspace\some_project\.sonarqube\conf
18:58:21.294  Creating directory: c:\Programe\jenkins-data\workspace\some_project\.sonarqube\out
18:58:21.3  Fetching analysis configuration settings...
18:58:21.302  Downloading from http://localhost:9000/api/server/version...

In MSBuild logs I noticed lots of :
[exec] 18:58:26.066     0>Property reassignment: $(SonarQubeBuildDirectory)="D:\dev\some_project\Source\Generic\src" (previous value: "") at C:\Users\CIUser\AppData\Local\Microsoft\MSBuild\14.0\Microsoft.Common.targets\ImportBefore\SonarQube.Integration.ImportBefore.targets (12,5)

and I also found lots of this:
[exec]                    Target "SonarQubeImportBeforeInfo" skipped, due to false condition; ( $(SonarQubeTempPath) != '' AND $(BuildingInsideVisualStudio) != 'true' ) was evaluated as (  != '' AND  != 'true' ).

Thanks!

Amaury Leve

unread,
Feb 14, 2018, 5:18:46 AM2/14/18
to Simona Avornicesei, SonarQube
Would you mind sharing the complete log of the scanner (using the /d:sonar.verbose=true switch)? Additionally, could you also share the content of the .sonarqube folder?

Cheers,
Amaury

--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Simona Avornicesei

unread,
Feb 14, 2018, 10:44:14 AM2/14/18
to SonarQube
Hi Amaury,

I did some tests because the log file was too big (1,9Gb).
The SQ analysis is successful, even if the MSBuild process is started from a NAnt script, if a single solution file exists (or if a single build is made).

If there are more than one .sln files to be build (and this is common in large projects) then the SQ analysis fails with that error.

Thanks,
Simo

Amaury Leve

unread,
Feb 15, 2018, 10:20:32 AM2/15/18
to Simona Avornicesei, SonarQube
Hi Simona,

I made some tests and you can actually build multiple solutions (this used not to work and I never made any new test with the latest changes we did). So I guess it is linked to some configuration.

I made a test with a small setup:
RootFolder
- All.sln
- Library.sln
- ConsoleApp (simple console app for .net fwk)
- ClassLibrary (simple class library for .net fwk)

And I have used the following commands (against a local SQ on LTS version):
scanner begin /k:multi-sln
msbuild /t:rebuild All.sln
msbuild /t:rebuild Library.sln
scanner end

The analysis was successful, files uploaded, issues and metrics too.

Could you confirm that with such small setup (running the scanner directly) you manage to have a successful analysis? If so could you do the same with a small NAnt script? If both are working this would indicate either a misconfiguration on your side or a context dependent issue.

Cheers,
Amaury


For more options, visit https://groups.google.com/d/optout.

Simona Avornicesei

unread,
Feb 19, 2018, 5:07:41 AM2/19/18
to SonarQube
Hi Amaury,

I tested your proposed setup and it worked fine (from Jenkins, usign a nant build file).

But if any .sln file is not in the root folder, it doesn't get analyzed. You  can test this by changing your setup to the following:
RootFolder (directory)
- All.sln
- ConsoleApp
----Source (directory)
------Library.sln
------ClassLibrary

In this scenario, the Library.sln will not be analyzed.
Let me know if you can reproduce it.

Best,
Simo

Amaury Leve

unread,
Feb 21, 2018, 5:13:00 AM2/21/18
to Simona Avornicesei, SonarQube
Hi Simona,

I have tried your suggestion and a couple of others but I can see the files in SonarQube with the issues and metrics. Would you mind sharing a zip (or a github project) reproducing the issue?

Also could you let me know the version of SonarC# you are using? This might be the difference between our tests,

Cheers,
Amaury 


For more options, visit https://groups.google.com/d/optout.

Simona Avornicesei

unread,
Mar 2, 2018, 7:22:45 AM3/2/18
to SonarQube
Hi Amaury,

I've uploaded the test project I used in GitHub.

In the README you can also find the version of SQ, MSBuild, sonar-msbuild plugin and SQ C# plugin, along with the command line to build and analyze.

Let me know if you can reproduce the issue.

Best,
Simo
Reply all
Reply to author
Forward
0 new messages