From 7f4aa60a456383169a374e3970cb580c88d9b08f Mon Sep 17 00:00:00 2001 From: Pranav K Date: Wed, 5 Apr 2017 12:45:39 -0700 Subject: [PATCH] Add support for precompiling RazorPages --- RazorViewCompilation.sln | 9 +- ...rCodeGenerator.cs => ManifestGenerator.cs} | 68 +++++++++++- .../Internal/PrecompileRunCommand.cs | 28 +++-- .../Internal/ViewCompilationInfo.cs | 3 + ...spNetCore.Mvc.Razor.ViewCompilation.csproj | 2 +- .../Infrastructure/ApplicationTestFixture.cs | 8 +- ...zor.ViewCompilation.FunctionalTests.csproj | 1 + .../RazorPagesAppTest.cs | 100 ++++++++++++++++++ .../Resources/RazorPages.Index.txt | 2 + ...ages.Nested1.Nested2.PageWithTagHelper.txt | 2 + .../Resources/RazorPages.PageWithModel.txt | 2 + .../Resources/RazorPages.PageWithRoute.txt | 2 + .../ClassLibraryTagHelper.csproj | 2 + .../RazorPagesApp/Pages/Auth/Index.cshtml | 2 + testapps/RazorPagesApp/Pages/Index.cshtml | 3 + testapps/RazorPagesApp/Pages/Login.cshtml | 3 + testapps/RazorPagesApp/Pages/MyPageModel.cs | 16 +++ .../Nested1/Nested2/PageWithTagHelper.cshtml | 4 + .../Pages/Nested1/_ViewImports.cshtml | 1 + .../RazorPagesApp/Pages/PageWithModel.cshtml | 4 + .../RazorPagesApp/Pages/PageWithRoute.cshtml | 4 + .../RazorPagesApp/Pages/_PageStart.cshtml | 3 + .../RazorPagesApp/Pages/_ViewImports.cshtml | 1 + testapps/RazorPagesApp/Program.cs | 26 +++++ testapps/RazorPagesApp/RazorPagesApp.csproj | 18 ++++ testapps/RazorPagesApp/Startup.cs | 38 +++++++ .../RazorPagesApp/Views/Shared/_Layout.cshtml | 3 + 27 files changed, 339 insertions(+), 16 deletions(-) rename src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/{ViewInfoContainerCodeGenerator.cs => ManifestGenerator.cs} (59%) create mode 100644 test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/RazorPagesAppTest.cs create mode 100644 test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/RazorPages.Index.txt create mode 100644 test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/RazorPages.Nested1.Nested2.PageWithTagHelper.txt create mode 100644 test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/RazorPages.PageWithModel.txt create mode 100644 test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/RazorPages.PageWithRoute.txt create mode 100644 testapps/RazorPagesApp/Pages/Auth/Index.cshtml create mode 100644 testapps/RazorPagesApp/Pages/Index.cshtml create mode 100644 testapps/RazorPagesApp/Pages/Login.cshtml create mode 100644 testapps/RazorPagesApp/Pages/MyPageModel.cs create mode 100644 testapps/RazorPagesApp/Pages/Nested1/Nested2/PageWithTagHelper.cshtml create mode 100644 testapps/RazorPagesApp/Pages/Nested1/_ViewImports.cshtml create mode 100644 testapps/RazorPagesApp/Pages/PageWithModel.cshtml create mode 100644 testapps/RazorPagesApp/Pages/PageWithRoute.cshtml create mode 100644 testapps/RazorPagesApp/Pages/_PageStart.cshtml create mode 100644 testapps/RazorPagesApp/Pages/_ViewImports.cshtml create mode 100644 testapps/RazorPagesApp/Program.cs create mode 100644 testapps/RazorPagesApp/RazorPagesApp.csproj create mode 100644 testapps/RazorPagesApp/Startup.cs create mode 100644 testapps/RazorPagesApp/Views/Shared/_Layout.cshtml diff --git a/RazorViewCompilation.sln b/RazorViewCompilation.sln index 4386216946..eb7796e638 100644 --- a/RazorViewCompilation.sln +++ b/RazorViewCompilation.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 -VisualStudioVersion = 15.0.26228.4 +VisualStudioVersion = 15.0.26329.2 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.AspNetCore.Mvc.Razor.ViewCompilation", "src\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation\Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.csproj", "{4339FC9B-AEC6-442A-B413-A41555ED76C7}" EndProject @@ -51,6 +51,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApplicationUsingPrecompiled EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApplicationWithTagHelpers", "testapps\ApplicationWithTagHelpers\ApplicationWithTagHelpers.csproj", "{08552602-37E7-48A7-95A2-BB1A1F57C804}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RazorPagesApp", "testapps\RazorPagesApp\RazorPagesApp.csproj", "{779BACC4-B20E-4F73-A9C7-350443CF1941}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -117,6 +119,10 @@ Global {08552602-37E7-48A7-95A2-BB1A1F57C804}.Debug|Any CPU.Build.0 = Debug|Any CPU {08552602-37E7-48A7-95A2-BB1A1F57C804}.Release|Any CPU.ActiveCfg = Release|Any CPU {08552602-37E7-48A7-95A2-BB1A1F57C804}.Release|Any CPU.Build.0 = Release|Any CPU + {779BACC4-B20E-4F73-A9C7-350443CF1941}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {779BACC4-B20E-4F73-A9C7-350443CF1941}.Debug|Any CPU.Build.0 = Debug|Any CPU + {779BACC4-B20E-4F73-A9C7-350443CF1941}.Release|Any CPU.ActiveCfg = Release|Any CPU + {779BACC4-B20E-4F73-A9C7-350443CF1941}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -137,5 +143,6 @@ Global {68BB859F-E5D5-407E-9DFB-8CD478EFE90D} = {0DC7C88C-E3DB-46DF-B47E-AC5ECB2A16B7} {037F4B73-75FB-4570-A38A-9109B580168C} = {0DC7C88C-E3DB-46DF-B47E-AC5ECB2A16B7} {08552602-37E7-48A7-95A2-BB1A1F57C804} = {0DC7C88C-E3DB-46DF-B47E-AC5ECB2A16B7} + {779BACC4-B20E-4F73-A9C7-350443CF1941} = {0DC7C88C-E3DB-46DF-B47E-AC5ECB2A16B7} EndGlobalSection EndGlobal diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/ViewInfoContainerCodeGenerator.cs b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/ManifestGenerator.cs similarity index 59% rename from src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/ViewInfoContainerCodeGenerator.cs rename to src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/ManifestGenerator.cs index 52eee2242f..d29b46e8fc 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/ViewInfoContainerCodeGenerator.cs +++ b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/ManifestGenerator.cs @@ -9,15 +9,16 @@ using System.Text; using Microsoft.AspNetCore.Mvc.ApplicationParts; using Microsoft.AspNetCore.Mvc.Razor.Compilation; using Microsoft.AspNetCore.Mvc.Razor.Internal; +using Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.Text; namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal { - internal class ViewInfoContainerCodeGenerator + internal class ManifestGenerator { - public ViewInfoContainerCodeGenerator( + public ManifestGenerator( CSharpCompiler compiler, CSharpCompilation compilation) { @@ -29,8 +30,35 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal public CSharpCompilation Compilation { get; private set; } - public void AddViewFactory(IList result) + public void GenerateManifest(IList results) { + var views = new List(); + var pages = new List(); + + for (var i = 0; i < results.Count; i++) + { + var result = results[i]; + if (result.RouteTemplate != null) + { + pages.Add(result); + } + else + { + views.Add(result); + } + } + + GeneratePageManifest(pages); + GenerateViewManifest(views); + } + + private void GenerateViewManifest(IList result) + { + if (result.Count == 0) + { + return; + } + var precompiledViewsArray = new StringBuilder(); foreach (var item in result) { @@ -56,6 +84,40 @@ namespace {ViewsFeatureProvider.ViewInfoContainerNamespace} Compilation = Compilation.AddSyntaxTrees(syntaxTree); } + private void GeneratePageManifest(IList pages) + { + if (pages.Count == 0) + { + return; + } + + var precompiledViewsArray = new StringBuilder(); + foreach (var item in pages) + { + var path = item.ViewFileInfo.ViewEnginePath; + var routeTemplate = item.RouteTemplate; + var escapedRouteTemplate = routeTemplate.Replace("\"", "\\\""); + precompiledViewsArray.AppendLine( + $"new global::{typeof(CompiledPageInfo).FullName}(@\"{path}\", typeof({item.TypeName}), \"{escapedRouteTemplate}\"),"); + } + + var factoryContent = $@" +namespace {CompiledPageFeatureProvider.CompiledPageManifestNamespace} +{{ + public class {CompiledPageFeatureProvider.CompiledPageManifestTypeName} : global::{typeof(CompiledPageManifest).FullName} + {{ + public {CompiledPageFeatureProvider.CompiledPageManifestTypeName}() : base(new[] + {{ + {precompiledViewsArray} + }}) + {{ + }} + }} +}}"; + var syntaxTree = Compiler.CreateSyntaxTree(SourceText.From(factoryContent)); + Compilation = Compilation.AddSyntaxTrees(syntaxTree); + } + public void AddAssemblyMetadata( AssemblyName applicationAssemblyName, CompilationOptions compilationOptions) diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/PrecompileRunCommand.cs b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/PrecompileRunCommand.cs index e21de3786b..bfaf5d2aae 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/PrecompileRunCommand.cs +++ b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/PrecompileRunCommand.cs @@ -9,7 +9,10 @@ using System.Reflection; using System.Text; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.Razor.Compilation; +using Microsoft.AspNetCore.Mvc.Razor.Extensions; using Microsoft.AspNetCore.Mvc.Razor.Internal; +using Microsoft.AspNetCore.Mvc.RazorPages.Infrastructure; +using Microsoft.AspNetCore.Razor.Language; using Microsoft.CodeAnalysis; using Microsoft.CodeAnalysis.CSharp; using Microsoft.CodeAnalysis.CSharp.Syntax; @@ -75,7 +78,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal return 1; } - var precompileAssemblyName = $"{Options.ApplicationName}{ViewsFeatureProvider.PrecompiledViewsAssemblySuffix}"; + var precompileAssemblyName = $"{Options.ApplicationName}{CompiledViewManfiest.PrecompiledViewsAssemblySuffix}"; var compilation = CompileViews(results, precompileAssemblyName); var resources = GetResources(results); @@ -189,8 +192,8 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal MvcServiceProvider.ViewEngineOptions.CompilationCallback(compilationContext); compilation = compilationContext.Compilation; - var codeGenerator = new ViewInfoContainerCodeGenerator(compiler, compilation); - codeGenerator.AddViewFactory(results); + var codeGenerator = new ManifestGenerator(compiler, compilation); + codeGenerator.GenerateManifest(results); var assemblyName = new AssemblyName(Options.ApplicationName); assemblyName = Assembly.Load(assemblyName).GetName(); @@ -236,11 +239,20 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal Parallel.For(0, results.Length, ParalellOptions, i => { var fileInfo = files[i]; + var templateEngine = MvcServiceProvider.TemplateEngine; + ViewCompilationInfo compilationInfo; using (var fileStream = fileInfo.CreateReadStream()) { - var csharpDocument = MvcServiceProvider.TemplateEngine.GenerateCode(fileInfo.ViewEnginePath); - results[i] = new ViewCompilationInfo(fileInfo, csharpDocument); + var csharpDocument = templateEngine.GenerateCode(fileInfo.ViewEnginePath); + compilationInfo = new ViewCompilationInfo(fileInfo, csharpDocument); } + + if (PageDirectiveFeature.TryGetPageDirective(fileInfo.CreateReadStream, out var template)) + { + compilationInfo.RouteTemplate = template; + } + + results[i] = compilationInfo; }); return results; @@ -250,7 +262,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal { var contentRoot = Options.ContentRootOption.Value(); var viewFiles = Options.ViewsToCompile; - var relativeFiles = new List(viewFiles.Count); + var viewFileInfo = new List(viewFiles.Count); var trimLength = contentRoot.EndsWith("/") ? contentRoot.Length - 1 : contentRoot.Length; for (var i = 0; i < viewFiles.Count; i++) @@ -259,11 +271,11 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal if (fullPath.StartsWith(contentRoot, StringComparison.OrdinalIgnoreCase)) { var viewEnginePath = fullPath.Substring(trimLength).Replace('\\', '/'); - relativeFiles.Add(new ViewFileInfo(fullPath, viewEnginePath)); + viewFileInfo.Add(new ViewFileInfo(fullPath, viewEnginePath)); } } - return relativeFiles; + return viewFileInfo; } private string ReadTypeInfo(CSharpCompilation compilation, SyntaxTree syntaxTree) diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/ViewCompilationInfo.cs b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/ViewCompilationInfo.cs index 02f0c2679e..9f1e88d864 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/ViewCompilationInfo.cs +++ b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Internal/ViewCompilationInfo.cs @@ -1,6 +1,7 @@ // 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.Razor.Extensions; using Microsoft.AspNetCore.Razor.Language; namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal @@ -20,5 +21,7 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.Internal public RazorCSharpDocument CSharpDocument { get; } public string TypeName { get; set; } + + public string RouteTemplate { get; set; } } } diff --git a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.csproj b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.csproj index 71200034c0..f641b03b42 100644 --- a/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.csproj +++ b/src/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.csproj @@ -18,7 +18,7 @@ - + diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Infrastructure/ApplicationTestFixture.cs b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Infrastructure/ApplicationTestFixture.cs index 69ccd33519..8648eea6d0 100644 --- a/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Infrastructure/ApplicationTestFixture.cs +++ b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Infrastructure/ApplicationTestFixture.cs @@ -19,15 +19,17 @@ namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation { ApplicationName = applicationName; DeploymentResult = CreateDeployment(); - HttpClient = new HttpClient(); - HttpClient.BaseAddress = new Uri(DeploymentResult.ApplicationBaseUri); + HttpClient = new HttpClient + { + BaseAddress = new Uri(DeploymentResult.ApplicationBaseUri), + }; } public string ApplicationName { get; } public string ApplicationPath => ApplicationPaths.GetTestAppDirectory(ApplicationName); - public HttpClient HttpClient { get; } + public HttpClient HttpClient { get; private set; } public ILogger Logger { get; private set; } diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests.csproj b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests.csproj index cacf21dda9..2590a5231e 100644 --- a/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests.csproj +++ b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests.csproj @@ -5,6 +5,7 @@ netcoreapp2.0 $(DefineConstants);__remove_this_to__GENERATE_BASELINES + $(DefineConstants);GENERATE_BASELINES diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/RazorPagesAppTest.cs b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/RazorPagesAppTest.cs new file mode 100644 index 0000000000..0f6ff5ffa1 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/RazorPagesAppTest.cs @@ -0,0 +1,100 @@ +// 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.Threading.Tasks; +using Microsoft.AspNetCore.Server.IntegrationTesting; +using Xunit; + +namespace Microsoft.AspNetCore.Mvc.Razor.ViewCompilation +{ + public class RazorPagesAppTest : IClassFixture + { + public RazorPagesAppTest(TestFixture fixture) + { + Fixture = fixture; + } + + public ApplicationTestFixture Fixture { get; } + + [Fact] + public async Task Precompilation_WorksForIndexPage_UsingFolderName() + { + // Act + var response = await Fixture.HttpClient.GetStringWithRetryAsync( + "/", + Fixture.Logger); + + // Assert + TestEmbeddedResource.AssertContent("RazorPages.Index.txt", response); + } + + [Fact] + public async Task Precompilation_WorksForIndexPage_UsingFileName() + { + // Act + var response = await Fixture.HttpClient.GetStringWithRetryAsync( + "/Index", + Fixture.Logger); + + // Assert + TestEmbeddedResource.AssertContent("RazorPages.Index.txt", response); + } + + [Fact] + public async Task Precompilation_WorksForPageWithModel() + { + // Act + var response = await Fixture.HttpClient.GetStringWithRetryAsync( + "/PageWithModel?person=Dan", + Fixture.Logger); + + // Assert + TestEmbeddedResource.AssertContent("RazorPages.PageWithModel.txt", response); + } + + [Fact] + public async Task Precompilation_WorksForPageWithRoute() + { + // Act + var response = await Fixture.HttpClient.GetStringWithRetryAsync( + "/PageWithRoute/Dan", + Fixture.Logger); + + // Assert + TestEmbeddedResource.AssertContent("RazorPages.PageWithRoute.txt", response); + } + + [Fact] + public async Task Precompilation_WorksForPageInNestedFolder() + { + // Act + var response = await Fixture.HttpClient.GetStringWithRetryAsync( + "/Nested1/Nested2/PageWithTagHelper", + Fixture.Logger); + + // Assert + TestEmbeddedResource.AssertContent("RazorPages.Nested1.Nested2.PageWithTagHelper.txt", response); + } + + [Fact] + public async Task Precompilation_WorksWithPageConventions() + { + // Act + var response = await RetryHelper.RetryRequest( + () => Fixture.HttpClient.GetAsync("/Auth/Index"), + Fixture.Logger, + retryCount: 5); + + // Assert + Assert.Equal("/Login?ReturnUrl=%2FAuth%2FIndex", response.RequestMessage.RequestUri.PathAndQuery); + } + + public class TestFixture : ApplicationTestFixture + { + public TestFixture() + : base("RazorPagesApp") + { + } + } + } +} diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/RazorPages.Index.txt b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/RazorPages.Index.txt new file mode 100644 index 0000000000..ff3f1d2458 --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/RazorPages.Index.txt @@ -0,0 +1,2 @@ + +Hello world! \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/RazorPages.Nested1.Nested2.PageWithTagHelper.txt b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/RazorPages.Nested1.Nested2.PageWithTagHelper.txt new file mode 100644 index 0000000000..9cf6533fae --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/RazorPages.Nested1.Nested2.PageWithTagHelper.txt @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/RazorPages.PageWithModel.txt b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/RazorPages.PageWithModel.txt new file mode 100644 index 0000000000..1cdbdae92e --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/RazorPages.PageWithModel.txt @@ -0,0 +1,2 @@ + +Greetings Dan! \ No newline at end of file diff --git a/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/RazorPages.PageWithRoute.txt b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/RazorPages.PageWithRoute.txt new file mode 100644 index 0000000000..1cdbdae92e --- /dev/null +++ b/test/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation.FunctionalTests/Resources/RazorPages.PageWithRoute.txt @@ -0,0 +1,2 @@ + +Greetings Dan! \ No newline at end of file diff --git a/testapps/ClassLibraryTagHelper/ClassLibraryTagHelper.csproj b/testapps/ClassLibraryTagHelper/ClassLibraryTagHelper.csproj index 95e97bdf29..9b2e3f2908 100644 --- a/testapps/ClassLibraryTagHelper/ClassLibraryTagHelper.csproj +++ b/testapps/ClassLibraryTagHelper/ClassLibraryTagHelper.csproj @@ -1,4 +1,6 @@  + + netstandard1.6 diff --git a/testapps/RazorPagesApp/Pages/Auth/Index.cshtml b/testapps/RazorPagesApp/Pages/Auth/Index.cshtml new file mode 100644 index 0000000000..3ec4fdbc18 --- /dev/null +++ b/testapps/RazorPagesApp/Pages/Auth/Index.cshtml @@ -0,0 +1,2 @@ +@page +Can't see me diff --git a/testapps/RazorPagesApp/Pages/Index.cshtml b/testapps/RazorPagesApp/Pages/Index.cshtml new file mode 100644 index 0000000000..0ac52dc2e9 --- /dev/null +++ b/testapps/RazorPagesApp/Pages/Index.cshtml @@ -0,0 +1,3 @@ +@page + +Hello world! \ No newline at end of file diff --git a/testapps/RazorPagesApp/Pages/Login.cshtml b/testapps/RazorPagesApp/Pages/Login.cshtml new file mode 100644 index 0000000000..0ac52dc2e9 --- /dev/null +++ b/testapps/RazorPagesApp/Pages/Login.cshtml @@ -0,0 +1,3 @@ +@page + +Hello world! \ No newline at end of file diff --git a/testapps/RazorPagesApp/Pages/MyPageModel.cs b/testapps/RazorPagesApp/Pages/MyPageModel.cs new file mode 100644 index 0000000000..a2aa5b0b04 --- /dev/null +++ b/testapps/RazorPagesApp/Pages/MyPageModel.cs @@ -0,0 +1,16 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace RazorPagesApp +{ + public class MyPageModel : PageModel + { + public string Name { get; private set; } + + public IActionResult OnGet(string person) + { + Name = person; + return View(); + } + } +} diff --git a/testapps/RazorPagesApp/Pages/Nested1/Nested2/PageWithTagHelper.cshtml b/testapps/RazorPagesApp/Pages/Nested1/Nested2/PageWithTagHelper.cshtml new file mode 100644 index 0000000000..d26fb586b2 --- /dev/null +++ b/testapps/RazorPagesApp/Pages/Nested1/Nested2/PageWithTagHelper.cshtml @@ -0,0 +1,4 @@ +@page + \ No newline at end of file diff --git a/testapps/RazorPagesApp/Pages/Nested1/_ViewImports.cshtml b/testapps/RazorPagesApp/Pages/Nested1/_ViewImports.cshtml new file mode 100644 index 0000000000..9018c7897f --- /dev/null +++ b/testapps/RazorPagesApp/Pages/Nested1/_ViewImports.cshtml @@ -0,0 +1 @@ +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers \ No newline at end of file diff --git a/testapps/RazorPagesApp/Pages/PageWithModel.cshtml b/testapps/RazorPagesApp/Pages/PageWithModel.cshtml new file mode 100644 index 0000000000..51286a72bd --- /dev/null +++ b/testapps/RazorPagesApp/Pages/PageWithModel.cshtml @@ -0,0 +1,4 @@ +@page +@model MyPageModel + +Greetings @Model.Name! \ No newline at end of file diff --git a/testapps/RazorPagesApp/Pages/PageWithRoute.cshtml b/testapps/RazorPagesApp/Pages/PageWithRoute.cshtml new file mode 100644 index 0000000000..75f483b8bf --- /dev/null +++ b/testapps/RazorPagesApp/Pages/PageWithRoute.cshtml @@ -0,0 +1,4 @@ +@page "{person}" +@model MyPageModel + +Greetings @Model.Name! \ No newline at end of file diff --git a/testapps/RazorPagesApp/Pages/_PageStart.cshtml b/testapps/RazorPagesApp/Pages/_PageStart.cshtml new file mode 100644 index 0000000000..77b65af1c3 --- /dev/null +++ b/testapps/RazorPagesApp/Pages/_PageStart.cshtml @@ -0,0 +1,3 @@ +@{ + Layout = "_Layout"; +} \ No newline at end of file diff --git a/testapps/RazorPagesApp/Pages/_ViewImports.cshtml b/testapps/RazorPagesApp/Pages/_ViewImports.cshtml new file mode 100644 index 0000000000..fcd6f860b6 --- /dev/null +++ b/testapps/RazorPagesApp/Pages/_ViewImports.cshtml @@ -0,0 +1 @@ +@using RazorPagesApp diff --git a/testapps/RazorPagesApp/Program.cs b/testapps/RazorPagesApp/Program.cs new file mode 100644 index 0000000000..6007a0387a --- /dev/null +++ b/testapps/RazorPagesApp/Program.cs @@ -0,0 +1,26 @@ +using System.IO; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; + +namespace RazorPagesApp +{ + public class Program + { + public static void Main(string[] args) + { + var config = new ConfigurationBuilder() + .AddCommandLine(args) + .AddEnvironmentVariables(prefix: "ASPNETCORE_") + .Build(); + + var host = new WebHostBuilder() + .UseConfiguration(config) + .UseKestrel() + .UseContentRoot(Directory.GetCurrentDirectory()) + .UseStartup() + .Build(); + + host.Run(); + } + } +} diff --git a/testapps/RazorPagesApp/RazorPagesApp.csproj b/testapps/RazorPagesApp/RazorPagesApp.csproj new file mode 100644 index 0000000000..f141b468b9 --- /dev/null +++ b/testapps/RazorPagesApp/RazorPagesApp.csproj @@ -0,0 +1,18 @@ + + + + netcoreapp2.0 + true + + + + + + + + + + + + + diff --git a/testapps/RazorPagesApp/Startup.cs b/testapps/RazorPagesApp/Startup.cs new file mode 100644 index 0000000000..72b94f8024 --- /dev/null +++ b/testapps/RazorPagesApp/Startup.cs @@ -0,0 +1,38 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; + +namespace RazorPagesApp +{ + public class Startup : IDesignTimeMvcBuilderConfiguration + { + public void ConfigureServices(IServiceCollection services) + { + var builder = services.AddMvc(); + ConfigureMvc(builder); + } + + public void Configure(IApplicationBuilder app, ILoggerFactory loggerFactory) + { + loggerFactory.AddConsole(); + app.UseCookieAuthentication(new CookieAuthenticationOptions + { + LoginPath = "/Login", + AutomaticAuthenticate = true, + AutomaticChallenge = true + }); + + app.UseMvc(); + } + + public void ConfigureMvc(IMvcBuilder builder) + { + builder.AddRazorPagesOptions(options => + { + options.RootDirectory = "/Pages"; + options.AuthorizeFolder("/Auth"); + }); + } + } +} diff --git a/testapps/RazorPagesApp/Views/Shared/_Layout.cshtml b/testapps/RazorPagesApp/Views/Shared/_Layout.cshtml new file mode 100644 index 0000000000..20b44df8d1 --- /dev/null +++ b/testapps/RazorPagesApp/Views/Shared/_Layout.cshtml @@ -0,0 +1,3 @@ + +@RenderBody() + \ No newline at end of file