{"record":{"id":"39e72bd28614d815","repo":"dotnet/efcore","slug":"the-project-project-does-not-support-compilati","errorCode":null,"errorMessage":"The project '{project}' does not support compilation.","messagePattern":"The project '(.+?)' does not support compilation\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Design/Internal/DbContextOperations.cs","lineNumber":367,"sourceCode":"        }\n        catch (Exception ex)\n        {\n            if (workspace != null && !workspace.Diagnostics.IsEmpty)\n            {\n                var diagnosticMessages = Environment.NewLine\n                    + string.Join(\n                        Environment.NewLine,\n                        workspace.Diagnostics.Select(d => $\"  {d.Kind}: {d.Message}\"));\n                _reporter.WriteVerbose(DesignStrings.MSBuildWorkspaceDiagnostics(diagnosticMessages));\n            }\n\n            throw new InvalidOperationException(\n                DesignStrings.QueryPrecompilationProjectLoadFailed(_project, ex.Message), ex);\n        }\n\n        if (!project.SupportsCompilation)\n        {\n            throw new NotSupportedException(DesignStrings.UncompilableProject(_project));\n        }\n\n        var compilation = project.GetCompilationAsync().GetAwaiter().GetResult()!;\n        var errorDiagnostics = compilation.GetDiagnostics().Where(d => d.Severity == DiagnosticSeverity.Error).ToArray();\n        if (errorDiagnostics.Length != 0)\n        {\n            var errorBuilder = new StringBuilder();\n            errorBuilder.AppendLine(DesignStrings.CompilationErrors);\n            foreach (var diagnostic in errorDiagnostics)\n            {\n                errorBuilder.AppendLine(diagnostic.ToString());\n            }\n\n            throw new InvalidOperationException(errorBuilder.ToString());\n        }\n\n        var syntaxGenerator = SyntaxGenerator.GetGenerator(\n            workspace, _language == \"VB\" ? LanguageNames.VisualBasic : _language ?? LanguageNames.CSharp);","sourceCodeStart":349,"sourceCodeEnd":385,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Design/Internal/DbContextOperations.cs#L349-L385","documentation":"Thrown as NotSupportedException by DbContextOperations.PrecompileQueries when project.SupportsCompilation is false after the project was loaded by MSBuildWorkspace. Query precompilation requires Roslyn to compile the project's sources, so projects that cannot be compiled (e.g., certain project types or unsupported languages) are rejected.","triggerScenarios":"Running the query-precompilation flow on a project that MSBuildWorkspace loaded but that does not support compilation. This includes some non-standard project kinds, projects without a compilable source set, or unsupported target frameworks/scenarios.","commonSituations":"Optimizing a project that is not a regular C#/VB compilable project (e.g., a shared MSBuild project, a project that only contains content). Using a project format or target that Roslyn's MSBuildWorkspace marks as non-compilable. Mixing languages where the loaded project is not compilable in the current workspace.","solutions":["Run precompilation against a standard compilable C# or VB project that contains the DbContext.","Move the DbContext and queries into a compilable project if it currently lives in a non-compilable one.","Skip '--precompile-queries' if you only need the compiled model ('--native-aot' scaffolding may still work without query precompilation depending on flags).","Confirm the project's target framework and SDK are supported by the installed Roslyn/MSBuild."],"exampleFix":"// before - optimizing a non-compilable project\ndotnet ef dbcontext optimize --precompile-queries --project ./src/MyApp.Shared\n\n// after - target a compilable application project\ndotnet ef dbcontext optimize --precompile-queries --startup-project ./src/MyApp","handlingStrategy":"validation","validationCode":"// Pre-check: confirm the target project is compilable before optimizing.\nvar workspace = MSBuildWorkspace.Create();\nvar project = workspace.OpenProjectAsync(projectPath).GetAwaiter().GetResult();\nif (!project.SupportsCompilation)\n    throw new NotSupportedException($\"Project '{projectPath}' does not support compilation; choose a compilable project.\");","typeGuard":null,"tryCatchPattern":"try { ops.Optimize(..., precompileQueries: true, ...); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"does not support compilation\"))\n{\n    // target a compilable C#/VB project instead\n}","preventionTips":["Run precompilation against standard compilable C#/VB projects.","Keep the DbContext in a compilable application project, not a shared/non-compilable one.","Verify the project's SDK and target framework are supported by the installed MSBuild/Roslyn."],"tags":["design","precompilation","roslyn","compilation","project"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}