Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MSBuild 15 on macOS with Mono does not work with SonarQube MSBuild Scanner #1956

Closed
nextmunich opened this issue Apr 7, 2017 · 7 comments
Closed
Labels

Comments

@nextmunich
Copy link

I'm not sure whether this is, in fact, a bug in MSBuild but I don't seem to find any other place to ask for help (my StackOverflow question did not yield any results).

When trying to use SonarQube MSBuild Scanner with MSBuild 15 on macOS with a Xamarin solution, the MSBuild build does not seem to produce the output expected by the scanner.

I can successfully run the scanner's "begin" using mono like so:

mono sonar-scanner-msbuild-2/SonarQube.Scanner.MSBuild.exe begin /k:"KEY"

The command creates the following files:

.sonarqube/conf/SonarQubeAnalysisConfig.xml
.sonarqube/conf/SonarQubeRoslyn-cs.ruleset
.sonarqube/conf/cs/SonarLint.xml

I'm running MSBuild using:

msbuild /t:Rebuild

Now the build starts correctly but eventually terminates with two errors:

The scanner is invoked to end the scan process like so:

mono sonar-scanner-msbuild-2/SonarQube.Scanner.MSBuild.exe end

This outputs the following information:

SonarQube Scanner for MSBuild 2.2
Default properties file was found at sonar-scanner-msbuild-2/SonarQube.Analysis.xml
Loading analysis properties from sonar-scanner-msbuild-2/SonarQube.Analysis.xml
Post-processing started.
SonarQube Scanner for MSBuild 2.2
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 12.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.
23:25:26.863  Creating a summary markdown file...
23:25:26.868  Post-processing failed. Exit code: 1

What's missing in MSBuild on macOS to make this work?

Moreover, I stumbled upon information somewhere that indicated that it might be required to add an import for the scanner's targets to the .csproj files in the solution:

<Import Project="sonar-scanner-msbuild-2/Targets/SonarQube.Integration.ImportBefore.targets" />

But when I do this and run the build, MSBuild complains with the following:

Build FAILED.

"SomeProject/SomeProject.sln" (Rebuild target) (1) ->
"SomeProject/SomeProject.Core/SomeProject.Core.csproj" (Rebuild target) (2) ->
(CoreCompile target) -> 
  CSC : error CS2001: Source file /additionalfile:SomeProject/.sonarqube/conf/SomeProject.Core_AnyCPU_Debug_0473/ProjectOutFolderPath.txt' could not be found [SomeProject/SomeProject.Core/SomeProject.Core.csproj]

    0 Warning(s)
    1 Error(s)

Checking the file system, the file does actually exist. Why would MSBuild not be able to find / access this file? Is there anything that can be done about it?

Any feedback is greatly appreciated!

@radical
Copy link
Member

radical commented Apr 8, 2017

Could you share a gist of the diagnostic build log? Collect it with $ msbuild /v:diag /t:Rebuild 2>&1 | tee build.log .

And which version of mono are you using? mono --version

@nextmunich
Copy link
Author

Sure, no problem at all!

I've created a clean solution via Xamarin with a PCL, an iOS and an Android project inside of it. I ran SonarQube's begin on the project which created the .sonarqube folder in my solution directory.

Then I execute $ msbuild /v:diag /t:Rebuild 2>&1 | tee build.log, the log output can be found in the following Gist:

https://gist.github.com/nextmunich/aa23c2a11785390d2272b5e4f3404305

I've also tried to build with the added Import line in the PCL project (I'm unsure whether this is necessary or not, I think I was experimenting or came across this in some other thread). The Gist for the build output which I receive when the import is included can be found in the following Gist:

https://gist.github.com/nextmunich/c1ab0b01aa58d202abf5eb0785f78b52

The mono version is:

Mono JIT compiler version 4.8.0 (mono-4.8.0-branch/8f6d0f6 Thu Mar  9 11:59:17 EST 2017)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
	TLS:           normal
	SIGSEGV:       altstack
	Notification:  kqueue
	Architecture:  x86
	Disabled:      none
	Misc:          softdebug 
	LLVM:          yes(3.6.0svn-mono-master/8b1520c)
	GC:            sgen

@radical
Copy link
Member

radical commented Apr 8, 2017

I think the Import is required because without that in the first log there is nothing about SonarQube. The second one is failing because /additionalfile: parameter is not supported by mcs. You could try building with csc by passing /p:CscToolExe=csc.exe /p:CscToolPath=/Library/Frameworks/Mono.framework/Versions/4.8.0/lib/mono/msbuild/15.0/bin/Roslyn/ to msbuild.

With the upcoming version of Mono, csc will be the default compiler.

@nextmunich
Copy link
Author

@radical thanks for your help - that does, indeed, work for me! Now I'm running into issues with the scanner itself but that should not be related to MSBuild in any way.

@chiraggb
Copy link

when i run mono /var/jenkins_home/tools/sonar-scanner-msbuild/SonarQube.Scanner.MSBuild.exe end
i am getting error
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 12.0 upwards are supported
  3. The begin, build or end steps have not all been launched from the same folder
    Writing processing summary to /var/jenkins_home/workspace/CI_HPEFS.AXI.UAG.API/UAG/HPFS.Gateway.UAGFulfillment/.sonarqube/out/ProjectInfo.log
    Generation of the sonar-properties file failed. Unable to complete SonarQube analysis.

@chiraggb
Copy link

i am using MSBuild 14.1

@radical
Copy link
Member

radical commented Apr 14, 2017

@chiraggb Same as - #1956 (comment) . You should update to the latest Mono also, which will have a newer msbuild too. Also, I can't re-open the issue, so could you create a new one?

@AR-May AR-May added the triaged label Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants