{"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/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Scaffolding/Internal/CompiledModelScaffolder.cs#L72-L97","documentation":"Thrown in CompiledModelScaffolder.WriteFiles (line 90, resource ReadOnlyFiles) when writing the compiled-model output files: some target files already exist and are marked read-only (FileAttributes.ReadOnly), so they cannot be overwritten. Rather than partially writing files, EF collects all read-only paths and throws an OperationException listing them. No files in the conflicting set are written.","triggerScenarios":"Running compiled-model scaffolding into a directory where one or more output files already exist with the read-only attribute set. For each file, if File.Exists and attributes include ReadOnly, it is added to readOnlyFiles; if any exist at the end, the ReadOnlyFiles OperationException is thrown.","commonSituations":"Files checked into source control with read-only attributes (some VCS mark files read-only), or generated previously and then locked. Running on a filesystem/CI that marks output read-only. Re-running 'dotnet ef dbcontext optimize' without clearing previous read-only outputs.","solutions":["Clear the read-only attribute on the listed files (e.g. chmod +w / attrib -r) so they can be overwritten.","Delete the existing output files in the target directory before regenerating.","Use the scaffolder's force/overwrite option if invoking programmatically, or write to a fresh output directory.","If a VCS marks files read-only, ensure generated output is excluded from VCS or that the VCS is configured not to set read-only."],"exampleFix":"# before: read-only files block generation\nchmod u+w obj/CompiledModels/*.cs   # Linux/mac\nattrib -r obj\\CompiledModels\\*.cs   # Windows\n\n# then re-run\ndotnet ef dbcontext optimize","handlingStrategy":"validation","validationCode":"// Clear read-only attributes on existing output files before writing\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 { CompiledModelScaffolder.WriteFiles(model, outputDir); }\ncatch (OperationException ex) when (ex.Message.Contains(\"must be made writeable\"))\n{ /* clear read-only flags on listed files or use a fresh directory, then retry */ }","preventionTips":["Generate into a clean directory or clear read-only flags first.","Exclude generated output from VCS systems that set read-only attributes.","Use the overwrite/force path when available."],"tags":["ef-core","compiled-model","filesystem","io","design-time"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}