For case 1, have you check the error message ? You may have to check on your side of you have some exclusions / inclusions set to be sure that they do not overlap each other.
For case 2, you need to put the Prepare analysis configure task BEFORE the build solution, in order for the targets to be installed and detected in the subsequent build.
Log:
2021-03-12T09:25:39.7503876Z ##[section]Starting: Run Code Analysis
2021-03-12T09:26:03.5360236Z ==============================================================================
2021-03-12T09:26:03.5360556Z Task : Run Code Analysis
2021-03-12T09:26:03.5360828Z Description : Run scanner and upload the results to the SonarQube server.
2021-03-12T09:26:03.5361091Z Version : 4.18.0
2021-03-12T09:26:03.5361435Z Author : sonarsource
2021-03-12T09:26:03.5362147Z Help : Version: 4.18.0. This task is not needed for Maven and Gradle projects since the scanner should be run as part of the build.
More Information
2021-03-12T09:26:03.5362674Z ==============================================================================
2021-03-12T09:26:04.8673608Z [command]“C:\SonarAgent\vsts-agent-win-x64-2.181.2 (1)_work_tasks\SonarQubePrepare_15b84ca1-b62f-4a2a-a403-89b77a063157\4.18.0\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe” end
2021-03-12T09:26:04.8678712Z SonarScanner for MSBuild 5.1
2021-03-12T09:26:04.8679294Z Using the .NET Framework version of the Scanner for MSBuild
2021-03-12T09:26:04.8679680Z Post-processing started.
2021-03-12T09:26:04.8680194Z 09:26:04.646 09:26:04.646 WARNING: The following projects do not have a valid ProjectGuid and were not built using a valid solution (.sln) thus will be skipped from analysis…
2021-03-12T09:26:04.8680921Z C:\SonarAgent\vsts-agent-win-x64-2.181.2 (1)_work\10\s\SocialGoal.Web.csproj
2021-03-12T09:26:04.8682105Z ##[error]09:26:04.694 No analysable projects were found. SonarQube analysis will not be performed. Check the build summary report for details.
2021-03-12T09:26:04.8784769Z 09:26:04.694 No analysable projects were found. SonarQube analysis will not be performed. Check the build summary report for details.
2021-03-12T09:26:04.8786099Z 09:26:04.695 Generation of the sonar-properties file failed. Unable to complete the analysis.
2021-03-12T09:26:04.8787903Z ##[error]09:26:04.718 Post-processing failed. Exit code: 1
2021-03-12T09:26:04.8846619Z 09:26:04.718 Post-processing failed. Exit code: 1
2021-03-12T09:26:04.8874688Z ##[error]The process ‘C:\SonarAgent\vsts-agent-win-x64-2.181.2 (1)_work_tasks\SonarQubePrepare_15b84ca1-b62f-4a2a-a403-89b77a063157\4.18.0\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe’ failed with exit code 1
2021-03-12T09:26:04.8895826Z ##[section]Finishing: Run Code Analysis.