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

Analysis fails with .NET 7 #1333

Closed
cristian-ambrosini-sonarsource opened this issue Oct 10, 2022 · 2 comments
Closed

Analysis fails with .NET 7 #1333

cristian-ambrosini-sonarsource opened this issue Oct 10, 2022 · 2 comments
Milestone

Comments

@cristian-ambrosini-sonarsource
Copy link
Contributor

cristian-ambrosini-sonarsource commented Oct 10, 2022

Description

During the analysis of a .NET project with SonarScanner, after building the project using .NET 7 through the dotnet CLI, the end step fails with the error:

16:10:24.487  Generating SonarQube project properties file to  .\Projects\ProjectRoot\.sonarqube\out\sonar-project.properties
16:10:24.501  Generation of the sonar-properties file failed. Unable to complete the analysis.

Additionally in build step logs:

Sonar: (Project.Net5.csproj) The analysis targets file not found: .\Projects\AnotherProject\.sonarqube\bin\targets\SonarQube.Integration.targets

The dotnet build cannot correctly detect the base path of the project because the MSBuildStartupDirectory property has the wrong value. We use MSBuildStartupDirectory to detect the root folder of the project and create there the .sonarqube directory.
(see here where MSBuildStartupDirectory is used in the sonar-scanner-msbuild repo).

Repro steps

Clone https://github.com/mary-georgiou-sonarsource/scanner-net7-repro

cd Project1
dotnet sonarscanner begin /k:"project-key" /d:sonar.login="token"
dotnet build
dotnet sonarscanner end /d:sonar.login="token"

In the case, this succeeds it means that the MSBuildStartupDirectory was not set yet - so now it should be set to .\Project1.
So to reproduce now you should run also:

cd ..
cd Project2
dotnet sonarscanner begin /k:"project-key" /d:sonar.login="token"
dotnet build
dotnet sonarscanner end /d:sonar.login="token"

If you want to see the values of the MSBuildStartupDirectory in the two projects:

cd Project1
dotnet build /target:DisplayMessages
cd ../Project2
dotnet build /target:DisplayMessages

Expected behavior

SonarScanner.MSBuild.exe end should call sonar-scanner.bat and send the data.

Actual behavior

Analysis fails.

Known workarounds

Build the project through MSBuild with the command:

msbuild /t:rebuild -v:d

This will compile, allowing the end step to finish the analysis.

@csaba-sagi-sonarsource csaba-sagi-sonarsource added this to the 5.9.0 milestone Oct 10, 2022
@mary-georgiou-sonarsource mary-georgiou-sonarsource changed the title Running build command with .Net 7 cause SonarScanner to fail the analysis Analysis fails with .NET 7 Oct 26, 2022
@mary-georgiou-sonarsource
Copy link
Contributor

According to the discussion in this issue, the problem should be solved after the release of .NET 7.
Meanwhile, a workaround to use the dotnet build CLI command is to set DOTNET_CLI_DO_NOT_USE_MSBUILD_SERVER=1 in the environment variables.

@mary-georgiou-sonarsource
Copy link
Contributor

After .NET 7 7.0.100 this issue has been fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants