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

.NET MAUI projects supported? #18481

Open
dhindrik opened this issue Jan 13, 2025 · 4 comments
Open

.NET MAUI projects supported? #18481

dhindrik opened this issue Jan 13, 2025 · 4 comments
Labels
question Further information is requested

Comments

@dhindrik
Copy link

We have used CodeQL for our .NET MAUI app for a while. But last time it was running successful was 13th November. Since than it failed, even if we still was on .NET 8.

We get a lot of errors like this:
{APP_PATH}\obj\Release\net9.0-windows10.0.19041.0\win10-x64\generated\Microsoft.Maui.Controls.SourceGen\Microsoft.Maui.Controls.SourceGen.CodeBehindGenerator\App.xaml.sg.cs'.'

I guess it is because of code generation of XAML.

So is .NET MAUI projects supported? If I look at the docs I cannot see .NET MAUI there. I a look back and I can also see that we never had any issues reported even if the run succeed.

Image
Image from, https://codeql.github.com/docs/codeql-overview/supported-languages-and-frameworks/

We have an requirement to run CodeQL on all our repositories, but if it is not supported for .NET MAUI projects we need to explain it for the managers and looking for options.

@dhindrik dhindrik added the question Further information is requested label Jan 13, 2025
@tamasvajk
Copy link
Contributor

I've tried the following to reproduce your issue:

dotnet workload install maui
dotnet new maui --name maui1   
cd maui1
dotnet build -f net9.0-maccatalyst /t:rebuild

The above built the application successfully, so then I tried the below, which created a database:

codeql database create DB1 --language=csharp --command="dotnet build -f net9.0-maccatalyst /t:rebuild"

Could you give a bit more context on the errors that you see? Would you be able to provide a minimal repro of your issue?

@dhindrik
Copy link
Author

Here is an workflow that are more or less the same as we have for the real app, /~https://github.com/dhindrik/MauiCodeQL/actions/runs/12794061568

@tamasvajk
Copy link
Contributor

Thank you for the repro. This is just a progress report, not a solution yet.

I looked into the debug logs of the job, and found that an exception is thrown here:

 Unhandled exception: System.IO.DirectoryNotFoundException: Could not find a part of the path 'D:\a\MauiCodeQL\MauiCodeQL\MauiCodeQL\obj\Release\net9.0-windows10.0.19041.0\win10-x64\generated'.

The path comes from the msbuild property CompilerGeneratedFilesOutputPath, which is actually set to: obj\Release\net9.0-windows10.0.19041.0\win10-x64\/generated, note the odd \/.

This could be handled by wrapping the call with a try-catch. The generated files make analysis more precise, but could be omitted.

At the same time, the compiler is reporting these kind of errors:

CSC : error CS0016: Could not write to output file 'D:\a\MauiCodeQL\MauiCodeQL\MauiCodeQL\obj\Release\net9.0-windows10.0.19041.0\win10-x64\generated\Microsoft.Maui.Controls.SourceGen\Microsoft.Maui.Controls.SourceGen.CodeBehindGenerator\App.xaml.sg.cs'

This only happens when the build is executed within a codeql context. The reason for this is that codeql silently modifies the build command, see here, and injects the /p:EmitCompilerGeneratedFiles=true into the call. If this is added to the build command manually, then the build fails even without CodeQL, see here.

@tamasvajk
Copy link
Contributor

@dhindrik I think we can't do much with the compilation failure caused by /p:EmitCompilerGeneratedFiles=true, this seems to be a bug somewhere in the toolchain.

CodeQL also supports creating databases from msbuild binary log files. In this mode, the extractor doesn't rely on the /p:EmitCompilerGeneratedFiles=true property, so this is a viable workaround for the issue that you're facing. Here's a run with this option.

You'd need to change your build command to generate the binary log file, and CodeQL needs to be configured to use build-mode: none with the binlog option, which can be achieved as follows (see the workflow here):

      - name: Initialize CodeQL
        uses: github/codeql-action/init@v3
        with:
          languages: csharp
          build-mode: none
          # ...

      - name: Build app for release
        run: |
          dotnet build -f net9.0-windows10.0.19041.0 -c Release -bl:log.binlog
          echo "CODEQL_EXTRACTOR_CSHARP_OPTION_BINLOG=log.binlog" >> $env:GITHUB_ENV

      - name: Perform CodeQL Analysis
        uses: github/codeql-action/analyze@v3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants