CLI CreateMigrationAndRunMigrator: check if EF Core global tool installed

resolves https://github.com/abpframework/abp/issues/7800
pull/7802/head
Yunus Emre Kalkan 5 years ago
parent 6786e373cb
commit 33f45d504b

@ -2,6 +2,8 @@
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Volo.Abp.Cli.Args; using Volo.Abp.Cli.Args;
using Volo.Abp.Cli.Utils; using Volo.Abp.Cli.Utils;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
@ -10,6 +12,13 @@ namespace Volo.Abp.Cli.Commands
{ {
public class CreateMigrationAndRunMigrator : IConsoleCommand, ITransientDependency public class CreateMigrationAndRunMigrator : IConsoleCommand, ITransientDependency
{ {
public ILogger<CreateMigrationAndRunMigrator> Logger { get; set; }
public CreateMigrationAndRunMigrator()
{
Logger = NullLogger<CreateMigrationAndRunMigrator>.Instance;
}
public virtual async Task ExecuteAsync(CommandLineArgs commandLineArgs) public virtual async Task ExecuteAsync(CommandLineArgs commandLineArgs)
{ {
if (commandLineArgs.Target.IsNullOrEmpty()) if (commandLineArgs.Target.IsNullOrEmpty())
@ -26,6 +35,8 @@ namespace Volo.Abp.Cli.Commands
throw new Exception("DbMigrator is not found!"); throw new Exception("DbMigrator is not found!");
} }
await CheckAndInstallDotnetEfIfNeededAsync();
var output = CmdHelper.RunCmdAndGetOutput($"cd \"{commandLineArgs.Target}\" && dotnet ef migrations add Initial -s \"{dbMigratorProjectPath}\""); var output = CmdHelper.RunCmdAndGetOutput($"cd \"{commandLineArgs.Target}\" && dotnet ef migrations add Initial -s \"{dbMigratorProjectPath}\"");
if (output.Contains("Done.") && output.Contains("To undo this action") && output.Contains("ef migrations remove")) // Migration added successfully if (output.Contains("Done.") && output.Contains("To undo this action") && output.Contains("ef migrations remove")) // Migration added successfully
@ -38,6 +49,22 @@ namespace Volo.Abp.Cli.Commands
} }
} }
private async Task CheckAndInstallDotnetEfIfNeededAsync()
{
var output = CmdHelper.RunCmdAndGetOutput("dotnet tool list -g");
if (output.Contains("dotnet-ef"))
{
return;
}
Logger.LogInformation("Installing dotnet-ef tool...");
CmdHelper.RunCmd("dotnet tool install --global dotnet-ef");
Logger.LogInformation("dotnet-ef tool is installed.");
}
private string GetDbMigratorProjectPath(string dbMigrationsFolderPath) private string GetDbMigratorProjectPath(string dbMigrationsFolderPath)
{ {
var srcFolder = Directory.GetParent(dbMigrationsFolderPath); var srcFolder = Directory.GetParent(dbMigrationsFolderPath);

Loading…
Cancel
Save