public async Task Scaffold(Configuration configuration, IMotor motor) { var workingDirectory = Path.GetDirectoryName(configuration.DataProjectFile); var outputDirectory = Path.GetDirectoryName(configuration.ContextFile).Replace(workingDirectory, ""); var commandParams = configuration.Database.GetParams(); var motorParams = motor.GetParams(); var oldContextFileContent = await File.ReadAllTextAsync(configuration.ContextFile); var existingContent = GetTextBetween(oldContextFileContent, "protected override void OnModelCreating(ModelBuilder modelBuilder)", "modelBuilder.HasAnnotation"); if (outputDirectory.StartsWith("\\")) { outputDirectory = outputDirectory.Remove(0, 1); } if (!string.IsNullOrEmpty(motorParams)) { commandParams += $" {motorParams}"; } if (!string.IsNullOrEmpty(configuration.AdditionalParams)) { commandParams += $" {configuration.AdditionalParams}"; } var command = $"ef dbcontext scaffold \"{configuration.ConnectionString}\" Microsoft.EntityFrameworkCore.SqlServer -o {outputDirectory} {commandParams}"; var processExitCode = await _console.RunCommandAsync("dotnet", command.Trim(), workingDirectory); if (processExitCode != 0) { throw new InvalidDataException("Error during command execution"); } var newContextFileContent = await File.ReadAllTextAsync(configuration.ContextFile); newContextFileContent = ReplaceTextBetween(newContextFileContent, "protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)", "modelBuilder.HasAnnotation", existingContent); await File.WriteAllTextAsync(configuration.ContextFile, newContextFileContent); }