From 755513d349f8bd458311457c98a2c2ec7d2b446e Mon Sep 17 00:00:00 2001 From: Safia Abdalla Date: Wed, 10 Mar 2021 16:50:29 -0800 Subject: [PATCH 1/8] Update SDK to bring in RSG one assembly changes --- global.json | 4 ++-- .../src/Microsoft.AspNetCore.Authentication.AzureAD.UI.csproj | 2 +- .../Microsoft.AspNetCore.Authentication.AzureADB2C.UI.csproj | 2 +- src/Identity/UI/src/Microsoft.AspNetCore.Identity.UI.csproj | 2 +- src/SignalR/clients/ts/yarn.lock | 4 ++++ 5 files changed, 9 insertions(+), 5 deletions(-) create mode 100644 src/SignalR/clients/ts/yarn.lock diff --git a/global.json b/global.json index f229375d1bf4..0bf2154d2a8f 100644 --- a/global.json +++ b/global.json @@ -1,9 +1,9 @@ { "sdk": { - "version": "6.0.100-preview.3.21160.5" + "version": "6.0.100-preview.3.21160.15" }, "tools": { - "dotnet": "6.0.100-preview.3.21160.5", + "dotnet": "6.0.100-preview.3.21160.15", "runtimes": { "dotnet/x64": [ "2.1.25", diff --git a/src/Azure/AzureAD/Authentication.AzureAD.UI/src/Microsoft.AspNetCore.Authentication.AzureAD.UI.csproj b/src/Azure/AzureAD/Authentication.AzureAD.UI/src/Microsoft.AspNetCore.Authentication.AzureAD.UI.csproj index 86f2ac73d86d..d523f6c9616a 100644 --- a/src/Azure/AzureAD/Authentication.AzureAD.UI/src/Microsoft.AspNetCore.Authentication.AzureAD.UI.csproj +++ b/src/Azure/AzureAD/Authentication.AzureAD.UI/src/Microsoft.AspNetCore.Authentication.AzureAD.UI.csproj @@ -6,8 +6,8 @@ $(DefaultNetCoreTargetFramework) aspnetcore;authentication;AzureAD true - Microsoft.AspNetCore.Mvc.ApplicationParts.NullApplicationPartFactory, Microsoft.AspNetCore.Mvc.Core true + RS0016 diff --git a/src/Azure/AzureAD/Authentication.AzureADB2C.UI/src/Microsoft.AspNetCore.Authentication.AzureADB2C.UI.csproj b/src/Azure/AzureAD/Authentication.AzureADB2C.UI/src/Microsoft.AspNetCore.Authentication.AzureADB2C.UI.csproj index e92ddfff11d7..83f08b97c1cd 100644 --- a/src/Azure/AzureAD/Authentication.AzureADB2C.UI/src/Microsoft.AspNetCore.Authentication.AzureADB2C.UI.csproj +++ b/src/Azure/AzureAD/Authentication.AzureADB2C.UI/src/Microsoft.AspNetCore.Authentication.AzureADB2C.UI.csproj @@ -6,8 +6,8 @@ $(DefaultNetCoreTargetFramework) aspnetcore;authentication;AzureADB2C true - Microsoft.AspNetCore.Mvc.ApplicationParts.NullApplicationPartFactory, Microsoft.AspNetCore.Mvc.Core true + RS0016 diff --git a/src/Identity/UI/src/Microsoft.AspNetCore.Identity.UI.csproj b/src/Identity/UI/src/Microsoft.AspNetCore.Identity.UI.csproj index ceebc2861397..83f5175d977c 100644 --- a/src/Identity/UI/src/Microsoft.AspNetCore.Identity.UI.csproj +++ b/src/Identity/UI/src/Microsoft.AspNetCore.Identity.UI.csproj @@ -6,9 +6,9 @@ $(DefaultNetCoreTargetFramework) true aspnetcore;identity;membership;razorpages - Microsoft.AspNetCore.Mvc.ApplicationParts.NullApplicationPartFactory, Microsoft.AspNetCore.Mvc.Core false true + RS0016 Microsoft.AspNetCore.Identity.UI.Views.V4 true diff --git a/src/SignalR/clients/ts/yarn.lock b/src/SignalR/clients/ts/yarn.lock new file mode 100644 index 000000000000..fb57ccd13afb --- /dev/null +++ b/src/SignalR/clients/ts/yarn.lock @@ -0,0 +1,4 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + From 8c2efb6395d84b606ddde8f97749cbead090efb0 Mon Sep 17 00:00:00 2001 From: Safia Abdalla Date: Mon, 15 Mar 2021 08:49:58 -0700 Subject: [PATCH 2/8] Update version to pick up bug fix --- global.json | 4 ++-- src/Identity/UI/src/IdentityBuilderUIExtensions.cs | 2 +- src/Identity/UI/src/Microsoft.AspNetCore.Identity.UI.csproj | 1 - .../UI/src/Properties/AssemblyInfo.ApplicationParts.cs | 4 +--- .../Identity.FunctionalTests/Infrastructure/ServerFactory.cs | 2 +- 5 files changed, 5 insertions(+), 8 deletions(-) diff --git a/global.json b/global.json index 0bf2154d2a8f..788502269e15 100644 --- a/global.json +++ b/global.json @@ -1,9 +1,9 @@ { "sdk": { - "version": "6.0.100-preview.3.21160.15" + "version": "6.0.100-preview.3.21165.3" }, "tools": { - "dotnet": "6.0.100-preview.3.21160.15", + "dotnet": "6.0.100-preview.3.21165.3", "runtimes": { "dotnet/x64": [ "2.1.25", diff --git a/src/Identity/UI/src/IdentityBuilderUIExtensions.cs b/src/Identity/UI/src/IdentityBuilderUIExtensions.cs index 426c3d58facb..4b5948b126a9 100644 --- a/src/Identity/UI/src/IdentityBuilderUIExtensions.cs +++ b/src/Identity/UI/src/IdentityBuilderUIExtensions.cs @@ -47,7 +47,7 @@ public static IdentityBuilder AddDefaultUI(this IdentityBuilder builder) private static readonly IDictionary _assemblyMap = new Dictionary() { - [UIFramework.Bootstrap4] = "Microsoft.AspNetCore.Identity.UI.Views.V4", + [UIFramework.Bootstrap4] = "Microsoft.AspNetCore.Identity.UI.", }; private static void AddRelatedParts(IdentityBuilder builder) diff --git a/src/Identity/UI/src/Microsoft.AspNetCore.Identity.UI.csproj b/src/Identity/UI/src/Microsoft.AspNetCore.Identity.UI.csproj index 83f5175d977c..7145be2cc9aa 100644 --- a/src/Identity/UI/src/Microsoft.AspNetCore.Identity.UI.csproj +++ b/src/Identity/UI/src/Microsoft.AspNetCore.Identity.UI.csproj @@ -9,7 +9,6 @@ false true RS0016 - Microsoft.AspNetCore.Identity.UI.Views.V4 true true diff --git a/src/Identity/UI/src/Properties/AssemblyInfo.ApplicationParts.cs b/src/Identity/UI/src/Properties/AssemblyInfo.ApplicationParts.cs index 85889305bf0c..f743a8cea9d8 100644 --- a/src/Identity/UI/src/Properties/AssemblyInfo.ApplicationParts.cs +++ b/src/Identity/UI/src/Properties/AssemblyInfo.ApplicationParts.cs @@ -1,6 +1,4 @@ // Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. -using Microsoft.AspNetCore.Mvc.ApplicationParts; - -[assembly: RelatedAssembly("Microsoft.AspNetCore.Identity.UI.Views.V4")] \ No newline at end of file +using Microsoft.AspNetCore.Mvc.ApplicationParts; \ No newline at end of file diff --git a/src/Identity/test/Identity.FunctionalTests/Infrastructure/ServerFactory.cs b/src/Identity/test/Identity.FunctionalTests/Infrastructure/ServerFactory.cs index c921df9289ea..d935a12cf2ac 100644 --- a/src/Identity/test/Identity.FunctionalTests/Infrastructure/ServerFactory.cs +++ b/src/Identity/test/Identity.FunctionalTests/Infrastructure/ServerFactory.cs @@ -156,7 +156,7 @@ private static void AddRelatedParts(IServiceCollection services, string framewor var _assemblyMap = new Dictionary() { - [UIFramework.Bootstrap4] = "Microsoft.AspNetCore.Identity.UI.Views.V4", + [UIFramework.Bootstrap4] = "Microsoft.AspNetCore.Identity.UI", }; var mvcBuilder = services From e84fe3bd03ed010a43577b7bf57b796b167c2e68 Mon Sep 17 00:00:00 2001 From: Safia Abdalla Date: Mon, 15 Mar 2021 16:25:38 -0700 Subject: [PATCH 3/8] Update WASM authentication tests --- .../AzureAD/test/FunctionalTests/WebAuthenticationTests.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/Azure/AzureAD/test/FunctionalTests/WebAuthenticationTests.cs b/src/Azure/AzureAD/test/FunctionalTests/WebAuthenticationTests.cs index d724ee2561fd..572ed87113f0 100644 --- a/src/Azure/AzureAD/test/FunctionalTests/WebAuthenticationTests.cs +++ b/src/Azure/AzureAD/test/FunctionalTests/WebAuthenticationTests.cs @@ -31,14 +31,8 @@ public WebAuthenticationTests(WebApplicationFactory fixture) public static TheoryData NotAddedEndpoints => new TheoryData() { - "/AzureAD/Account/AccessDenied", - "/AzureAD/Account/Error", - "/AzureAD/Account/SignedOut", "/AzureAD/Account/SignIn", "/AzureAD/Account/SignOut", - "/AzureADB2C/Account/AccessDenied", - "/AzureADB2C/Account/Error", - "/AzureADB2C/Account/SignedOut", "/AzureADB2C/Account/SignIn", "/AzureADB2C/Account/ResetPassword", "/AzureADB2C/Account/EditProfile", From 0e4c0f06d0c17183dd07f00adcda583ef89f6eaa Mon Sep 17 00:00:00 2001 From: Safia Abdalla Date: Mon, 15 Mar 2021 17:39:16 -0700 Subject: [PATCH 4/8] Remove unneeded assembly attributes file --- .../UI/src/Properties/AssemblyInfo.ApplicationParts.cs | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 src/Identity/UI/src/Properties/AssemblyInfo.ApplicationParts.cs diff --git a/src/Identity/UI/src/Properties/AssemblyInfo.ApplicationParts.cs b/src/Identity/UI/src/Properties/AssemblyInfo.ApplicationParts.cs deleted file mode 100644 index f743a8cea9d8..000000000000 --- a/src/Identity/UI/src/Properties/AssemblyInfo.ApplicationParts.cs +++ /dev/null @@ -1,4 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using Microsoft.AspNetCore.Mvc.ApplicationParts; \ No newline at end of file From 63e71c13a27a379f475840b71503248c12e8aa56 Mon Sep 17 00:00:00 2001 From: Safia Abdalla Date: Mon, 15 Mar 2021 22:06:45 -0700 Subject: [PATCH 5/8] Fix up Startup for test site --- .../ControllersFromServicesWebSite/Startup.cs | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/Mvc/test/WebSites/ControllersFromServicesWebSite/Startup.cs b/src/Mvc/test/WebSites/ControllersFromServicesWebSite/Startup.cs index f5e55e015e1f..9b48db83b90d 100644 --- a/src/Mvc/test/WebSites/ControllersFromServicesWebSite/Startup.cs +++ b/src/Mvc/test/WebSites/ControllersFromServicesWebSite/Startup.cs @@ -25,21 +25,6 @@ public void ConfigureServices(IServiceCollection services) .AddControllersWithViews() .ConfigureApplicationPartManager(manager => manager.ApplicationParts.Clear()) .AddApplicationPart(typeof(TimeScheduleController).GetTypeInfo().Assembly) - .ConfigureApplicationPartManager(manager => - { - manager.ApplicationParts.Add(new TypesPart( - typeof(AnotherController), - typeof(ComponentFromServicesViewComponent), - typeof(InServicesTagHelper))); - - var relatedAssenbly = RelatedAssemblyAttribute - .GetRelatedAssemblies(GetType().Assembly, throwOnError: true) - .SingleOrDefault(); - foreach (var part in CompiledRazorAssemblyApplicationPartFactory.GetDefaultApplicationParts(relatedAssenbly)) - { - manager.ApplicationParts.Add(part); - } - }) .AddControllersAsServices() .AddViewComponentsAsServices() .AddTagHelpersAsServices(); From c19003c36f8f082a81b6b391ded8cbe1f4ea45fb Mon Sep 17 00:00:00 2001 From: Safia Abdalla Date: Wed, 17 Mar 2021 06:09:12 -0700 Subject: [PATCH 6/8] Bump to new SDK --- global.json | 4 ++-- .../ControllersFromServicesWebSite/Startup.cs | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/global.json b/global.json index 788502269e15..c1fee647276e 100644 --- a/global.json +++ b/global.json @@ -1,9 +1,9 @@ { "sdk": { - "version": "6.0.100-preview.3.21165.3" + "version": "6.0.100-preview.3.21167.3" }, "tools": { - "dotnet": "6.0.100-preview.3.21165.3", + "dotnet": "6.0.100-preview.3.21167.3", "runtimes": { "dotnet/x64": [ "2.1.25", diff --git a/src/Mvc/test/WebSites/ControllersFromServicesWebSite/Startup.cs b/src/Mvc/test/WebSites/ControllersFromServicesWebSite/Startup.cs index 9b48db83b90d..4193dac080d3 100644 --- a/src/Mvc/test/WebSites/ControllersFromServicesWebSite/Startup.cs +++ b/src/Mvc/test/WebSites/ControllersFromServicesWebSite/Startup.cs @@ -25,6 +25,18 @@ public void ConfigureServices(IServiceCollection services) .AddControllersWithViews() .ConfigureApplicationPartManager(manager => manager.ApplicationParts.Clear()) .AddApplicationPart(typeof(TimeScheduleController).GetTypeInfo().Assembly) + .ConfigureApplicationPartManager(manager => + { + manager.ApplicationParts.Add(new TypesPart( + typeof(AnotherController), + typeof(ComponentFromServicesViewComponent), + typeof(InServicesTagHelper))); + + foreach (var part in CompiledRazorAssemblyApplicationPartFactory.GetDefaultApplicationParts(Assembly.GetExecutingAssembly())) + { + manager.ApplicationParts.Add(part); + } + }) .AddControllersAsServices() .AddViewComponentsAsServices() .AddTagHelpersAsServices(); From 4986a106e570bc9f6b82ae153293a948380d09ad Mon Sep 17 00:00:00 2001 From: Safia Abdalla Date: Wed, 17 Mar 2021 14:18:08 -0700 Subject: [PATCH 7/8] Clean up consolidated views APIs --- ...nsolidatedMvcViewDocumentClassifierPass.cs | 90 ------------------- .../src/MvcViewDocumentClassifierPass.cs | 19 +++- .../src/PublicAPI.Unshipped.txt | 7 +- .../src/RazorExtensions.cs | 7 +- .../src/RazorPageDocumentClassifierPass.cs | 19 +++- ...idatedMvcViewDocumentClassifierPassTest.cs | 12 +-- 6 files changed, 48 insertions(+), 106 deletions(-) delete mode 100644 src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/ConsolidatedMvcViewDocumentClassifierPass.cs diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/ConsolidatedMvcViewDocumentClassifierPass.cs b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/ConsolidatedMvcViewDocumentClassifierPass.cs deleted file mode 100644 index 715ae3496e89..000000000000 --- a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/ConsolidatedMvcViewDocumentClassifierPass.cs +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. - -using System; -using Microsoft.AspNetCore.Razor.Language; -using Microsoft.AspNetCore.Razor.Language.Intermediate; - -namespace Microsoft.AspNetCore.Mvc.Razor.Extensions -{ - public sealed class ConsolidatedMvcViewDocumentClassifierPass : DocumentClassifierPassBase - { - public static readonly string MvcViewDocumentKind = "mvc.1.0.view"; - - protected override string DocumentKind => MvcViewDocumentKind; - - protected override bool IsMatch(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode) => true; - - protected override void OnDocumentStructureCreated( - RazorCodeDocument codeDocument, - NamespaceDeclarationIntermediateNode @namespace, - ClassDeclarationIntermediateNode @class, - MethodDeclarationIntermediateNode method) - { - base.OnDocumentStructureCreated(codeDocument, @namespace, @class, method); - - if (!codeDocument.TryComputeNamespace(fallbackToRootNamespace: false, out var namespaceName)) - { - @namespace.Content = "AspNetCoreGeneratedDocument"; - } - else - { - @namespace.Content = namespaceName; - } - - if (!TryComputeClassName(codeDocument, out var className)) - { - // It's possible for a Razor document to not have a file path. - // Eg. When we try to generate code for an in memory document like default imports. - var checksum = Checksum.BytesToString(codeDocument.Source.GetChecksum()); - @class.ClassName = $"AspNetCore_{checksum}"; - } - else - { - @class.ClassName = className; - } - - @class.BaseType = "global::Microsoft.AspNetCore.Mvc.Razor.RazorPage"; - @class.Modifiers.Clear(); - @class.Modifiers.Add("internal"); - @class.Modifiers.Add("sealed"); - - method.MethodName = "ExecuteAsync"; - method.Modifiers.Clear(); - method.Modifiers.Add("public"); - method.Modifiers.Add("async"); - method.Modifiers.Add("override"); - method.ReturnType = $"global::{typeof(System.Threading.Tasks.Task).FullName}"; - } - - private bool TryComputeClassName(RazorCodeDocument codeDocument, out string className) - { - var filePath = codeDocument.Source.RelativePath ?? codeDocument.Source.FilePath; - if (string.IsNullOrEmpty(filePath)) - { - className = null; - return false; - } - - className = GetClassNameFromPath(filePath); - return true; - } - - private static string GetClassNameFromPath(string path) - { - const string cshtmlExtension = ".cshtml"; - - if (string.IsNullOrEmpty(path)) - { - return path; - } - - if (path.EndsWith(cshtmlExtension, StringComparison.OrdinalIgnoreCase)) - { - path = path.Substring(0, path.Length - cshtmlExtension.Length); - } - - return CSharpIdentifier.SanitizeIdentifier(path); - } - } -} \ No newline at end of file diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/MvcViewDocumentClassifierPass.cs b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/MvcViewDocumentClassifierPass.cs index 7ab07afc8ba2..f09bde6b78e3 100644 --- a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/MvcViewDocumentClassifierPass.cs +++ b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/MvcViewDocumentClassifierPass.cs @@ -9,12 +9,19 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions { public class MvcViewDocumentClassifierPass : DocumentClassifierPassBase { + private bool _useConsolidatedMvcViews = false; + public static readonly string MvcViewDocumentKind = "mvc.1.0.view"; protected override string DocumentKind => MvcViewDocumentKind; protected override bool IsMatch(RazorCodeDocument codeDocument, DocumentIntermediateNode documentNode) => true; + public MvcViewDocumentClassifierPass(bool useConsolidatedMvcViews = false) + { + _useConsolidatedMvcViews = useConsolidatedMvcViews; + } + protected override void OnDocumentStructureCreated( RazorCodeDocument codeDocument, NamespaceDeclarationIntermediateNode @namespace, @@ -25,7 +32,7 @@ protected override void OnDocumentStructureCreated( if (!codeDocument.TryComputeNamespace(fallbackToRootNamespace: false, out var namespaceName)) { - @namespace.Content = "AspNetCore"; + @namespace.Content = _useConsolidatedMvcViews ? "AspNetCoreGeneratedDocument" : "AspNetCore"; } else { @@ -47,7 +54,15 @@ protected override void OnDocumentStructureCreated( @class.BaseType = "global::Microsoft.AspNetCore.Mvc.Razor.RazorPage"; @class.Modifiers.Clear(); - @class.Modifiers.Add("public"); + if (_useConsolidatedMvcViews) + { + @class.Modifiers.Add("internal"); + @class.Modifiers.Add("sealed"); + } + else + { + @class.Modifiers.Add("public"); + } method.MethodName = "ExecuteAsync"; method.Modifiers.Clear(); diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/PublicAPI.Unshipped.txt b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/PublicAPI.Unshipped.txt index e4a5fa72ae36..4e70623e7865 100644 --- a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/PublicAPI.Unshipped.txt +++ b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/PublicAPI.Unshipped.txt @@ -1,4 +1,5 @@ #nullable enable -Microsoft.AspNetCore.Mvc.Razor.Extensions.ConsolidatedMvcViewDocumentClassifierPass -Microsoft.AspNetCore.Mvc.Razor.Extensions.ConsolidatedMvcViewDocumentClassifierPass.ConsolidatedMvcViewDocumentClassifierPass() -> void -~static readonly Microsoft.AspNetCore.Mvc.Razor.Extensions.ConsolidatedMvcViewDocumentClassifierPass.MvcViewDocumentKind -> string \ No newline at end of file +*REMOVED*Microsoft.AspNetCore.Mvc.Razor.Extensions.MvcViewDocumentClassifierPass.MvcViewDocumentClassifierPass() -> void +*REMOVED*Microsoft.AspNetCore.Mvc.Razor.Extensions.RazorPageDocumentClassifierPass.RazorPageDocumentClassifierPass() -> void +Microsoft.AspNetCore.Mvc.Razor.Extensions.MvcViewDocumentClassifierPass.MvcViewDocumentClassifierPass(bool useConsolidatedMvcViews = false) -> void +Microsoft.AspNetCore.Mvc.Razor.Extensions.RazorPageDocumentClassifierPass.RazorPageDocumentClassifierPass(bool useConsolidatedMvcViews = false) -> void \ No newline at end of file diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/RazorExtensions.cs b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/RazorExtensions.cs index 0c7b298aa738..5e22c450e4ed 100644 --- a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/RazorExtensions.cs +++ b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/RazorExtensions.cs @@ -36,15 +36,16 @@ public static void Register(RazorProjectEngineBuilder builder) builder.Features.Add(new ModelExpressionPass()); builder.Features.Add(new PagesPropertyInjectionPass()); builder.Features.Add(new ViewComponentTagHelperPass()); - builder.Features.Add(new RazorPageDocumentClassifierPass()); + if (builder.Configuration.UseConsolidatedMvcViews) { - builder.Features.Add(new ConsolidatedMvcViewDocumentClassifierPass()); + builder.Features.Add(new RazorPageDocumentClassifierPass(useConsolidatedMvcViews: true)); + builder.Features.Add(new MvcViewDocumentClassifierPass(useConsolidatedMvcViews: true)); } else { - builder.Features.Add(new MvcViewDocumentClassifierPass()); + builder.Features.Add(new RazorPageDocumentClassifierPass()); builder.Features.Add(new MvcViewDocumentClassifierPass()); } builder.Features.Add(new MvcImportProjectFeature()); diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/RazorPageDocumentClassifierPass.cs b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/RazorPageDocumentClassifierPass.cs index 567754cd663a..ca81aa25282b 100644 --- a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/RazorPageDocumentClassifierPass.cs +++ b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/RazorPageDocumentClassifierPass.cs @@ -11,9 +11,16 @@ namespace Microsoft.AspNetCore.Mvc.Razor.Extensions { public class RazorPageDocumentClassifierPass : DocumentClassifierPassBase { + private bool _useConsolidatedMvcViews = false; + public static readonly string RazorPageDocumentKind = "mvc.1.0.razor-page"; public static readonly string RouteTemplateKey = "RouteTemplate"; + public RazorPageDocumentClassifierPass(bool useConsolidatedMvcViews = false) + { + _useConsolidatedMvcViews = useConsolidatedMvcViews; + } + private static readonly RazorProjectEngine LeadingDirectiveParsingEngine = RazorProjectEngine.Create( RazorConfiguration.Create(RazorLanguageVersion.Version_3_0, "leading-directive-parser", Array.Empty()), RazorProjectFileSystem.Create("/"), @@ -50,7 +57,7 @@ protected override void OnDocumentStructureCreated( if (!codeDocument.TryComputeNamespace(fallbackToRootNamespace: false, out var namespaceName)) { - @namespace.Content = "AspNetCore"; + @namespace.Content = _useConsolidatedMvcViews ? "AspNetCoreGeneratedDocument" : "AspNetCore"; } else { @@ -71,7 +78,15 @@ protected override void OnDocumentStructureCreated( @class.BaseType = "global::Microsoft.AspNetCore.Mvc.RazorPages.Page"; @class.Modifiers.Clear(); - @class.Modifiers.Add("public"); + if (_useConsolidatedMvcViews) + { + @class.Modifiers.Add("internal"); + @class.Modifiers.Add("sealed"); + } + else + { + @class.Modifiers.Add("public"); + } method.MethodName = "ExecuteAsync"; method.Modifiers.Clear(); diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/ConsolidatedMvcViewDocumentClassifierPassTest.cs b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/ConsolidatedMvcViewDocumentClassifierPassTest.cs index b4c6ed145ed7..d8d5751f60b9 100644 --- a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/ConsolidatedMvcViewDocumentClassifierPassTest.cs +++ b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/test/ConsolidatedMvcViewDocumentClassifierPassTest.cs @@ -19,7 +19,7 @@ public void ConsolidatedMvcViewDocumentClassifierPass_SetsDifferentNamespace() var projectEngine = CreateProjectEngine(); var irDocument = CreateIRDocument(projectEngine, codeDocument); - var pass = new ConsolidatedMvcViewDocumentClassifierPass + var pass = new MvcViewDocumentClassifierPass(useConsolidatedMvcViews: true) { Engine = projectEngine.Engine }; @@ -42,7 +42,7 @@ public void ConsolidatedMvcViewDocumentClassifierPass_SetsClass() var projectEngine = CreateProjectEngine(); var irDocument = CreateIRDocument(projectEngine, codeDocument); - var pass = new ConsolidatedMvcViewDocumentClassifierPass + var pass = new MvcViewDocumentClassifierPass(useConsolidatedMvcViews: true) { Engine = projectEngine.Engine }; @@ -67,7 +67,7 @@ public void MvcViewDocumentClassifierPass_NullFilePath_SetsClass() var projectEngine = CreateProjectEngine(); var irDocument = CreateIRDocument(projectEngine, codeDocument); - var pass = new ConsolidatedMvcViewDocumentClassifierPass + var pass = new MvcViewDocumentClassifierPass(useConsolidatedMvcViews: true) { Engine = projectEngine.Engine }; @@ -86,7 +86,7 @@ public void MvcViewDocumentClassifierPass_NullFilePath_SetsClass() [Theory] [InlineData("/Views/Home/Index.cshtml", "_Views_Home_Index")] [InlineData("/Areas/MyArea/Views/Home/About.cshtml", "_Areas_MyArea_Views_Home_About")] - public void MvcViewDocumentClassifierPass_UsesRelativePathToGenerateTypeName(string relativePath, string expected) + public void ConsolidatedMvcViewDocumentClassifierPass_UsesRelativePathToGenerateTypeName(string relativePath, string expected) { // Arrange var properties = new RazorSourceDocumentProperties(filePath: "ignored", relativePath: relativePath); @@ -94,7 +94,7 @@ public void MvcViewDocumentClassifierPass_UsesRelativePathToGenerateTypeName(str var projectEngine = CreateProjectEngine(); var irDocument = CreateIRDocument(projectEngine, codeDocument); - var pass = new ConsolidatedMvcViewDocumentClassifierPass + var pass = new MvcViewDocumentClassifierPass(useConsolidatedMvcViews: true) { Engine = projectEngine.Engine }; @@ -117,7 +117,7 @@ public void ConsolidatedMvcViewDocumentClassifierPass_SetsUpExecuteAsyncMethod() var projectEngine = CreateProjectEngine(); var irDocument = CreateIRDocument(projectEngine, codeDocument); - var pass = new ConsolidatedMvcViewDocumentClassifierPass + var pass = new MvcViewDocumentClassifierPass(useConsolidatedMvcViews: true) { Engine = projectEngine.Engine }; From 79e023c9072bad1cac4f9ed98715fdeff3c6d8c5 Mon Sep 17 00:00:00 2001 From: Safia Abdalla Date: Wed, 17 Mar 2021 14:28:51 -0700 Subject: [PATCH 8/8] Update RazorExtensions.cs --- .../src/RazorExtensions.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/RazorExtensions.cs b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/RazorExtensions.cs index 5e22c450e4ed..7f74487d1532 100644 --- a/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/RazorExtensions.cs +++ b/src/Razor/Microsoft.AspNetCore.Mvc.Razor.Extensions/src/RazorExtensions.cs @@ -36,7 +36,6 @@ public static void Register(RazorProjectEngineBuilder builder) builder.Features.Add(new ModelExpressionPass()); builder.Features.Add(new PagesPropertyInjectionPass()); builder.Features.Add(new ViewComponentTagHelperPass()); - if (builder.Configuration.UseConsolidatedMvcViews) { @@ -45,7 +44,8 @@ public static void Register(RazorProjectEngineBuilder builder) } else { - builder.Features.Add(new RazorPageDocumentClassifierPass()); builder.Features.Add(new MvcViewDocumentClassifierPass()); + builder.Features.Add(new RazorPageDocumentClassifierPass()); + builder.Features.Add(new MvcViewDocumentClassifierPass()); } builder.Features.Add(new MvcImportProjectFeature());