Skip to main content

C# compiler unexpectedly failing

The CodeQL tracer injects some flags into the C# compiler invocation to ensure every component is built and included in the CodeQL database, which may cause your C# code to build differently to what you expect during CodeQL analysis. See CodeQL code scanning for compiled languages.

/p:EmitCompilerGeneratedFiles=true is one of the injected properties, and emits compiler-generated files during the build process. This option causes the compiler to generate additional files that are used to support features such as improved regular expression support, serialization, and web application view generation. These generated artifacts are typically not written to disk by the compiler, but setting the option to true forces writing the files to disk, and so the extractor can process the files.

For some legacy projects, and projects that use .sqlproj files, you may see that the injected /p:EmitCompilerGeneratedFiles=true property causes unexpected issues with msbuild.

If you have set the "treat warnings as errors" flag, then msbuild will produce an error, which will cause the extraction to fail.

You should add the <CompilerGeneratedFilesOutputPath> element to the application's project file. For more information, see Understanding the project file in Microsoft Learn.