SonarCloud and ASP.NETCore Azure DevOps Build

This is the error I am getting when trying to use SonarCloud in an ASP.NET Core build. Works fine for .net framework.

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…

D:\a\1\s\IRISDispenseWebsite\IRISDispenseWebsite.csproj

##[error]No analysable projects were found. SonarQube analysis will not be performed. Check the build summary report for details.

No analysable projects were found. SonarQube analysis will not be performed. Check the build summary report for details.

Generation of the sonar-properties file failed. Unable to complete SonarQube analysis.

##[error]21:44:36.974 Post-processing failed. Exit code: 1

21:44:36.974 Post-processing failed. Exit code: 1

##[error]D:\a_tasks\SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255\1.6.0\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe failed with return code: 1

##[section]Finishing: Run Code Analysis

Are you are building a .NET Core project or a solution?

If you are building projects directly, you will need to add a <ProjectGuid> element to the project as described in the docs.
If you are building a solution it isn’t necessary.

Background: old-style MSBuild projects automatically included a unique that the Scanner for MSBuild uses as a stable identifier for the project. Unfortunately, new SDK-style MSBuild projects don’t contain a or any other stable identifier that can be used by third-parties like SonarQube.

We’d like to remove the requirement to add a for SDK-style MSBuild projects, tracked by this ticket.

It is a build and is done via an Azure DevOps Build pipeline on hosted agents. Image below. I am looking at the docs and not understanding how I would modify the .csproj file. I would add these three lines somewhere in the .csproj file?

dotnet begin /k:“project-key”

dotnet build

dotnet end

The .csproj file currently does not have any dotnet commands.

Thanks for your help.

I’ve just edited the my above post to fix a markup issue: the word <ProjectGuid> wasn’t visible, without which my post didn’t make much sense. Sorry about that.

No, the dotnet commands don’t go in the project file.

You have two options:

  1. manually edit your .csproj file to add an element like the following, and check in the updated file:
      <PropertyGroup>
        <ProjectGuid>{1586A33C-14D8-401B-B486-129518846E29}</ProjectGuid>
      </PropertyGroup>

You can just copy and paste this sample exactly as is if you want - I generated the GUID using Visual Studio Tools, Create GUID so it’s not used anywhere else.

or
2) change the build definition to build a .sln file that includes the projects you want to build, rather than building the .csproj file directly.

Thank – either approach seems to work. But now I get typescript errors as shown below. I find some post about this in reference to SonarQube but not to SonarCloud.

ERROR: throw err;

ERROR: ^

ERROR:

ERROR: Error: Cannot find module ‘typescript’

ERROR: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)

ERROR: at Function.Module._load (internal/modules/cjs/loader.js:507:25)

ERROR: at Module.require (internal/modules/cjs/loader.js:637:17)

ERROR: at require (internal/modules/cjs/helpers.js:22:18)

ERROR: at Object. (D:\a\1.sonarqube\out.sonar\mod0\sonarts-bundle\node_modules\tslint\lib\language\walker\blockScopeAwareRuleWalker.js:20:10)

ERROR: at Module._compile (internal/modules/cjs/loader.js:689:30)

ERROR: at Object.Module._extensions…js (internal/modules/cjs/loader.js:700:10)

ERROR: at Module.load (internal/modules/cjs/loader.js:599:32)

ERROR: internal/modules/cjs/loader.js:583

ERROR: throw err;

ERROR: ^

ERROR:

ERROR: Error: Cannot find module ‘typescript’

ERROR: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)

ERROR: at Function.Module._load (internal/modules/cjs/loader.js:507:25)

ERROR: at Module.require (internal/modules/cjs/loader.js:637:17)

ERROR: at require (internal/modules/cjs/helpers.js:22:18)

ERROR: at Object. (D:\a\1.sonarqube\out.sonar\mod0\sonarts-bundle\node_modules\tslint\lib\language\walker\blockScopeAwareRuleWalker.js:20:10)

ERROR: at Module._compile (internal/modules/cjs/loader.js:689:30)

ERROR: at Object.Module._extensions…js (internal/modules/cjs/loader.js:700:10)

ERROR: at Module.load (internal/modules/cjs/loader.js:599:32)

##[error]ERROR: at tryModuleLoad (internal/modules/cjs/loader.js:538:12)

ERROR: at Function.Module._load (internal/modules/cjs/loader.js:530:3)

ERROR: at tryModuleLoad (internal/modules/cjs/loader.js:538:12)

ERROR: at Function.Module._load (internal/modules/cjs/loader.js:530:3)

##[error]ERROR: Failed to find ‘typescript’ module. Please check, NODE_PATH contains location of global ‘typescript’ or install
locally in your project

ERROR: Failed to find ‘typescript’ module. Please check, NODE_PATH contains location of global ‘typescript’ or install locally in
your project

Thank you. Both of t hose options work. But know it is complaining about Typescript. I have seen several posts about this but all around SonarQube not SonarCloud. Error below:

##[error]ERROR: throw err;

ERROR: ^

ERROR:

ERROR: Error: Cannot find module ‘typescript’

ERROR: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)

ERROR: at Function.Module._load (internal/modules/cjs/loader.js:507:25)

ERROR: at Module.require (internal/modules/cjs/loader.js:637:17)

ERROR: at require (internal/modules/cjs/helpers.js:22:18)

ERROR: at Object. (D:\a\1.sonarqube\out.sonar\mod0\sonarts-bundle\node_modules\tslint\lib\language\walker\blockScopeAwareRuleWalker.js:20:10)

ERROR: at Module._compile (internal/modules/cjs/loader.js:689:30)

ERROR: at Object.Module._extensions…js (internal/modules/cjs/loader.js:700:10)

ERROR: at Module.load (internal/modules/cjs/loader.js:599:32)

ERROR: at tryModuleLoad (internal/modules/cjs/loader.js:538:12)

ERROR: at Function.Module._load (internal/modules/cjs/loader.js:530:3)

ERROR: throw err;

ERROR: ^

ERROR:

ERROR: Error: Cannot find module ‘typescript’

ERROR: at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)

ERROR: at Function.Module._load (internal/modules/cjs/loader.js:507:25)

ERROR: at Module.require (internal/modules/cjs/loader.js:637:17)

ERROR: at require (internal/modules/cjs/helpers.js:22:18)

ERROR: at Object. (D:\a\1.sonarqube\out.sonar\mod0\sonarts-bundle\node_modules\tslint\lib\language\walker\blockScopeAwareRuleWalker.js:20:10)

ERROR: at Module._compile (internal/modules/cjs/loader.js:689:30)

ERROR: at Object.Module._extensions…js (internal/modules/cjs/loader.js:700:10)

ERROR: at Module.load (internal/modules/cjs/loader.js:599:32)

ERROR: at tryModuleLoad (internal/modules/cjs/loader.js:538:12)

ERROR: at Function.Module._load (internal/modules/cjs/loader.js:530:3)

##[error]ERROR: Failed to find ‘typescript’ module. Please check, NODE_PATH contains location of global ‘typescript’ or install
locally in your project

ERROR: Failed to find ‘typescript’ module. Please check, NODE_PATH contains location of global ‘typescript’ or install locally in
your project

I

i am getting the same error. i have an ASP.NET MVC project I am building in Azure DevOps and running SonarCloud to analyse. were you able to find the solution ?
please let me know
thanks

.net framework or core?

.net framework. and i am not using any typescript that i know of :slight_smile: