{"record":{"id":"bfd7661dae5b5e88","repo":"dotnet/efcore","slug":"no-files-were-generated-in-directory-outputdirec","errorCode":null,"errorMessage":"No files were generated in directory '{outputDirectoryName}'. The following file(s) already exist(s) and must be made writeable to continue: {readOnlyFiles}.","messagePattern":"No files were generated in directory '(.+?)'\\. The following file\\(s\\) already exist\\(s\\) and must be made writeable to continue: (.+?)\\.","errorType":"exception","errorClass":"OperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Scaffolding/Internal/CompiledModelScaffolder.cs","lineNumber":90,"sourceCode":"        var savedFiles = new List<string>();\n        foreach (var file in scaffoldedModel)\n        {\n            var fullPath = Path.Combine(outputDir, file.Path);\n\n            if (File.Exists(fullPath)\n                && File.GetAttributes(fullPath).HasFlag(FileAttributes.ReadOnly))\n            {\n                readOnlyFiles.Add(file.Path);\n            }\n            else\n            {\n                File.WriteAllText(fullPath, file.Code, new UTF8Encoding(encoderShouldEmitUTF8Identifier: false));\n                savedFiles.Add(fullPath);\n            }\n        }\n\n        return readOnlyFiles.Count != 0\n            ? throw new OperationException(\n                DesignStrings.ReadOnlyFiles(\n                    outputDir,\n                    string.Join(CultureInfo.CurrentCulture.TextInfo.ListSeparator, readOnlyFiles)))\n            : (IReadOnlyList<string>)savedFiles;\n    }\n}\n","sourceCodeStart":72,"sourceCodeEnd":97,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Design/Scaffolding/Internal/CompiledModelScaffolder.cs#L72-L97","documentation":"Thrown by CompiledModelScaffolder when writing the generated compiled-model files and one or more target paths already exist with the read-only file attribute. The scaffolder refuses to overwrite read-only files, collects the offending paths, and throws OperationException (DesignStrings.ReadOnlyFiles) listing them so they can be made writable.","triggerScenarios":"Running 'dotnet ef dbcontext optimize' (or programmatic compiled-model scaffolding) into a directory where a previous generation produced files that are now read-only.","commonSituations":"Files checked into source control that applies a read-only attribute; output generated on one OS/filesystem and copied to another; CI that marks artifacts read-only; a previous --force run left read-only files.","solutions":["Remove the read-only attribute from the listed files: chmod +w (Linux/mac) or attrib -R (Windows), or delete them.","Clear the output directory before regenerating.","Ensure the output directory is writable by the user running the tool."],"exampleFix":"# before: files are read-only\nchmod -R u+w OutputDir/\n# or remove and regenerate\nrm -rf OutputDir/ && dotnet ef dbcontext optimize","handlingStrategy":"validation","validationCode":"// Ensure output files are writable before scaffolding\nforeach (var f in Directory.GetFiles(outputDir, \"*.cs\", SearchOption.AllDirectories))\n    if ((File.GetAttributes(f) & FileAttributes.ReadOnly) != 0)\n        File.SetAttributes(f, File.GetAttributes(f) & ~FileAttributes.ReadOnly);","typeGuard":null,"tryCatchPattern":"try { scaffolder.Save(outputDir); }\ncatch (OperationException ex) when (ex.Message.Contains(\"writeable\"))\n{ /* chmod/attrib the listed files, or delete the directory and retry */ }","preventionTips":["Write compiled-model output to a directory not under a read-only source-control attribute.","Clear or chmod the output directory before regenerating.","In CI, write to a fresh working directory."],"tags":["compiled-model","file-system","permissions","scaffolding"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}