I am a bit confused by your question. You flagged your question as SonarLint and yet you are talking about the scanner (dotnet sonarscanner). Do you need help with analyzing within Visual Studio using SonarLint or running an analysis you push to a SonarQube/SonarCloud instance using the scanner?
C:\Builds\1\MBS.Payments.Forms.Mvc\MBS Payment Forms MVC\Sources\MBS.Payments.Forms.Mvc\MBS.Forms.Payments.Web\MBS.Forms.Payments.Web.csproj (979): The imported project “C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\WebApplications\Microsoft.WebApplication.targets” was not found.
C# analyzer only analyze code when the solution complete.
However, sometimes dotnet sonarscanner failed from above error.
In this case, how can i build my solution and get the result.
dotnet tool install --global dotnet-sonarscanner dotnet sonarscanner begin /k:"project-key" dotnet build dotnet sonarscanner end
commands.
MSBUILD.exe is recently version. (15.8.169+g1ccb72aefa)
However, i got a message like :
C:\Builds\1\MBS.Payments.Forms.Mvc\MBS Payment Forms MVC\Sources\MBS.Payments.Forms.Mvc\MBS.Forms.Payments.Web\MBS.Forms.Payments.Web.csproj (979): The imported project “C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\WebApplications\Microsoft.WebApplication.targets” was not found.
I am sorry but you are not giving me any information about the version, no logs nor any clear problem to work onto. I really don’t see how I can help for now.
The general answer to that is no. Independently of the language, independently of the tool, doing static code analysis on code that does not compile simply does not make sense.
The very first step of your pipeline should be to build the code, and if that fails then fixing the build should be the absolute priority. Other Continuous Integration phases (be it testing, code analysis, other sort of the inspection) strongly depend on the fact that the code is syntactically correct, and compiles.
You don’t need to specify any other options you make the analysis work; you just need to have the correct pre-requisites installed on the build agent to run the Scanner for MSBuild, and they will be present if you have MSBuild 15 installed.
Does the project build correctly using dotnet build if you don’t run any of the sonarscanner steps?
The build error you reported above (“The imported project “C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\WebApplications\Microsoft.WebApplication.targets” was not found”) has nothing to do with SonarQube. Does that targets file exist on your machine?