diff --git a/src/Middleware/tools/RazorPageGenerator/Program.cs b/src/Middleware/tools/RazorPageGenerator/Program.cs index 1e9b08e755d6..c45e975e1f97 100644 --- a/src/Middleware/tools/RazorPageGenerator/Program.cs +++ b/src/Middleware/tools/RazorPageGenerator/Program.cs @@ -19,12 +19,14 @@ public static int Main(string[] args) { Console.WriteLine("Invalid argument(s)."); Console.WriteLine(@"Usage: - dotnet razorpagegenerator [path] + dotnet razorpagegenerator [directory path [#line path prefix]] Examples: - dotnet razorpagegenerator Microsoft.AspNetCore.Diagnostics.RazorViews - - processes all views in ""Views"" subfolders of the current directory - dotnet razorpagegenerator Microsoft.AspNetCore.Diagnostics.RazorViews c:\project - - processes all views in ""Views"" subfolders of c:\project directory + dotnet razorpagegenerator Microsoft.AspNetCore.Diagnostics.RazorViews + - process all views in ""Views"" subfolders of the current directory; use filename in #line directives + dotnet razorpagegenerator Microsoft.AspNetCore.Diagnostics.RazorViews c:\project + - process all views in ""Views"" subfolders of c:\project directory; use filename in #line directives + dotnet razorpagegenerator Microsoft.AspNetCore.Diagnostics.RazorViews c:\project ../Views/ + - process all views in ""Views"" subfolders of c:\project directory; use ""../Views/{filename}"" in line directives "); return 1; @@ -33,7 +35,9 @@ dotnet razorpagegenerator Microsoft.AspNetCore.Diagnostics.RazorViews var rootNamespace = args[0]; var targetProjectDirectory = args.Length > 1 ? args[1] : Directory.GetCurrentDirectory(); var projectEngine = CreateProjectEngine(rootNamespace, targetProjectDirectory); - var results = MainCore(projectEngine, targetProjectDirectory); + + var physicalPathPrefix = args.Length > 2 ? args[2] : string.Empty; + var results = MainCore(projectEngine, targetProjectDirectory, physicalPathPrefix); foreach (var result in results) { @@ -79,7 +83,10 @@ @using System.Threading.Tasks return projectEngine; } - public static IList MainCore(RazorProjectEngine projectEngine, string targetProjectDirectory) + public static IList MainCore( + RazorProjectEngine projectEngine, + string targetProjectDirectory, + string physicalPathPrefix) { var viewDirectories = Directory.EnumerateDirectories(targetProjectDirectory, "Views", SearchOption.AllDirectories); var fileCount = 0; @@ -94,14 +101,14 @@ public static IList MainCore(RazorProjectEngine projec if (!cshtmlFiles.Any()) { - Console.WriteLine(" No .cshtml files were found."); + Console.WriteLine(" No .cshtml or .razor files were found."); continue; } foreach (var item in cshtmlFiles) { Console.WriteLine(" Generating code file for view {0}...", item.FileName); - results.Add(GenerateCodeFile(projectEngine, item)); + results.Add(GenerateCodeFile(projectEngine, item, physicalPathPrefix)); Console.WriteLine(" Done!"); fileCount++; } @@ -110,9 +117,12 @@ public static IList MainCore(RazorProjectEngine projec return results; } - private static RazorPageGeneratorResult GenerateCodeFile(RazorProjectEngine projectEngine, RazorProjectItem projectItem) + private static RazorPageGeneratorResult GenerateCodeFile( + RazorProjectEngine projectEngine, + RazorProjectItem projectItem, + string physicalPathPrefix) { - var projectItemWrapper = new FileSystemRazorProjectItemWrapper(projectItem); + var projectItemWrapper = new FileSystemRazorProjectItemWrapper(projectItem, physicalPathPrefix); var codeDocument = projectEngine.Process(projectItemWrapper); var cSharpDocument = codeDocument.GetCSharpDocument(); if (cSharpDocument.Diagnostics.Any()) @@ -163,17 +173,19 @@ private class FileSystemRazorProjectItemWrapper : RazorProjectItem { private readonly RazorProjectItem _source; - public FileSystemRazorProjectItemWrapper(RazorProjectItem item) + public FileSystemRazorProjectItemWrapper(RazorProjectItem item, string physicalPathPrefix) { _source = item; + + // Mask the full name since we don't want a developer's local file paths to be committed. + PhysicalPath = $"{physicalPathPrefix}{_source.FileName}"; } public override string BasePath => _source.BasePath; public override string FilePath => _source.FilePath; - // Mask the full name since we don't want a developer's local file paths to be commited. - public override string PhysicalPath => _source.FileName; + public override string PhysicalPath { get; } public override bool Exists => _source.Exists; @@ -213,4 +225,4 @@ private string ProcessFileIncludes() } } } -} \ No newline at end of file +} diff --git a/src/Shared/ErrorPage/ErrorPage.Designer.cs b/src/Shared/ErrorPage/ErrorPage.Designer.cs index 402e3ad49478..7e92a1fd7f74 100644 --- a/src/Shared/ErrorPage/ErrorPage.Designer.cs +++ b/src/Shared/ErrorPage/ErrorPage.Designer.cs @@ -5,42 +5,42 @@ namespace Microsoft.AspNetCore.Hosting.Views #line hidden using System.Threading.Tasks; #nullable restore -#line 1 "ErrorPage.cshtml" +#line 1 "Views/ErrorPage.cshtml" using System; #line default #line hidden #nullable disable #nullable restore -#line 2 "ErrorPage.cshtml" +#line 2 "Views/ErrorPage.cshtml" using System.Globalization; #line default #line hidden #nullable disable #nullable restore -#line 3 "ErrorPage.cshtml" +#line 3 "Views/ErrorPage.cshtml" using System.Linq; #line default #line hidden #nullable disable #nullable restore -#line 4 "ErrorPage.cshtml" +#line 4 "Views/ErrorPage.cshtml" using System.Net; #line default #line hidden #nullable disable #nullable restore -#line 5 "ErrorPage.cshtml" +#line 5 "Views/ErrorPage.cshtml" using System.Reflection; #line default #line hidden #nullable disable #nullable restore -#line 6 "ErrorPage.cshtml" +#line 6 "Views/ErrorPage.cshtml" using Microsoft.AspNetCore.Hosting.Views; #line default @@ -53,7 +53,7 @@ internal class ErrorPage : Microsoft.Extensions.RazorViews.BaseView { WriteLiteral("\r\n"); #nullable restore -#line 17 "ErrorPage.cshtml" +#line 17 "Views/ErrorPage.cshtml" var location = string.Empty; @@ -63,7 +63,7 @@ internal class ErrorPage : Microsoft.Extensions.RazorViews.BaseView WriteLiteral("\r\nAn error occurred while starting the application. "); #nullable restore -#line 226 "ErrorPage.cshtml" +#line 232 "Views/ErrorPage.cshtml" foreach (var errorDetail in Model.ErrorDetails) { @@ -289,7 +295,7 @@ .page .length { #nullable disable WriteLiteral("
"); #nullable restore -#line 228 "ErrorPage.cshtml" +#line 234 "Views/ErrorPage.cshtml" Write(errorDetail.Error.GetType().Name); #line default @@ -297,7 +303,7 @@ .page .length { #nullable disable WriteLiteral(": "); #nullable restore -#line 228 "ErrorPage.cshtml" +#line 234 "Views/ErrorPage.cshtml" Output.Write(HtmlEncodeAndReplaceLineBreaks(errorDetail.Error.Message)); #line default @@ -305,7 +311,7 @@ .page .length { #nullable disable WriteLiteral("
\r\n"); #nullable restore -#line 229 "ErrorPage.cshtml" +#line 235 "Views/ErrorPage.cshtml" var firstFrame = errorDetail.StackFrames.FirstOrDefault(); if (firstFrame != null) @@ -320,17 +326,17 @@ .page .length { #nullable disable WriteLiteral("

"); #nullable restore -#line 237 "ErrorPage.cshtml" +#line 243 "Views/ErrorPage.cshtml" Write(location); #line default #line hidden #nullable disable WriteLiteral(" in

\r\n"); #nullable restore -#line 238 "ErrorPage.cshtml" +#line 244 "Views/ErrorPage.cshtml" } else if (!string.IsNullOrEmpty(location)) { @@ -364,7 +370,7 @@ .page .length { #nullable disable WriteLiteral("

"); #nullable restore -#line 241 "ErrorPage.cshtml" +#line 247 "Views/ErrorPage.cshtml" Write(location); #line default @@ -372,7 +378,7 @@ .page .length { #nullable disable WriteLiteral("

\r\n"); #nullable restore -#line 242 "ErrorPage.cshtml" +#line 248 "Views/ErrorPage.cshtml" } else { @@ -382,7 +388,7 @@ .page .length { #nullable disable WriteLiteral("

Unknown location

\r\n"); #nullable restore -#line 246 "ErrorPage.cshtml" +#line 252 "Views/ErrorPage.cshtml" } var reflectionTypeLoadException = errorDetail.Error as ReflectionTypeLoadException; @@ -396,7 +402,7 @@ .page .length { #nullable disable WriteLiteral("

Loader Exceptions:

\r\n
    \r\n"); #nullable restore -#line 255 "ErrorPage.cshtml" +#line 261 "Views/ErrorPage.cshtml" foreach (var ex in reflectionTypeLoadException.LoaderExceptions) { @@ -405,7 +411,7 @@ .page .length { #nullable disable WriteLiteral("
  • "); #nullable restore -#line 257 "ErrorPage.cshtml" +#line 263 "Views/ErrorPage.cshtml" Write(ex.Message); #line default @@ -413,7 +419,7 @@ .page .length { #nullable disable WriteLiteral("
  • \r\n"); #nullable restore -#line 258 "ErrorPage.cshtml" +#line 264 "Views/ErrorPage.cshtml" } #line default @@ -421,7 +427,7 @@ .page .length { #nullable disable WriteLiteral("
\r\n"); #nullable restore -#line 260 "ErrorPage.cshtml" +#line 266 "Views/ErrorPage.cshtml" } } } @@ -431,7 +437,7 @@ .page .length { #nullable disable WriteLiteral("
\r\n
    \r\n"); #nullable restore -#line 265 "ErrorPage.cshtml" +#line 271 "Views/ErrorPage.cshtml" var exceptionCount = 0; var stackFrameCount = 0; @@ -443,7 +449,7 @@ .page .length { #line hidden #nullable disable #nullable restore -#line 271 "ErrorPage.cshtml" +#line 277 "Views/ErrorPage.cshtml" foreach (var errorDetail in Model.ErrorDetails) { exceptionCount++; @@ -454,7 +460,7 @@ .page .length { #nullable disable WriteLiteral("
  • \r\n

    "); #nullable restore -#line 276 "ErrorPage.cshtml" +#line 282 "Views/ErrorPage.cshtml" Write(errorDetail.Error.GetType().Name); #line default @@ -462,7 +468,7 @@ .page .length { #nullable disable WriteLiteral(": "); #nullable restore -#line 276 "ErrorPage.cshtml" +#line 282 "Views/ErrorPage.cshtml" Write(errorDetail.Error.Message); #line default @@ -470,7 +476,7 @@ .page .length { #nullable disable WriteLiteral("

    \r\n
      \r\n"); #nullable restore -#line 278 "ErrorPage.cshtml" +#line 284 "Views/ErrorPage.cshtml" foreach (var frame in errorDetail.StackFrames) { stackFrameCount++; @@ -480,10 +486,10 @@ .page .length { #line hidden #nullable disable WriteLiteral("
    • "); #nullable restore -#line 301 "ErrorPage.cshtml" +#line 307 "Views/ErrorPage.cshtml" Write(line); #line default @@ -605,7 +611,7 @@ .page .length { #nullable disable WriteLiteral("
    • \r\n"); #nullable restore -#line 302 "ErrorPage.cshtml" +#line 308 "Views/ErrorPage.cshtml" } #line default @@ -613,17 +619,17 @@ .page .length { #nullable disable WriteLiteral(" \r\n"); #nullable restore -#line 304 "ErrorPage.cshtml" +#line 310 "Views/ErrorPage.cshtml" } #line default #line hidden #nullable disable WriteLiteral("\r\n
\r\n"); #nullable restore -#line 323 "ErrorPage.cshtml" +#line 329 "Views/ErrorPage.cshtml" } #line default @@ -716,7 +722,7 @@ .page .length { #nullable disable WriteLiteral(" \r\n"); #nullable restore -#line 325 "ErrorPage.cshtml" +#line 331 "Views/ErrorPage.cshtml" } #line default @@ -730,17 +736,17 @@ .page .length {
\r\n
\r\n