From 9adaac275633db9f05258d85afc70ff20152e42e Mon Sep 17 00:00:00 2001 From: Deep Choudhery Date: Mon, 9 Dec 2024 22:08:36 -0800 Subject: [PATCH] fix AccountLayout, also MSBuildProjectService for blazor projects. --- eng/Versions.DotNetScaffold.props | 2 +- scripts/install-scaffold-all.cmd | 2 +- .../Services/MSBuildProjectService.cs | 11 +++++------ .../ScaffoldSteps/ValidateIdentityStep.cs | 3 +++ .../Templates/BlazorIdentity/Shared/AccountLayout.cs | 4 ++-- .../Templates/BlazorIdentity/Shared/AccountLayout.tt | 4 ++-- 6 files changed, 14 insertions(+), 12 deletions(-) diff --git a/eng/Versions.DotNetScaffold.props b/eng/Versions.DotNetScaffold.props index c49807c67..280ec8a35 100644 --- a/eng/Versions.DotNetScaffold.props +++ b/eng/Versions.DotNetScaffold.props @@ -1,7 +1,7 @@ -9.0.0 +9.0.1 preview 10 False diff --git a/scripts/install-scaffold-all.cmd b/scripts/install-scaffold-all.cmd index 18717b685..91ed853be 100644 --- a/scripts/install-scaffold-all.cmd +++ b/scripts/install-scaffold-all.cmd @@ -1,4 +1,4 @@ -set VERSION=10.0.0-dev +set VERSION=9.0.1-dev set DEFAULT_NUPKG_PATH=%userprofile%/.nuget/packages set SRC_DIR=%cd% set NUPKG=artifacts/packages/Debug/Shipping/ diff --git a/src/dotnet-scaffolding/Microsoft.DotNet.Scaffolding.Roslyn/Services/MSBuildProjectService.cs b/src/dotnet-scaffolding/Microsoft.DotNet.Scaffolding.Roslyn/Services/MSBuildProjectService.cs index 933b2f85b..062ebce31 100644 --- a/src/dotnet-scaffolding/Microsoft.DotNet.Scaffolding.Roslyn/Services/MSBuildProjectService.cs +++ b/src/dotnet-scaffolding/Microsoft.DotNet.Scaffolding.Roslyn/Services/MSBuildProjectService.cs @@ -9,7 +9,7 @@ namespace Microsoft.DotNet.Scaffolding.Roslyn.Services; public class MSBuildProjectService : IMSBuildProjectService { private readonly string _projectPath; - private Build.Evaluation.Project? _project; + private Project? _project; private bool _initialized; private readonly object _initLock = new(); public MSBuildProjectService(string projectPath) @@ -53,13 +53,12 @@ private void Initialize(bool refresh = false) return; } - //try loading MSBuild project the faster way. - _project = new Project(_projectPath, null, null, new Build.Evaluation.ProjectCollection(), ProjectLoadSettings.IgnoreMissingImports); - //if fails, use the longer way using GLobalProjectCollection. - if (_project is null) + try { - _project = ProjectCollection.GlobalProjectCollection.LoadProject(_projectPath); + //try loading MSBuild project the faster way. + _project = new Project(_projectPath, null, null, new ProjectCollection(), ProjectLoadSettings.IgnoreMissingImports); } + catch (Exception) { } } } diff --git a/src/dotnet-scaffolding/dotnet-scaffold-aspnet/ScaffoldSteps/ValidateIdentityStep.cs b/src/dotnet-scaffolding/dotnet-scaffold-aspnet/ScaffoldSteps/ValidateIdentityStep.cs index 5fbf0ccaf..c5f6b61f6 100644 --- a/src/dotnet-scaffolding/dotnet-scaffold-aspnet/ScaffoldSteps/ValidateIdentityStep.cs +++ b/src/dotnet-scaffolding/dotnet-scaffold-aspnet/ScaffoldSteps/ValidateIdentityStep.cs @@ -162,10 +162,12 @@ public override async Task ExecuteAsync(ScaffolderContext context, Cancell string identityNamespace = string.Empty; string userClassNamespace = string.Empty; + string identityLayoutNamespace = string.Empty; var projectName = Path.GetFileNameWithoutExtension(settings.Project); if (!string.IsNullOrEmpty(projectName)) { identityNamespace = settings.BlazorScenario ? $"{projectName}.Components.Account" : $"{projectName}.Areas.Identity"; + identityLayoutNamespace = settings.BlazorScenario ? $"{projectName}.Components.Layout.MainLayout" : string.Empty; userClassNamespace = $"{projectName}.Data"; } @@ -176,6 +178,7 @@ public override async Task ExecuteAsync(ScaffolderContext context, Cancell IdentityNamespace = identityNamespace, UserClassName = AspNetConstants.Identity.UserClassName, UserClassNamespace = userClassNamespace, + IdentityLayoutNamespace = identityLayoutNamespace, BaseOutputPath = projectDirectory, Overwrite = settings.Overwrite }; diff --git a/src/dotnet-scaffolding/dotnet-scaffold-aspnet/Templates/BlazorIdentity/Shared/AccountLayout.cs b/src/dotnet-scaffolding/dotnet-scaffold-aspnet/Templates/BlazorIdentity/Shared/AccountLayout.cs index ba948fb77..1ffd0b755 100644 --- a/src/dotnet-scaffolding/dotnet-scaffold-aspnet/Templates/BlazorIdentity/Shared/AccountLayout.cs +++ b/src/dotnet-scaffolding/dotnet-scaffold-aspnet/Templates/BlazorIdentity/Shared/AccountLayout.cs @@ -122,8 +122,8 @@ public virtual void Initialize() } else { - this.Error("The type \'Microsoft.DotNet.Tools.Scaffold.AspNet.Models.BlazorIdentityModel\' of t" + - "he parameter \'Model\' did not match the type of the data passed to the template."); + this.Error("The type \'Microsoft.DotNet.Tools.Scaffold.AspNet.Models.IdentityModel\' of the par" + + "ameter \'Model\' did not match the type of the data passed to the template."); } } } diff --git a/src/dotnet-scaffolding/dotnet-scaffold-aspnet/Templates/BlazorIdentity/Shared/AccountLayout.tt b/src/dotnet-scaffolding/dotnet-scaffold-aspnet/Templates/BlazorIdentity/Shared/AccountLayout.tt index 25252dca9..6c37d2e89 100644 --- a/src/dotnet-scaffolding/dotnet-scaffold-aspnet/Templates/BlazorIdentity/Shared/AccountLayout.tt +++ b/src/dotnet-scaffolding/dotnet-scaffold-aspnet/Templates/BlazorIdentity/Shared/AccountLayout.tt @@ -6,9 +6,9 @@ @using <#= Model.UserClassNamespace #> @inherits LayoutComponentBase <# -if (!string.IsNullOrEmpty(Model.BlazorLayoutNamespace)) +if (!string.IsNullOrEmpty(Model.IdentityLayoutNamespace)) { -#>@layout <#= Model.BlazorLayoutNamespace #> +#>@layout <#= Model.IdentityLayoutNamespace #> <#} #> @inject NavigationManager NavigationManager