From 33f45d504b1b3d4f78a7d45b9a994c198c91a744 Mon Sep 17 00:00:00 2001 From: Yunus Emre Kalkan Date: Mon, 22 Feb 2021 14:06:56 +0300 Subject: [PATCH] CLI CreateMigrationAndRunMigrator: check if EF Core global tool installed resolves https://github.com/abpframework/abp/issues/7800 --- .../Commands/CreateMigrationAndRunMigrator.cs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/CreateMigrationAndRunMigrator.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/CreateMigrationAndRunMigrator.cs index 982ef77065..b6eadd4183 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/CreateMigrationAndRunMigrator.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/CreateMigrationAndRunMigrator.cs @@ -2,6 +2,8 @@ using System.IO; using System.Linq; using System.Threading.Tasks; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; using Volo.Abp.Cli.Args; using Volo.Abp.Cli.Utils; using Volo.Abp.DependencyInjection; @@ -10,6 +12,13 @@ namespace Volo.Abp.Cli.Commands { public class CreateMigrationAndRunMigrator : IConsoleCommand, ITransientDependency { + public ILogger Logger { get; set; } + + public CreateMigrationAndRunMigrator() + { + Logger = NullLogger.Instance; + } + public virtual async Task ExecuteAsync(CommandLineArgs commandLineArgs) { if (commandLineArgs.Target.IsNullOrEmpty()) @@ -26,6 +35,8 @@ namespace Volo.Abp.Cli.Commands throw new Exception("DbMigrator is not found!"); } + await CheckAndInstallDotnetEfIfNeededAsync(); + 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 @@ -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) { var srcFolder = Directory.GetParent(dbMigrationsFolderPath);