diff --git a/src/dotnet-scaffolding/dotnet-scaffold-aspnet/Common/Constants.cs b/src/dotnet-scaffolding/dotnet-scaffold-aspnet/Common/Constants.cs index d3defbc4c..c00fc0f1c 100644 --- a/src/dotnet-scaffolding/dotnet-scaffold-aspnet/Common/Constants.cs +++ b/src/dotnet-scaffolding/dotnet-scaffold-aspnet/Common/Constants.cs @@ -10,6 +10,7 @@ internal class Constants public const string ViewModelExtension = ".cshtml.cs"; public const string T4TemplateExtension = ".tt"; public const string GlobalNamespace = ""; + public const string NewDbContext = nameof(NewDbContext); public class CliOptions { diff --git a/src/dotnet-scaffolding/dotnet-scaffold-aspnet/Models/IdentityModel.cs b/src/dotnet-scaffolding/dotnet-scaffold-aspnet/Models/IdentityModel.cs index 056e10940..381b65471 100644 --- a/src/dotnet-scaffolding/dotnet-scaffold-aspnet/Models/IdentityModel.cs +++ b/src/dotnet-scaffolding/dotnet-scaffold-aspnet/Models/IdentityModel.cs @@ -13,9 +13,6 @@ internal class IdentityModel public required string UserClassName { get; internal set; } public required string UserClassNamespace { get; internal set; } public string? DbContextNamespace { get; set; } - public required string DbContextName { get; set; } - //Database type eg. SQL Server or SQLite - public string? DatabaseProvider { get; set; } public required string BaseOutputPath { get; set; } public bool Overwrite { get; set; } } diff --git a/src/dotnet-scaffolding/dotnet-scaffold-aspnet/ScaffoldSteps/ValidateBlazorCrudStep.cs b/src/dotnet-scaffolding/dotnet-scaffold-aspnet/ScaffoldSteps/ValidateBlazorCrudStep.cs index 971b4467c..3e5021f1a 100644 --- a/src/dotnet-scaffolding/dotnet-scaffold-aspnet/ScaffoldSteps/ValidateBlazorCrudStep.cs +++ b/src/dotnet-scaffolding/dotnet-scaffold-aspnet/ScaffoldSteps/ValidateBlazorCrudStep.cs @@ -1,5 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using Microsoft.CodeAnalysis.CSharp; using Microsoft.DotNet.Scaffolding.Core.Scaffolders; using Microsoft.DotNet.Scaffolding.Core.Steps; using Microsoft.DotNet.Scaffolding.Internal.Services; @@ -10,6 +11,7 @@ using Microsoft.DotNet.Tools.Scaffold.AspNet.ScaffoldSteps.Settings; using Microsoft.Extensions.Logging; using Constants = Microsoft.DotNet.Scaffolding.Internal.Constants; +using AspNetConstants = Microsoft.DotNet.Tools.Scaffold.AspNet.Common.Constants; namespace Microsoft.DotNet.Tools.Scaffold.AspNet.ScaffoldSteps; @@ -93,19 +95,19 @@ public override async Task ExecuteAsync(ScaffolderContext context, Cancell { if (string.IsNullOrEmpty(Project) || !_fileSystem.FileExists(Project)) { - _logger.LogError("Missing/Invalid --project option."); + _logger.LogError($"Missing/Invalid {AspNetConstants.CliOptions.ProjectCliOption} option."); return null; } if (string.IsNullOrEmpty(Model)) { - _logger.LogError("Missing/Invalid --model option."); + _logger.LogError($"Missing/Invalid {AspNetConstants.CliOptions.ModelCliOption} option."); return null; } if (string.IsNullOrEmpty(Page)) { - _logger.LogError("Missing/Invalid --page option."); + _logger.LogError($"Missing/Invalid {AspNetConstants.CliOptions.PageTypeOption} option."); return null; } else if (!string.IsNullOrEmpty(Page) && !BlazorCrudHelper.CRUDPages.Contains(Page, StringComparer.OrdinalIgnoreCase)) @@ -116,12 +118,22 @@ public override async Task ExecuteAsync(ScaffolderContext context, Cancell if (string.IsNullOrEmpty(DataContext)) { - _logger.LogError("Missing/Invalid --dataContext option."); + _logger.LogError($"Missing/Invalid {AspNetConstants.CliOptions.DataContextOption} option."); return null; } - else if (string.IsNullOrEmpty(DatabaseProvider) || !PackageConstants.EfConstants.EfPackagesDict.ContainsKey(DatabaseProvider)) + else { - DatabaseProvider = PackageConstants.EfConstants.SqlServer; + if (!SyntaxFacts.IsValidIdentifier(DataContext) || DataContext.Equals("DbContext", StringComparison.OrdinalIgnoreCase)) + { + _logger.LogInformation($"Invalid {AspNetConstants.CliOptions.DataContextOption} option"); + _logger.LogInformation($"Using default '{AspNetConstants.NewDbContext}'"); + DataContext = AspNetConstants.NewDbContext; + } + + if (string.IsNullOrEmpty(DatabaseProvider) || !PackageConstants.EfConstants.EfPackagesDict.ContainsKey(DatabaseProvider)) + { + DatabaseProvider = PackageConstants.EfConstants.SqlServer; + } } return new CrudSettings @@ -149,7 +161,7 @@ public override async Task ExecuteAsync(ScaffolderContext context, Cancell var modelClassSymbol = allClasses.FirstOrDefault(x => x.Name.Equals(settings.Model, StringComparison.OrdinalIgnoreCase)); if (string.IsNullOrEmpty(settings.Model) || modelClassSymbol is null) { - _logger.LogError($"Invalid --model '{settings.Model}'"); + _logger.LogError($"Invalid {AspNetConstants.CliOptions.ModelCliOption} '{settings.Model}'"); return null; } else @@ -160,7 +172,7 @@ public override async Task ExecuteAsync(ScaffolderContext context, Cancell var validateModelInfoResult = ClassAnalyzers.ValidateModelForCrudScaffolders(modelInfo, _logger); if (!validateModelInfoResult) { - _logger.LogError($"Invalid --model '{settings.Model}'"); + _logger.LogError($"Invalid {AspNetConstants.CliOptions.ModelCliOption} '{settings.Model}'"); return null; } diff --git a/src/dotnet-scaffolding/dotnet-scaffold-aspnet/ScaffoldSteps/ValidateEfControllerStep.cs b/src/dotnet-scaffolding/dotnet-scaffold-aspnet/ScaffoldSteps/ValidateEfControllerStep.cs index 09e0874be..d6d0732bf 100644 --- a/src/dotnet-scaffolding/dotnet-scaffold-aspnet/ScaffoldSteps/ValidateEfControllerStep.cs +++ b/src/dotnet-scaffolding/dotnet-scaffold-aspnet/ScaffoldSteps/ValidateEfControllerStep.cs @@ -1,5 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using Microsoft.CodeAnalysis.CSharp; using Microsoft.DotNet.Scaffolding.Core.Scaffolders; using Microsoft.DotNet.Scaffolding.Core.Steps; using Microsoft.DotNet.Scaffolding.Internal.Services; @@ -10,6 +11,7 @@ using Microsoft.DotNet.Tools.Scaffold.AspNet.ScaffoldSteps.Settings; using Microsoft.Extensions.Logging; using Constants = Microsoft.DotNet.Scaffolding.Internal.Constants; +using AspNetConstants = Microsoft.DotNet.Tools.Scaffold.AspNet.Common.Constants; namespace Microsoft.DotNet.Tools.Scaffold.AspNet.ScaffoldSteps; @@ -85,19 +87,19 @@ public override async Task ExecuteAsync(ScaffolderContext context, Cancell { if (string.IsNullOrEmpty(Project) || !_fileSystem.FileExists(Project)) { - _logger.LogError("Missing/Invalid --project option."); + _logger.LogError($"Missing/Invalid {AspNetConstants.CliOptions.ProjectCliOption} option."); return null; } if (string.IsNullOrEmpty(Model)) { - _logger.LogError("Missing/Invalid --model option."); + _logger.LogError($"Missing/Invalid {AspNetConstants.CliOptions.ModelCliOption} option."); return null; } if (string.IsNullOrEmpty(ControllerName)) { - _logger.LogError("Missing/Invalid --controller option."); + _logger.LogError($"Missing/Invalid {AspNetConstants.CliOptions.ControllerNameOption} option."); return null; } else @@ -107,7 +109,7 @@ public override async Task ExecuteAsync(ScaffolderContext context, Cancell if (string.IsNullOrEmpty(ControllerType)) { - _logger.LogError($"Missing/Invalid '{nameof(ValidateEfControllerStep.ControllerType)}' value."); + _logger.LogError($"Missing/Invalid '{nameof(ControllerType)}' value."); return null; } else if ( @@ -121,12 +123,22 @@ public override async Task ExecuteAsync(ScaffolderContext context, Cancell if (string.IsNullOrEmpty(DataContext)) { - _logger.LogError("Missing/Invalid --dataContext option."); + _logger.LogError($"Missing/Invalid {AspNetConstants.CliOptions.DataContextOption} option."); return null; } - else if (string.IsNullOrEmpty(DatabaseProvider) || !PackageConstants.EfConstants.EfPackagesDict.ContainsKey(DatabaseProvider)) + else { - DatabaseProvider = PackageConstants.EfConstants.SqlServer; + if (!SyntaxFacts.IsValidIdentifier(DataContext) || DataContext.Equals("DbContext", StringComparison.OrdinalIgnoreCase)) + { + _logger.LogInformation($"Invalid {AspNetConstants.CliOptions.DataContextOption} option"); + _logger.LogInformation($"Using default '{AspNetConstants.NewDbContext}'"); + DataContext = AspNetConstants.NewDbContext; + } + + if (string.IsNullOrEmpty(DatabaseProvider) || !PackageConstants.EfConstants.EfPackagesDict.ContainsKey(DatabaseProvider)) + { + DatabaseProvider = PackageConstants.EfConstants.SqlServer; + } } return new EfControllerSettings @@ -156,7 +168,7 @@ public override async Task ExecuteAsync(ScaffolderContext context, Cancell var modelClassSymbol = allClasses.FirstOrDefault(x => x.Name.Equals(settings.Model, StringComparison.OrdinalIgnoreCase)); if (string.IsNullOrEmpty(settings.Model) || modelClassSymbol is null) { - _logger.LogError($"Invalid --model '{settings.Model}'"); + _logger.LogError($"Invalid {AspNetConstants.CliOptions.ModelCliOption} '{settings.Model}'"); return null; } else @@ -167,7 +179,7 @@ public override async Task ExecuteAsync(ScaffolderContext context, Cancell var validateModelInfoResult = ClassAnalyzers.ValidateModelForCrudScaffolders(modelInfo, _logger); if (!validateModelInfoResult) { - _logger.LogError($"Invalid --model '{settings.Model}'"); + _logger.LogError($"Invalid {AspNetConstants.CliOptions.ModelCliOption} '{settings.Model}'"); return null; } diff --git a/src/dotnet-scaffolding/dotnet-scaffold-aspnet/ScaffoldSteps/ValidateIdentityStep.cs b/src/dotnet-scaffolding/dotnet-scaffold-aspnet/ScaffoldSteps/ValidateIdentityStep.cs index b5175b04d..32e84c45f 100644 --- a/src/dotnet-scaffolding/dotnet-scaffold-aspnet/ScaffoldSteps/ValidateIdentityStep.cs +++ b/src/dotnet-scaffolding/dotnet-scaffold-aspnet/ScaffoldSteps/ValidateIdentityStep.cs @@ -1,5 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using Microsoft.CodeAnalysis.CSharp; using Microsoft.DotNet.Scaffolding.Core.Scaffolders; using Microsoft.DotNet.Scaffolding.Core.Steps; using Microsoft.DotNet.Scaffolding.Internal.Services; @@ -9,7 +10,8 @@ using Microsoft.DotNet.Tools.Scaffold.AspNet.Models; using Microsoft.DotNet.Tools.Scaffold.AspNet.ScaffoldSteps.Settings; using Microsoft.Extensions.Logging; -using static Microsoft.DotNet.Scaffolding.Internal.Constants; +using Constants = Microsoft.DotNet.Scaffolding.Internal.Constants; +using AspNetConstants = Microsoft.DotNet.Tools.Scaffold.AspNet.Common.Constants; namespace Microsoft.DotNet.Tools.Scaffold.AspNet.ScaffoldSteps; @@ -56,8 +58,8 @@ public override async Task ExecuteAsync(ScaffolderContext context, Cancell else { context.Properties.Add(nameof(IdentityModel), identityModel); - codeModifierProperties.Add(CodeModifierPropertyConstants.IdentityNamespace, identityModel.IdentityNamespace); - codeModifierProperties.Add(CodeModifierPropertyConstants.UserClassNamespace, identityModel.UserClassNamespace); + codeModifierProperties.Add(Constants.CodeModifierPropertyConstants.IdentityNamespace, identityModel.IdentityNamespace); + codeModifierProperties.Add(Constants.CodeModifierPropertyConstants.UserClassNamespace, identityModel.UserClassNamespace); } //Install packages and add a DbContext (if needed) @@ -74,7 +76,7 @@ public override async Task ExecuteAsync(ScaffolderContext context, Cancell var projectBasePath = Path.GetDirectoryName(identitySettings.Project); if (!string.IsNullOrEmpty(projectBasePath)) { - context.Properties.Add(StepConstants.BaseProjectPath, projectBasePath); + context.Properties.Add(Constants.StepConstants.BaseProjectPath, projectBasePath); } var dbCodeModifierProperties = AspNetDbContextHelper.GetDbContextCodeModifierProperties(identityModel.DbContextInfo); @@ -83,10 +85,10 @@ public override async Task ExecuteAsync(ScaffolderContext context, Cancell codeModifierProperties.TryAdd(kvp.Key, kvp.Value); } - codeModifierProperties.TryAdd(CodeModifierPropertyConstants.UserClassName, identityModel.UserClassName); + codeModifierProperties.TryAdd(Constants.CodeModifierPropertyConstants.UserClassName, identityModel.UserClassName); } - context.Properties.Add(StepConstants.CodeModifierProperties, codeModifierProperties); + context.Properties.Add(Constants.StepConstants.CodeModifierProperties, codeModifierProperties); return true; } @@ -94,18 +96,28 @@ public override async Task ExecuteAsync(ScaffolderContext context, Cancell { if (string.IsNullOrEmpty(Project) || !_fileSystem.FileExists(Project)) { - _logger.LogError("Missing/Invalid --project option."); + _logger.LogError($"Missing/Invalid {AspNetConstants.CliOptions.ProjectCliOption} option."); return null; } if (string.IsNullOrEmpty(DataContext)) { - _logger.LogError("Missing/Invalid --dataContext option."); + _logger.LogError($"Missing/Invalid {AspNetConstants.CliOptions.DataContextOption} option."); return null; } - else if (string.IsNullOrEmpty(DatabaseProvider) || !PackageConstants.EfConstants.IdentityEfPackagesDict.ContainsKey(DatabaseProvider)) + else { - DatabaseProvider = PackageConstants.EfConstants.SqlServer; + if (!SyntaxFacts.IsValidIdentifier(DataContext) || DataContext.Equals("DbContext", StringComparison.OrdinalIgnoreCase)) + { + _logger.LogInformation($"Invalid {AspNetConstants.CliOptions.DataContextOption} option"); + _logger.LogInformation($"Using default '{AspNetConstants.NewDbContext}'"); + DataContext = AspNetConstants.NewDbContext; + } + + if (string.IsNullOrEmpty(DatabaseProvider) || !PackageConstants.EfConstants.IdentityEfPackagesDict.ContainsKey(DatabaseProvider)) + { + DatabaseProvider = PackageConstants.EfConstants.SqlServer; + } } return new IdentitySettings @@ -154,9 +166,8 @@ public override async Task ExecuteAsync(ScaffolderContext context, Cancell ProjectInfo = projectInfo, DbContextInfo = dbContextInfo, IdentityNamespace = identityNamespace, - UserClassName = Constants.Identity.UserClassName, + UserClassName = AspNetConstants.Identity.UserClassName, UserClassNamespace = userClassNamespace, - DbContextName = Constants.Identity.DbContextName, BaseOutputPath = projectDirectory, Overwrite = settings.Overwrite }; diff --git a/src/dotnet-scaffolding/dotnet-scaffold-aspnet/ScaffoldSteps/ValidateMinimalApiStep.cs b/src/dotnet-scaffolding/dotnet-scaffold-aspnet/ScaffoldSteps/ValidateMinimalApiStep.cs index dac7b1617..9394144b5 100644 --- a/src/dotnet-scaffolding/dotnet-scaffold-aspnet/ScaffoldSteps/ValidateMinimalApiStep.cs +++ b/src/dotnet-scaffolding/dotnet-scaffold-aspnet/ScaffoldSteps/ValidateMinimalApiStep.cs @@ -1,5 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using Microsoft.CodeAnalysis.CSharp; using Microsoft.DotNet.Scaffolding.Core.Scaffolders; using Microsoft.DotNet.Scaffolding.Core.Steps; using Microsoft.DotNet.Scaffolding.Internal; @@ -11,6 +12,7 @@ using Microsoft.DotNet.Tools.Scaffold.AspNet.ScaffoldSteps.Settings; using Microsoft.Extensions.Logging; using Constants = Microsoft.DotNet.Scaffolding.Internal.Constants; +using AspNetConstants = Microsoft.DotNet.Tools.Scaffold.AspNet.Common.Constants; namespace Microsoft.DotNet.Tools.Scaffold.AspNet.ScaffoldSteps; @@ -98,20 +100,29 @@ public override async Task ExecuteAsync(ScaffolderContext context, Cancell { if (string.IsNullOrEmpty(Project) || !_fileSystem.FileExists(Project)) { - _logger.LogError("Missing/Invalid --project option."); + _logger.LogError($"Missing/Invalid {AspNetConstants.CliOptions.ProjectCliOption} option."); return null; } if (string.IsNullOrEmpty(Model)) { - _logger.LogError("Missing/Invalid --model option."); + _logger.LogError($"Missing/Invalid {AspNetConstants.CliOptions.ModelCliOption} option."); return null; } - if (!string.IsNullOrEmpty(DataContext) && - (string.IsNullOrEmpty(DatabaseProvider) || !PackageConstants.EfConstants.EfPackagesDict.ContainsKey(DatabaseProvider))) + if (!string.IsNullOrEmpty(DataContext)) { - DatabaseProvider = PackageConstants.EfConstants.SqlServer; + if (!SyntaxFacts.IsValidIdentifier(DataContext) || DataContext.Equals("DbContext", StringComparison.OrdinalIgnoreCase)) + { + _logger.LogInformation($"Invalid {AspNetConstants.CliOptions.DataContextOption} option"); + _logger.LogInformation($"Using default '{AspNetConstants.NewDbContext}'"); + DataContext = AspNetConstants.NewDbContext; + } + + if(string.IsNullOrEmpty(DatabaseProvider) || !PackageConstants.EfConstants.EfPackagesDict.ContainsKey(DatabaseProvider)) + { + DatabaseProvider = PackageConstants.EfConstants.SqlServer; + } } var commandSettings = new MinimalApiSettings @@ -142,7 +153,7 @@ public override async Task ExecuteAsync(ScaffolderContext context, Cancell var modelClassSymbol = allClasses.FirstOrDefault(x => x.Name.Equals(settings.Model, StringComparison.OrdinalIgnoreCase)); if (string.IsNullOrEmpty(settings.Model) || modelClassSymbol is null) { - _logger.LogError($"Invalid --model '{settings.Model}' provided"); + _logger.LogError($"Invalid {AspNetConstants.CliOptions.ModelCliOption} '{settings.Model}' provided"); return null; } else @@ -153,7 +164,7 @@ public override async Task ExecuteAsync(ScaffolderContext context, Cancell var validateModelInfoResult = ClassAnalyzers.ValidateModelForCrudScaffolders(modelInfo, _logger); if (!validateModelInfoResult) { - _logger.LogError($"Invalid --model '{settings.Model}'"); + _logger.LogError($"Invalid {AspNetConstants.CliOptions.ModelCliOption} '{settings.Model}'"); return null; } diff --git a/src/dotnet-scaffolding/dotnet-scaffold-aspnet/ScaffoldSteps/ValidateRazorPagesStep.cs b/src/dotnet-scaffolding/dotnet-scaffold-aspnet/ScaffoldSteps/ValidateRazorPagesStep.cs index 4f09e41c6..f9f4ef047 100644 --- a/src/dotnet-scaffolding/dotnet-scaffold-aspnet/ScaffoldSteps/ValidateRazorPagesStep.cs +++ b/src/dotnet-scaffolding/dotnet-scaffold-aspnet/ScaffoldSteps/ValidateRazorPagesStep.cs @@ -1,5 +1,6 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using Microsoft.CodeAnalysis.CSharp; using Microsoft.DotNet.Scaffolding.Core.Scaffolders; using Microsoft.DotNet.Scaffolding.Core.Steps; using Microsoft.DotNet.Scaffolding.Internal.Services; @@ -10,6 +11,7 @@ using Microsoft.DotNet.Tools.Scaffold.AspNet.ScaffoldSteps.Settings; using Microsoft.Extensions.Logging; using Constants = Microsoft.DotNet.Scaffolding.Internal.Constants; +using AspNetConstants = Microsoft.DotNet.Tools.Scaffold.AspNet.Common.Constants; namespace Microsoft.DotNet.Tools.Scaffold.AspNet.ScaffoldSteps; @@ -84,19 +86,19 @@ public override async Task ExecuteAsync(ScaffolderContext context, Cancell { if (string.IsNullOrEmpty(Project) || !_fileSystem.FileExists(Project)) { - _logger.LogError("Missing/Invalid --project option."); + _logger.LogError($"Missing/Invalid {AspNetConstants.CliOptions.ProjectCliOption} option."); return null; } if (string.IsNullOrEmpty(Model)) { - _logger.LogError("Missing/Invalid --model option."); + _logger.LogError($"Missing/Invalid {AspNetConstants.CliOptions.ModelCliOption} option."); return null; } if (string.IsNullOrEmpty(Page)) { - _logger.LogError("Missing/Invalid --page option."); + _logger.LogError($"Missing/Invalid {AspNetConstants.CliOptions.PageTypeOption} option."); return null; } else if (!string.IsNullOrEmpty(Page) && !BlazorCrudHelper.CRUDPages.Contains(Page, StringComparer.OrdinalIgnoreCase)) @@ -107,12 +109,22 @@ public override async Task ExecuteAsync(ScaffolderContext context, Cancell if (string.IsNullOrEmpty(DataContext)) { - _logger.LogError("Missing/Invalid --dataContext option."); + _logger.LogError($"Missing/Invalid {AspNetConstants.CliOptions.DataContextOption} option."); return null; } - else if (string.IsNullOrEmpty(DatabaseProvider) || !PackageConstants.EfConstants.EfPackagesDict.ContainsKey(DatabaseProvider)) + else { - DatabaseProvider = PackageConstants.EfConstants.SqlServer; + if (!SyntaxFacts.IsValidIdentifier(DataContext) || DataContext.Equals("DbContext", StringComparison.OrdinalIgnoreCase)) + { + _logger.LogInformation($"Invalid {AspNetConstants.CliOptions.DataContextOption} option"); + _logger.LogInformation($"Using default '{AspNetConstants.NewDbContext}'"); + DataContext = AspNetConstants.NewDbContext; + } + + if (string.IsNullOrEmpty(DatabaseProvider) || !PackageConstants.EfConstants.EfPackagesDict.ContainsKey(DatabaseProvider)) + { + DatabaseProvider = PackageConstants.EfConstants.SqlServer; + } } return new CrudSettings @@ -141,7 +153,7 @@ public override async Task ExecuteAsync(ScaffolderContext context, Cancell var modelClassSymbol = allClasses.FirstOrDefault(x => x.Name.Equals(settings.Model, StringComparison.OrdinalIgnoreCase)); if (string.IsNullOrEmpty(settings.Model) || modelClassSymbol is null) { - _logger.LogError($"Invalid --model '{settings.Model}'"); + _logger.LogError($"Invalid {AspNetConstants.CliOptions.ModelCliOption} '{settings.Model}'") ; return null; } else @@ -152,7 +164,7 @@ public override async Task ExecuteAsync(ScaffolderContext context, Cancell var validateModelInfoResult = ClassAnalyzers.ValidateModelForCrudScaffolders(modelInfo, _logger); if (!validateModelInfoResult) { - _logger.LogError($"Invalid --model '{settings.Model}'"); + _logger.LogError($"Invalid {AspNetConstants.CliOptions.ModelCliOption} '{settings.Model}'"); return null; } diff --git a/src/dotnet-scaffolding/dotnet-scaffold-aspnet/ScaffoldSteps/ValidateViewsStep.cs b/src/dotnet-scaffolding/dotnet-scaffold-aspnet/ScaffoldSteps/ValidateViewsStep.cs index d6db598d6..59320dbf4 100644 --- a/src/dotnet-scaffolding/dotnet-scaffold-aspnet/ScaffoldSteps/ValidateViewsStep.cs +++ b/src/dotnet-scaffolding/dotnet-scaffold-aspnet/ScaffoldSteps/ValidateViewsStep.cs @@ -8,6 +8,7 @@ using Microsoft.DotNet.Tools.Scaffold.AspNet.Models; using Microsoft.DotNet.Tools.Scaffold.AspNet.ScaffoldSteps.Settings; using Microsoft.Extensions.Logging; +using AspNetConstants = Microsoft.DotNet.Tools.Scaffold.AspNet.Common.Constants; namespace Microsoft.DotNet.Tools.Scaffold.AspNet.ScaffoldSteps; @@ -59,19 +60,19 @@ public override async Task ExecuteAsync(ScaffolderContext context, Cancell { if (string.IsNullOrEmpty(Project) || !_fileSystem.FileExists(Project)) { - _logger.LogError("Missing/Invalid --project option."); + _logger.LogError($"Missing/Invalid {AspNetConstants.CliOptions.ProjectCliOption} option."); return null; } if (string.IsNullOrEmpty(Model)) { - _logger.LogError("Missing/Invalid --model option."); + _logger.LogError($"Missing/Invalid {AspNetConstants.CliOptions.ModelCliOption} option."); return null; } if (string.IsNullOrEmpty(Page)) { - _logger.LogError("Missing/Invalid --page option."); + _logger.LogError($"Missing/Invalid {AspNetConstants.CliOptions.PageTypeOption} option."); return null; } else if (!string.IsNullOrEmpty(Page) && !BlazorCrudHelper.CRUDPages.Contains(Page, StringComparer.OrdinalIgnoreCase)) @@ -102,7 +103,7 @@ public override async Task ExecuteAsync(ScaffolderContext context, Cancell var modelClassSymbol = allClasses.FirstOrDefault(x => x.Name.Equals(settings.Model, StringComparison.OrdinalIgnoreCase)); if (string.IsNullOrEmpty(settings.Model) || modelClassSymbol is null) { - _logger.LogError($"Invalid --model '{settings.Model}'"); + _logger.LogError($"Invalid {AspNetConstants.CliOptions.ModelCliOption} '{settings.Model}'"); return null; } else @@ -113,7 +114,7 @@ public override async Task ExecuteAsync(ScaffolderContext context, Cancell var validateModelInfoResult = ClassAnalyzers.ValidateModelForCrudScaffolders(modelInfo, _logger); if (!validateModelInfoResult) { - _logger.LogError($"Invalid --model '{settings.Model}'"); + _logger.LogError($"Invalid {AspNetConstants.CliOptions.ModelCliOption} '{settings.Model}'"); return null; }