1010using Microsoft . CodeAnalysis . CSharp ;
1111using Microsoft . CodeAnalysis . Emit ;
1212using System . Reflection . Metadata ;
13- using System . Resources ;
1413
1514namespace RazorEngineCore
1615{
@@ -47,13 +46,16 @@ public IRazorEngineCompiledTemplate Compile(string content, Action<IRazorEngineC
4746
4847 public Task < IRazorEngineCompiledTemplate > CompileAsync ( string content , Action < IRazorEngineCompilationOptionsBuilder > builderAction = null , CancellationToken cancellationToken = default )
4948 {
50- return Task . Factory . StartNew ( ( ) => this . Compile ( content : content , builderAction : builderAction , cancellationToken : cancellationToken ) ) ;
49+ return Task . Factory . StartNew ( ( ) => this . Compile (
50+ content ,
51+ builderAction ,
52+ cancellationToken ) ) ;
5153 }
5254
5355 protected virtual RazorEngineCompiledTemplateMeta CreateAndCompileToStream ( string templateSource , RazorEngineCompilationOptions options , CancellationToken cancellationToken )
54-
5556 {
5657 templateSource = this . WriteDirectives ( templateSource , options ) ;
58+
5759 string projectPath = @"." ;
5860 string fileName = string . IsNullOrWhiteSpace ( options . TemplateFilename )
5961 ? Path . GetRandomFileName ( ) + ".cshtml"
@@ -67,20 +69,17 @@ protected virtual RazorEngineCompiledTemplateMeta CreateAndCompileToStream(strin
6769 builder . SetNamespace ( options . TemplateNamespace ) ;
6870 } ) ;
6971
70-
7172 RazorSourceDocument document = RazorSourceDocument . Create ( templateSource , fileName ) ;
7273
7374 RazorCodeDocument codeDocument = engine . Process (
7475 document ,
7576 null ,
7677 new List < RazorSourceDocument > ( ) ,
7778 new List < TagHelperDescriptor > ( ) ) ;
78-
7979
8080 RazorCSharpDocument razorCSharpDocument = codeDocument . GetCSharpDocument ( ) ;
8181 SyntaxTree syntaxTree = CSharpSyntaxTree . ParseText ( razorCSharpDocument . GeneratedCode , cancellationToken : cancellationToken ) ;
8282
83-
8483 CSharpCompilation compilation = CSharpCompilation . Create (
8584 fileName ,
8685 new [ ]
@@ -114,7 +113,6 @@ protected virtual RazorEngineCompiledTemplateMeta CreateAndCompileToStream(strin
114113
115114 EmitResult emitResult = compilation . Emit ( assemblyStream , pdbStream , cancellationToken : cancellationToken ) ;
116115
117-
118116 if ( ! emitResult . Success )
119117 {
120118 RazorEngineCompilationException exception = new RazorEngineCompilationException ( )
@@ -130,12 +128,11 @@ protected virtual RazorEngineCompiledTemplateMeta CreateAndCompileToStream(strin
130128 {
131129 AssemblyByteCode = assemblyStream . ToArray ( ) ,
132130 PdbByteCode = pdbStream ? . ToArray ( ) ,
133- GeneratedSourceCode = razorCSharpDocument . GeneratedCode ,
134- TemplateSource = templateSource ,
131+ GeneratedSourceCode = options . IncludeDebuggingInfo ? razorCSharpDocument . GeneratedCode : null ,
132+ TemplateSource = options . IncludeDebuggingInfo ? templateSource : null ,
135133 TemplateNamespace = options . TemplateNamespace ,
136134 TemplateFileName = fileName
137135 } ;
138-
139136 }
140137
141138 protected virtual string WriteDirectives ( string content , RazorEngineCompilationOptions options )
@@ -152,7 +149,5 @@ protected virtual string WriteDirectives(string content, RazorEngineCompilationO
152149
153150 return stringBuilder . ToString ( ) ;
154151 }
155-
156-
157152 }
158- }
153+ }
0 commit comments