diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/BundlingService.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/BundlingService.cs index ecbc0d2e9c..76bc82f570 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/BundlingService.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/BundlingService.cs @@ -13,6 +13,7 @@ using Volo.Abp.Cli.Build; using Volo.Abp.Cli.Bundling.Scripts; using Volo.Abp.Cli.Bundling.Styles; using Volo.Abp.Cli.Configuration; +using Volo.Abp.Cli.Version; using Volo.Abp.DependencyInjection; using Volo.Abp.Minify.Scripts; using Volo.Abp.Minify.Styles; @@ -29,6 +30,7 @@ public class BundlingService : IBundlingService, ITransientDependency public IScriptBundler ScriptBundler { get; set; } public IStyleBundler StyleBundler { get; set; } public IConfigReader ConfigReader { get; set; } + public CliVersionService CliVersionService { get; set; } public async Task BundleAsync(string directory, bool forceBuild, string projectType = BundlingConsts.WebAssembly) { @@ -47,7 +49,7 @@ public class BundlingService : IBundlingService, ITransientDependency var projectFilePath = projectFiles[0]; - CheckProjectIsSupportedType(projectFilePath, projectType); + await CheckProjectIsSupportedTypeAsync(projectFilePath, projectType); var config = projectType == BundlingConsts.WebAssembly? ConfigReader.Read(PathHelper.GetWwwRootPath(directory)): ConfigReader.Read(directory); var bundleConfig = config.Bundle; @@ -318,7 +320,7 @@ public class BundlingService : IBundlingService, ITransientDependency }; } - private void CheckProjectIsSupportedType(string projectFilePath, string projectType) + private async Task CheckProjectIsSupportedTypeAsync(string projectFilePath, string projectType) { var document = new XmlDocument(); document.Load(projectFilePath); @@ -342,5 +344,17 @@ public class BundlingService : IBundlingService, ITransientDependency } break; } + + var targetFramework = document.SelectSingleNode("//TargetFramework")?.InnerText ?? + document.SelectNodes("//TargetFrameworks")[0].InnerText; + var currentCliVersion = await CliVersionService.GetCurrentCliVersionAsync(); + + if (targetFramework.IsNullOrWhiteSpace() || + targetFramework.IndexOf($"net{currentCliVersion.Major}.0", StringComparison.OrdinalIgnoreCase) < 0) + { + throw new BundlingException($"Your project({projectFilePath}) target framework is {targetFramework}. " + Environment.NewLine + + $"But ABP CLI version is {currentCliVersion}. " + Environment.NewLine + + $"Please use the ABP CLI that is compatible with your project target framework."); + } } } diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/BundleCommand.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/BundleCommand.cs index 9990d8b8ed..9462f9512c 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/BundleCommand.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/BundleCommand.cs @@ -13,7 +13,7 @@ namespace Volo.Abp.Cli.Commands; public class BundleCommand : IConsoleCommand, ITransientDependency { public const string Name = "bundle"; - + public ILogger Logger { get; set; } public IBundlingService BundlingService { get; set; } @@ -30,7 +30,7 @@ public class BundleCommand : IConsoleCommand, ITransientDependency var forceBuild = commandLineArgs.Options.ContainsKey(Options.ForceBuild.Short) || commandLineArgs.Options.ContainsKey(Options.ForceBuild.Long); - + var projectType = GetProjectType(commandLineArgs); if (!Directory.Exists(workingDirectory)) @@ -42,15 +42,7 @@ public class BundleCommand : IConsoleCommand, ITransientDependency ); } - try - { - await BundlingService.BundleAsync(workingDirectory, forceBuild, projectType); - } - catch (BundlingException ex) - { - Logger.LogError(ex.Message); - throw; - } + await BundlingService.BundleAsync(workingDirectory, forceBuild, projectType); } public string GetShortDescription() @@ -77,7 +69,7 @@ public class BundleCommand : IConsoleCommand, ITransientDependency return sb.ToString(); } - + private string GetProjectType(CommandLineArgs commandLineArgs) { var projectType = commandLineArgs.Options.GetOrNull(Options.ProjectType.Short, Options.ProjectType.Long);