Browse Source

Output warning if the project and cli are use different `TargetFramework`.

Resolve #19602
pull/19842/head
maliming 2 years ago
parent
commit
d8a8c3bbbb
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  1. 17
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Bundling/BundlingService.cs
  2. 16
      framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/BundleCommand.cs

17
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.Scripts;
using Volo.Abp.Cli.Bundling.Styles; using Volo.Abp.Cli.Bundling.Styles;
using Volo.Abp.Cli.Configuration; using Volo.Abp.Cli.Configuration;
using Volo.Abp.Cli.Version;
using Volo.Abp.DependencyInjection; using Volo.Abp.DependencyInjection;
using Volo.Abp.Minify.Scripts; using Volo.Abp.Minify.Scripts;
using Volo.Abp.Minify.Styles; using Volo.Abp.Minify.Styles;
@ -29,6 +30,7 @@ public class BundlingService : IBundlingService, ITransientDependency
public IScriptBundler ScriptBundler { get; set; } public IScriptBundler ScriptBundler { get; set; }
public IStyleBundler StyleBundler { get; set; } public IStyleBundler StyleBundler { get; set; }
public IConfigReader ConfigReader { get; set; } public IConfigReader ConfigReader { get; set; }
public CliVersionService CliVersionService { get; set; }
public async Task BundleAsync(string directory, bool forceBuild, string projectType = BundlingConsts.WebAssembly) 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]; 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 config = projectType == BundlingConsts.WebAssembly? ConfigReader.Read(PathHelper.GetWwwRootPath(directory)): ConfigReader.Read(directory);
var bundleConfig = config.Bundle; 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(); var document = new XmlDocument();
document.Load(projectFilePath); document.Load(projectFilePath);
@ -342,5 +344,16 @@ public class BundlingService : IBundlingService, ITransientDependency
} }
break; 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.");
}
} }
} }

16
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 class BundleCommand : IConsoleCommand, ITransientDependency
{ {
public const string Name = "bundle"; public const string Name = "bundle";
public ILogger<BundleCommand> Logger { get; set; } public ILogger<BundleCommand> Logger { get; set; }
public IBundlingService BundlingService { get; set; } public IBundlingService BundlingService { get; set; }
@ -30,7 +30,7 @@ public class BundleCommand : IConsoleCommand, ITransientDependency
var forceBuild = commandLineArgs.Options.ContainsKey(Options.ForceBuild.Short) || var forceBuild = commandLineArgs.Options.ContainsKey(Options.ForceBuild.Short) ||
commandLineArgs.Options.ContainsKey(Options.ForceBuild.Long); commandLineArgs.Options.ContainsKey(Options.ForceBuild.Long);
var projectType = GetProjectType(commandLineArgs); var projectType = GetProjectType(commandLineArgs);
if (!Directory.Exists(workingDirectory)) if (!Directory.Exists(workingDirectory))
@ -42,15 +42,7 @@ public class BundleCommand : IConsoleCommand, ITransientDependency
); );
} }
try await BundlingService.BundleAsync(workingDirectory, forceBuild, projectType);
{
await BundlingService.BundleAsync(workingDirectory, forceBuild, projectType);
}
catch (BundlingException ex)
{
Logger.LogError(ex.Message);
throw;
}
} }
public string GetShortDescription() public string GetShortDescription()
@ -77,7 +69,7 @@ public class BundleCommand : IConsoleCommand, ITransientDependency
return sb.ToString(); return sb.ToString();
} }
private string GetProjectType(CommandLineArgs commandLineArgs) private string GetProjectType(CommandLineArgs commandLineArgs)
{ {
var projectType = commandLineArgs.Options.GetOrNull(Options.ProjectType.Short, Options.ProjectType.Long); var projectType = commandLineArgs.Options.GetOrNull(Options.ProjectType.Short, Options.ProjectType.Long);

Loading…
Cancel
Save