dotnet/efcore · error · OperationException

No files were generated in directory '{outputDirectoryName}'

Error message

No files were generated in directory '{outputDirectoryName}'. The following file(s) already exist(s) and must be made writeable to continue: {readOnlyFiles}.

What it means

Thrown during scaffolding when target files exist but are marked read-only (e.g. FileAttributes.ReadOnly), so EF Core cannot overwrite them even though overwrite was requested or they are the only blockers. The message lists the offending read-only files and instructs making them writeable.

Source

Thrown at src/EFCore.Design/Scaffolding/Internal/ReverseEngineerScaffolder.cs:187

                if (File.GetAttributes(fullPath).HasFlag(FileAttributes.ReadOnly))
                {
                    readOnlyFiles.Add(path);
                }
            }
        }

        if (!overwriteFiles
            && existingFiles.Count != 0)
        {
            throw new OperationException(
                DesignStrings.ExistingFiles(
                    outputDir,
                    string.Join(CultureInfo.CurrentCulture.TextInfo.ListSeparator, existingFiles)));
        }

        if (readOnlyFiles.Count != 0)
        {
            throw new OperationException(
                DesignStrings.ReadOnlyFiles(
                    outputDir,
                    string.Join(CultureInfo.CurrentCulture.TextInfo.ListSeparator, readOnlyFiles)));
        }
    }
}

View on GitHub (pinned to 3a2006ef56)

Solutions

  1. Clear the ReadOnly attribute on the listed files: `attrib -R <files>` on Windows or `chmod u+w <files>` on Unix.
  2. Close any editor/IDE or SCM that is locking the files read-only, then re-run scaffold.
  3. Delete the listed files and let scaffolding recreate them.
  4. Move the output to a directory you fully own and re-run.

Example fix

# before: files are read-only
attrib +r MyContext.cs
# after: clear the bit, then scaffold
attrib -r MyContext.cs Models\*.cs
dotnet ef dbcontext scaffold "..." Microsoft.EntityFrameworkCore.SqlServer --force
Defensive patterns

Strategy: validation

Validate before calling

foreach (var f in Directory.GetFiles(outputDir, "*.cs", SearchOption.AllDirectories))
{
    if (File.GetAttributes(f).HasFlag(FileAttributes.ReadOnly))
        File.SetAttributes(f, File.GetAttributes(f) & ~FileAttributes.ReadOnly);
}

Try / catch

try { scaffolder.ScaffoldModel(...); }
catch (OperationException ex) when (ex.Message.Contains("writeable"))
{
    foreach (var f in ListedFrom(ex)) File.SetAttributes(f, FileAttributes.Normal);
    scaffolder.ScaffoldModel(...);
}

Prevention

When it happens

Trigger: Scaffolding with overwriteFiles=true (or no non-readonly collisions) where at least one output path resolves to a file with the ReadOnly attribute set. Detected via File.GetAttributes(fullPath).HasFlag(FileAttributes.ReadOnly).

Common situations: Files checked out as read-only by an older TFS/SCM, files copied from a read-only share or CD image, files with the readonly bit set after a failed tool run, or files on a network mount with write protection.

Related errors


AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11). Data as JSON: /api/errors/0568b8c2c78ee0de. Report an issue: GitHub.