Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increase support for view-only pages #178

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions R4MVC.sln
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29318.209
# Visual Studio Version 17
VisualStudioVersion = 17.4.33205.214
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".solution", ".solution", "{1E8F7AFD-5175-406A-9736-817C75DA1142}"
ProjectSection(SolutionItems) = preProject
Expand Down Expand Up @@ -33,8 +33,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNetSimple.Test", "test\A
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SampleModels", "samples\SampleModels\SampleModels.csproj", "{8F6D7DDE-98A0-4808-BD91-C1CF2E0AAC69}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNetSimple.NetCore2", "samples\AspNetSimple.NetCore2\AspNetSimple.NetCore2.csproj", "{4609AF1D-0942-43DA-9979-F92972A22A7A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -73,10 +71,6 @@ Global
{8F6D7DDE-98A0-4808-BD91-C1CF2E0AAC69}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8F6D7DDE-98A0-4808-BD91-C1CF2E0AAC69}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8F6D7DDE-98A0-4808-BD91-C1CF2E0AAC69}.Release|Any CPU.Build.0 = Release|Any CPU
{4609AF1D-0942-43DA-9979-F92972A22A7A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4609AF1D-0942-43DA-9979-F92972A22A7A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4609AF1D-0942-43DA-9979-F92972A22A7A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4609AF1D-0942-43DA-9979-F92972A22A7A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -90,7 +84,6 @@ Global
{86B3FF8A-284E-4070-9120-D343366B18E2} = {B9FF7D5E-784B-4C4A-B6E6-286C1E3D131E}
{75510011-133B-4A05-AD09-A399CDBFA3A5} = {30626644-0E8A-4610-A0A9-274E91F1A037}
{8F6D7DDE-98A0-4808-BD91-C1CF2E0AAC69} = {B9FF7D5E-784B-4C4A-B6E6-286C1E3D131E}
{4609AF1D-0942-43DA-9979-F92972A22A7A} = {B9FF7D5E-784B-4C4A-B6E6-286C1E3D131E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B90C19F2-2B5E-42AD-AE1D-27AD17E4DDB4}
Expand Down
1 change: 0 additions & 1 deletion RunGenerate.bat
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ IF NOT "%1"=="" SET CONFIGURATION=%1

@ECHO ON
.\src\R4Mvc.Tools\bin\%CONFIGURATION%\net472\R4Mvc.Tools.exe generate -p .\samples\AspNetSimple\AspNetSimple.csproj
.\src\R4Mvc.Tools\bin\%CONFIGURATION%\net472\R4Mvc.Tools.exe generate -p .\samples\AspNetSimple.NetCore2\AspNetSimple.NetCore2.csproj
.\src\R4Mvc.Tools\bin\%CONFIGURATION%\net472\R4Mvc.Tools.exe generate -p .\samples\AspNetFeatureFolders\AspNetFeatureFolders.csproj
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: 1.0.0.{build}

image: Visual Studio 2019
image: Visual Studio 2022

configuration: Release
skip_tags: true
Expand Down
2 changes: 1 addition & 1 deletion samples/AspNetFeatureFolders/AspNetFeatureFolders.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down
16 changes: 0 additions & 16 deletions samples/AspNetSimple/Pages/Categories/Inner/NoModel.cshtml.cs

This file was deleted.

This file was deleted.

16 changes: 0 additions & 16 deletions samples/AspNetSimple/Pages/Categories/NoModel.cshtml.cs

This file was deleted.

31 changes: 0 additions & 31 deletions samples/AspNetSimple/Pages/Categories/NoModel.cshtml.generated.cs

This file was deleted.

This file was deleted.

This file was deleted.

16 changes: 0 additions & 16 deletions samples/AspNetSimple/Pages/NoModel.cshtml.cs

This file was deleted.

31 changes: 0 additions & 31 deletions samples/AspNetSimple/Pages/NoModel.cshtml.generated.cs

This file was deleted.

54 changes: 54 additions & 0 deletions samples/AspNetSimple/R4Mvc.generated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public static partial class MVCPages
public static R4Mvc.NoDirectChildPagesPathClass NoDirectChildPages => s_NoDirectChildPages;
public static readonly AspNetSimple.Pages.DefaultModel Default = new AspNetSimple.Pages.R4MVC_DefaultModel();
public static readonly R4Mvc.NoModelModel NoModel = new R4Mvc.NoModelModel();
public static readonly R4Mvc.NotARazorPageModel NotARazorPage = new R4Mvc.NotARazorPageModel();
}

namespace R4Mvc
Expand Down Expand Up @@ -558,4 +559,57 @@ public R4Mvc_Microsoft_AspNetCore_Mvc_RazorPages_RedirectToRouteResult(string pa

public RouteValueDictionary RouteValueDictionary { get; set; }
}

namespace R4Mvc
{
public partial class NoDirectChildPages_AnotherEmptyLayer_NestedPages_IndexModel : IR4ActionResult
{
[GeneratedCode("R4Mvc", "1.0"), DebuggerNonUserCode]
string IR4ActionResult.Protocol => null;
[GeneratedCode("R4Mvc", "1.0")]
RouteValueDictionary m_RouteValueDictionary = new RouteValueDictionary{{"Page", "/NoDirectChildPages/AnotherEmptyLayer/NestedPages/Index"}};
[GeneratedCode("R4Mvc", "1.0"), DebuggerNonUserCode]
RouteValueDictionary IR4ActionResult.RouteValueDictionary => m_RouteValueDictionary;
}

public partial class NoModelModel : IR4ActionResult
{
[GeneratedCode("R4Mvc", "1.0"), DebuggerNonUserCode]
string IR4ActionResult.Protocol => null;
[GeneratedCode("R4Mvc", "1.0")]
RouteValueDictionary m_RouteValueDictionary = new RouteValueDictionary{{"Page", "/NoModel"}};
[GeneratedCode("R4Mvc", "1.0"), DebuggerNonUserCode]
RouteValueDictionary IR4ActionResult.RouteValueDictionary => m_RouteValueDictionary;
}

public partial class Categories_NoModelModel : IR4ActionResult
{
[GeneratedCode("R4Mvc", "1.0"), DebuggerNonUserCode]
string IR4ActionResult.Protocol => null;
[GeneratedCode("R4Mvc", "1.0")]
RouteValueDictionary m_RouteValueDictionary = new RouteValueDictionary{{"Page", "/Categories/NoModel"}};
[GeneratedCode("R4Mvc", "1.0"), DebuggerNonUserCode]
RouteValueDictionary IR4ActionResult.RouteValueDictionary => m_RouteValueDictionary;
}

public partial class Categories_Inner_NoModelModel : IR4ActionResult
{
[GeneratedCode("R4Mvc", "1.0"), DebuggerNonUserCode]
string IR4ActionResult.Protocol => null;
[GeneratedCode("R4Mvc", "1.0")]
RouteValueDictionary m_RouteValueDictionary = new RouteValueDictionary{{"Page", "/Categories/Inner/NoModel"}};
[GeneratedCode("R4Mvc", "1.0"), DebuggerNonUserCode]
RouteValueDictionary IR4ActionResult.RouteValueDictionary => m_RouteValueDictionary;
}

public partial class NotARazorPageModel : IR4ActionResult
{
[GeneratedCode("R4Mvc", "1.0"), DebuggerNonUserCode]
string IR4ActionResult.Protocol => null;
[GeneratedCode("R4Mvc", "1.0")]
RouteValueDictionary m_RouteValueDictionary = new RouteValueDictionary{{"Page", "/NotARazorPage"}};
[GeneratedCode("R4Mvc", "1.0"), DebuggerNonUserCode]
RouteValueDictionary IR4ActionResult.RouteValueDictionary => m_RouteValueDictionary;
}
}
#pragma warning restore 1591, 3008, 3009, 0108
2 changes: 1 addition & 1 deletion samples/AspNetSimple/r4mvc.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"R4MvcNamespace": "R4Mvc",
"LinksNamespace": "Links",
"SplitIntoMultipleFiles": true,
"SplitViewOnlyPagesIntoMultipleFiles": true,
"SplitViewOnlyPagesIntoMultipleFiles": false,
"StaticFilesPath": "wwwroot",
"ExcludedStaticFileExtensions": null,
"ReferencedNamespaces": [
Expand Down
8 changes: 6 additions & 2 deletions src/R4Mvc.Tools/Commands/GenerateCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,13 @@ public async Task Run(string projectPath, IConfiguration configuration, string[]
if (hasPagesSupport)
{
var definitions = _pageRewriter.RewritePages(compilation);
pages = _pageViewLocators.SelectMany(x => x.Find(projectRoot)).Where(p => p.IsPage).ToList();
pages = _pageViewLocators.SelectMany(x => x.Find(projectRoot)).ToList();

foreach (var page in pages)
// Some of the entries in pages can be partial views i.e. not an actual Razor Page.
// They will have no associated code-behind class in the project, so filter them out when fetching definitions.
var razorPages = pages.Where(p => p.IsRazorPage).ToList();

foreach (var page in razorPages)
{
page.Definition = definitions.FirstOrDefault(d => d.GetFilePath() == (page.FilePath + ".cs"));
}
Expand Down
6 changes: 3 additions & 3 deletions src/R4Mvc.Tools/Locators/DefaultRazorPageViewLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public IEnumerable<PageView> Find(string projectRoot)

private PageView GetView(string projectRoot, string pagesRoot, string filePath)
{
bool isPage = false;
bool isRazorPage = false;
using (var file = File.OpenRead(filePath))
using (var reader = new StreamReader(file))
{
Expand All @@ -44,15 +44,15 @@ private PageView GetView(string projectRoot, string pagesRoot, string filePath)
break;
if (trimmedLine.StartsWith("@page"))
{
isPage = true;
isRazorPage = true;
break;
}
}
}

var relativePath = filePath.GetRelativePath(projectRoot).Replace("\\", "/");
var pagePath = filePath.GetRelativePath(pagesRoot).Replace("\\", "/").TrimEnd(".cshtml");
return new PageView(Path.GetFileNameWithoutExtension(filePath), filePath, relativePath, pagePath, isPage);
return new PageView(Path.GetFileNameWithoutExtension(filePath), filePath, relativePath, pagePath, isRazorPage);
}
}
}
Loading