{"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/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Design/Design/Internal/DbContextOperations.cs#L349-L385","documentation":"NotSupportedException thrown when project.SupportsCompilation is false after the project loaded successfully. Query precompilation needs Roslyn to compile the loaded project; if the project kind does not support compilation (e.g. a solution folder or unsupported project type), precompilation is impossible.","triggerScenarios":"Pointing optimize/precompilation at a project that MSBuildWorkspace loads but cannot compile — typically a non-C#/non-VB project, a project with no Compile items, or a meta project.","commonSituations":"Running tools from a shared/empty project, an MSBuild SDK project EF tools do not recognize, or a multi-targeting project where the inner framework project was not selected.","solutions":["Target the concrete C#/VB project (the .csproj with Compile items), not a wrapper or folder project.","Ensure a single target framework is selected when multi-targeting.","Disable precompilation (--no-precompile-queries) if the project legitimately cannot be compiled by Roslyn."],"exampleFix":"# before\n> dotnet ef dbcontext optimize --precompile-queries --project src/MyApp.sln\n\n# after\n> dotnet ef dbcontext optimize --precompile-queries --project src/MyApp.Data/MyApp.Data.csproj","handlingStrategy":"validation","validationCode":"// before invoking, ensure the project file is a compilable C#/VB project\nvar proj = await MSBuildWorkspace.Create().OpenProjectAsync(projectPath);\nif (!proj.SupportsCompilation)\n    throw new NotSupportedException($\"{projectPath} is not a compilable project.\");","typeGuard":null,"tryCatchPattern":"try { operations.Optimize(..., precompileQueries: true, ...); }\ncatch (NotSupportedException ex) when (ex.Message.Contains(\"does not support compilation\"))\n{ /* point the tool at the real .csproj */ }","preventionTips":["Point optimize at the concrete .csproj/.vbproj, not a solution or wrapper project.","Avoid precompilation on project types Roslyn cannot compile."],"tags":["design-time","ef-tools","precompilation","msbuild","not-supported"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}