Skip to main content

This version of GitHub Enterprise Server was discontinued on 2024-09-25. No patch releases will be made, even for critical security issues. For better performance, improved security, and new features, upgrade to the latest version of GitHub Enterprise Server. For help with the upgrade, contact GitHub Enterprise support.

C# compiler unexpectedly failing

If your MSBuild C# compilation is unexpectedly failing, you may need to amend your application project file.

About these errors

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.

Confirming the cause of the problem

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

Fixing the problem

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