codeql icon indicating copy to clipboard operation
codeql copied to clipboard

CodeQL failed to compile C# program based on Unity

Open wwwjwww opened this issue 11 months ago • 1 comments

I want to try codeQL on the Unity program of its C# code in its assets folder. I could execute "msbuild xxx.sln" in my local environment. However, when I try to build codeql database using: codeql database create trial-database --language=csharp --command="msbuild xxx.sln", it reports: CodeQL detected code written in C# but could not process any of it. This can occur if the specified build commands failed to compile or process any code.

  • Confirm that there is some source code for the specified language in the project.
  • For codebases written in Go, JavaScript, TypeScript, and Python, do not specify an explicit --command.
  • For other languages, the --command must specify a "clean" build which compiles all the source code files without reusing existing build artefacts.

Is it because codeql doesn't support analyzing C# code in a Unity program?

wwwjwww avatar Mar 05 '24 08:03 wwwjwww

Hi @wwwjwww 👋🏻

We should be able to analyse the C# code if it gets processed by the C# compiler.

The first thing to check here is the following. Since you are using a custom build command (--command="msbuild xxx.sln") and as the message you received suggests in the last bullet point, your build command must ensure that the code is built from scratch and doesn't inadvertently use previously built artifacts. See the documentation at https://docs.github.com/en/code-security/codeql-cli/getting-started-with-the-codeql-cli/preparing-your-code-for-codeql-analysis#creating-databases-for-compiled-languages for further guidance here.

If that still doesn't work, do you have a link to the repository that you are trying to analyse or any build logs that you can share?

mbg avatar Mar 06 '24 17:03 mbg

I will go ahead and close this issue now since there hasn't been an update in a month, but feel free to let us know if you are still having problems with this!

mbg avatar Apr 04 '24 15:04 mbg