From b8e13215e030f63e960107094e75d513fb649362 Mon Sep 17 00:00:00 2001 From: Deep Choudhery <54324771+deepchoudhery@users.noreply.github.com> Date: Wed, 23 Oct 2024 15:02:42 -0700 Subject: [PATCH] add missing EfCore.Tools package to dotnet-scaffold-aspnet scaffolders. (#3040) * add missing EfCore.Tools package to dotnet-scaffold-aspnet scaffolders. * minor fix for 'minimalapi' scaffolder --- .../Extensions/BlazorCrudScaffolderBuilderExtensions.cs | 3 ++- .../Extensions/EfControllerScaffolderBuilderExtensions.cs | 2 +- .../Extensions/MinimalApiScaffolderBuilderExtensions.cs | 6 ++++-- .../Extensions/RazorPagesScaffolderBuilderExtensions.cs | 2 +- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/dotnet-scaffolding/dotnet-scaffold-aspnet/Extensions/BlazorCrudScaffolderBuilderExtensions.cs b/src/dotnet-scaffolding/dotnet-scaffold-aspnet/Extensions/BlazorCrudScaffolderBuilderExtensions.cs index e7e770161..aed624dd9 100644 --- a/src/dotnet-scaffolding/dotnet-scaffold-aspnet/Extensions/BlazorCrudScaffolderBuilderExtensions.cs +++ b/src/dotnet-scaffolding/dotnet-scaffold-aspnet/Extensions/BlazorCrudScaffolderBuilderExtensions.cs @@ -49,7 +49,8 @@ public static IScaffoldBuilder WithBlazorCrudAddPackagesStep(this IScaffoldBuild var packageList = new List() { PackageConstants.AspNetCorePackages.QuickGridEfAdapterPackageName, - PackageConstants.AspNetCorePackages.AspNetCoreDiagnosticsEfCorePackageName + PackageConstants.AspNetCorePackages.AspNetCoreDiagnosticsEfCorePackageName, + PackageConstants.EfConstants.EfCoreToolsPackageName }; if (context.Properties.TryGetValue(nameof(CrudSettings), out var commandSettingsObj) && diff --git a/src/dotnet-scaffolding/dotnet-scaffold-aspnet/Extensions/EfControllerScaffolderBuilderExtensions.cs b/src/dotnet-scaffolding/dotnet-scaffold-aspnet/Extensions/EfControllerScaffolderBuilderExtensions.cs index afe73aa07..3726c14f0 100644 --- a/src/dotnet-scaffolding/dotnet-scaffold-aspnet/Extensions/EfControllerScaffolderBuilderExtensions.cs +++ b/src/dotnet-scaffolding/dotnet-scaffold-aspnet/Extensions/EfControllerScaffolderBuilderExtensions.cs @@ -46,7 +46,7 @@ public static IScaffoldBuilder WithEfControllerAddPackagesStep(this IScaffoldBui { var step = config.Step; var context = config.Context; - List packageList = []; + List packageList = [PackageConstants.EfConstants.EfCoreToolsPackageName]; if (context.Properties.TryGetValue(nameof(EfControllerSettings), out var commandSettingsObj) && commandSettingsObj is EfControllerSettings commandSettings) { diff --git a/src/dotnet-scaffolding/dotnet-scaffold-aspnet/Extensions/MinimalApiScaffolderBuilderExtensions.cs b/src/dotnet-scaffolding/dotnet-scaffold-aspnet/Extensions/MinimalApiScaffolderBuilderExtensions.cs index a9c086043..39afc2bf9 100644 --- a/src/dotnet-scaffolding/dotnet-scaffold-aspnet/Extensions/MinimalApiScaffolderBuilderExtensions.cs +++ b/src/dotnet-scaffolding/dotnet-scaffold-aspnet/Extensions/MinimalApiScaffolderBuilderExtensions.cs @@ -61,16 +61,18 @@ public static IScaffoldBuilder WithMinimalApiAddPackagesStep(this IScaffoldBuild { var step = config.Step; var context = config.Context; - //add Microsoft.EntityFrameworkCore.Tools package regardless of the DatabaseProvider + //this scaffolder has a non-EF scenario, only add EF packages if DataContext is provided. List packageList = []; if (context.Properties.TryGetValue(nameof(MinimalApiSettings), out var commandSettingsObj) && commandSettingsObj is MinimalApiSettings commandSettings) { step.ProjectPath = commandSettings.Project; step.Prerelease = commandSettings.Prerelease; - if (!string.IsNullOrEmpty(commandSettings.DatabaseProvider) && + if (!string.IsNullOrEmpty(commandSettings.DataContext) && + !string.IsNullOrEmpty(commandSettings.DatabaseProvider) && PackageConstants.EfConstants.EfPackagesDict.TryGetValue(commandSettings.DatabaseProvider, out string? projectPackageName)) { + packageList.Add(PackageConstants.EfConstants.EfCoreToolsPackageName); packageList.Add(projectPackageName); } diff --git a/src/dotnet-scaffolding/dotnet-scaffold-aspnet/Extensions/RazorPagesScaffolderBuilderExtensions.cs b/src/dotnet-scaffolding/dotnet-scaffold-aspnet/Extensions/RazorPagesScaffolderBuilderExtensions.cs index f9490346d..fd47ef679 100644 --- a/src/dotnet-scaffolding/dotnet-scaffold-aspnet/Extensions/RazorPagesScaffolderBuilderExtensions.cs +++ b/src/dotnet-scaffolding/dotnet-scaffold-aspnet/Extensions/RazorPagesScaffolderBuilderExtensions.cs @@ -84,7 +84,7 @@ public static IScaffoldBuilder WithRazorPagesAddPackagesStep(this IScaffoldBuild { var step = config.Step; var context = config.Context; - List packageList = []; + List packageList = [PackageConstants.EfConstants.EfCoreToolsPackageName]; if (context.Properties.TryGetValue(nameof(CrudSettings), out var commandSettingsObj) && commandSettingsObj is CrudSettings commandSettings) {