From d8a8c3bbbb1d7a3f40325309e260fef1f9444a9d Mon Sep 17 00:00:00 2001 From: maliming Date: Thu, 16 May 2024 13:59:03 +0800 Subject: [PATCH 1/2] Output warning if the project and cli are use different `TargetFramework`. Resolve #19602 --- .../Volo/Abp/Cli/Bundling/BundlingService.cs | 17 +++++++++++++++-- .../Volo/Abp/Cli/Commands/BundleCommand.cs | 16 ++++------------ 2 files changed, 19 insertions(+), 14 deletions(-) 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..d0a6698209 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,16 @@ public class BundlingService : IBundlingService, ITransientDependency } break; } + + var targetFramework = document.SelectSingleNode("//TargetFramework")?.InnerText; + var currentCliVersion = await CliVersionService.GetCurrentCliVersionAsync(); + + if (targetFramework.IsNullOrWhiteSpace() || + !targetFramework.StartsWith($"net{currentCliVersion.Major}", StringComparison.OrdinalIgnoreCase)) + { + throw new BundlingException($"Your project target framework is {targetFramework}. " + Environment.NewLine + + $"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); From 6899607b574817d00d9833ccb9ac14468ca99db8 Mon Sep 17 00:00:00 2001 From: maliming Date: Thu, 16 May 2024 14:10:46 +0800 Subject: [PATCH 2/2] Update bundle command warning message. --- .../Volo/Abp/Cli/Bundling/BundlingService.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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 d0a6698209..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 @@ -345,14 +345,15 @@ public class BundlingService : IBundlingService, ITransientDependency break; } - var targetFramework = document.SelectSingleNode("//TargetFramework")?.InnerText; + var targetFramework = document.SelectSingleNode("//TargetFramework")?.InnerText ?? + document.SelectNodes("//TargetFrameworks")[0].InnerText; var currentCliVersion = await CliVersionService.GetCurrentCliVersionAsync(); if (targetFramework.IsNullOrWhiteSpace() || - !targetFramework.StartsWith($"net{currentCliVersion.Major}", StringComparison.OrdinalIgnoreCase)) + targetFramework.IndexOf($"net{currentCliVersion.Major}.0", StringComparison.OrdinalIgnoreCase) < 0) { - throw new BundlingException($"Your project target framework is {targetFramework}. " + Environment.NewLine + - $"ABP CLI version is {currentCliVersion}. " + Environment.NewLine + + 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."); } }