Browse Source

Merge pull request #19842 from abpframework/bundle-command

Output warning if the project and cli are use different `TargetFramework`.
pull/19997/head
Enis Necipoglu 2 years ago
committed by GitHub
parent
commit
549841914e
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 18
      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

18
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.");
}
}
}

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 const string Name = "bundle";
public ILogger<BundleCommand> 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);

Loading…
Cancel
Save