@@ -19,12 +19,14 @@ public static int Main(string[] args)
19
19
{
20
20
Console . WriteLine ( "Invalid argument(s)." ) ;
21
21
Console . WriteLine ( @"Usage:
22
- dotnet razorpagegenerator <root-namespace-of-views> [path]
22
+ dotnet razorpagegenerator <root-namespace-of-views> [directory path [#line path prefix] ]
23
23
Examples:
24
- dotnet razorpagegenerator Microsoft.AspNetCore.Diagnostics.RazorViews
25
- - processes all views in ""Views"" subfolders of the current directory
26
- dotnet razorpagegenerator Microsoft.AspNetCore.Diagnostics.RazorViews c:\project
27
- - processes all views in ""Views"" subfolders of c:\project directory
24
+ dotnet razorpagegenerator Microsoft.AspNetCore.Diagnostics.RazorViews
25
+ - process all views in ""Views"" subfolders of the current directory; use filename in #line directives
26
+ dotnet razorpagegenerator Microsoft.AspNetCore.Diagnostics.RazorViews c:\project
27
+ - process all views in ""Views"" subfolders of c:\project directory; use filename in #line directives
28
+ dotnet razorpagegenerator Microsoft.AspNetCore.Diagnostics.RazorViews c:\project ../Views/
29
+ - process all views in ""Views"" subfolders of c:\project directory; use ""../Views/{filename}"" in line directives
28
30
" ) ;
29
31
30
32
return 1 ;
@@ -33,7 +35,9 @@ dotnet razorpagegenerator Microsoft.AspNetCore.Diagnostics.RazorViews
33
35
var rootNamespace = args [ 0 ] ;
34
36
var targetProjectDirectory = args . Length > 1 ? args [ 1 ] : Directory . GetCurrentDirectory ( ) ;
35
37
var projectEngine = CreateProjectEngine ( rootNamespace , targetProjectDirectory ) ;
36
- var results = MainCore ( projectEngine , targetProjectDirectory ) ;
38
+
39
+ var physicalPathPrefix = args . Length > 2 ? args [ 2 ] : string . Empty ;
40
+ var results = MainCore ( projectEngine , targetProjectDirectory , physicalPathPrefix ) ;
37
41
38
42
foreach ( var result in results )
39
43
{
@@ -79,7 +83,10 @@ @using System.Threading.Tasks
79
83
return projectEngine ;
80
84
}
81
85
82
- public static IList < RazorPageGeneratorResult > MainCore ( RazorProjectEngine projectEngine , string targetProjectDirectory )
86
+ public static IList < RazorPageGeneratorResult > MainCore (
87
+ RazorProjectEngine projectEngine ,
88
+ string targetProjectDirectory ,
89
+ string physicalPathPrefix )
83
90
{
84
91
var viewDirectories = Directory . EnumerateDirectories ( targetProjectDirectory , "Views" , SearchOption . AllDirectories ) ;
85
92
var fileCount = 0 ;
@@ -94,14 +101,14 @@ public static IList<RazorPageGeneratorResult> MainCore(RazorProjectEngine projec
94
101
95
102
if ( ! cshtmlFiles . Any ( ) )
96
103
{
97
- Console . WriteLine ( " No .cshtml files were found." ) ;
104
+ Console . WriteLine ( " No .cshtml or .razor files were found." ) ;
98
105
continue ;
99
106
}
100
107
101
108
foreach ( var item in cshtmlFiles )
102
109
{
103
110
Console . WriteLine ( " Generating code file for view {0}..." , item . FileName ) ;
104
- results . Add ( GenerateCodeFile ( projectEngine , item ) ) ;
111
+ results . Add ( GenerateCodeFile ( projectEngine , item , physicalPathPrefix ) ) ;
105
112
Console . WriteLine ( " Done!" ) ;
106
113
fileCount ++ ;
107
114
}
@@ -110,9 +117,12 @@ public static IList<RazorPageGeneratorResult> MainCore(RazorProjectEngine projec
110
117
return results ;
111
118
}
112
119
113
- private static RazorPageGeneratorResult GenerateCodeFile ( RazorProjectEngine projectEngine , RazorProjectItem projectItem )
120
+ private static RazorPageGeneratorResult GenerateCodeFile (
121
+ RazorProjectEngine projectEngine ,
122
+ RazorProjectItem projectItem ,
123
+ string physicalPathPrefix )
114
124
{
115
- var projectItemWrapper = new FileSystemRazorProjectItemWrapper ( projectItem ) ;
125
+ var projectItemWrapper = new FileSystemRazorProjectItemWrapper ( projectItem , physicalPathPrefix ) ;
116
126
var codeDocument = projectEngine . Process ( projectItemWrapper ) ;
117
127
var cSharpDocument = codeDocument . GetCSharpDocument ( ) ;
118
128
if ( cSharpDocument . Diagnostics . Any ( ) )
@@ -163,17 +173,19 @@ private class FileSystemRazorProjectItemWrapper : RazorProjectItem
163
173
{
164
174
private readonly RazorProjectItem _source ;
165
175
166
- public FileSystemRazorProjectItemWrapper ( RazorProjectItem item )
176
+ public FileSystemRazorProjectItemWrapper ( RazorProjectItem item , string physicalPathPrefix )
167
177
{
168
178
_source = item ;
179
+
180
+ // Mask the full name since we don't want a developer's local file paths to be committed.
181
+ PhysicalPath = $ "{ physicalPathPrefix } { _source . FileName } ";
169
182
}
170
183
171
184
public override string BasePath => _source . BasePath ;
172
185
173
186
public override string FilePath => _source . FilePath ;
174
187
175
- // Mask the full name since we don't want a developer's local file paths to be commited.
176
- public override string PhysicalPath => _source . FileName ;
188
+ public override string PhysicalPath { get ; }
177
189
178
190
public override bool Exists => _source . Exists ;
179
191
@@ -213,4 +225,4 @@ private string ProcessFileIncludes()
213
225
}
214
226
}
215
227
}
216
- }
228
+ }
0 commit comments