@@ -30,7 +30,7 @@ public sealed class DependencyManager : IDisposable
3030 private readonly DotNet dotnet ;
3131 private readonly FileContent fileContent ;
3232 private readonly TemporaryDirectory packageDirectory ;
33- private readonly TemporaryDirectory ? razorWorkingDirectory ;
33+ private TemporaryDirectory ? razorWorkingDirectory ;
3434
3535
3636 /// <summary>
@@ -136,34 +136,7 @@ public DependencyManager(string srcDir, IDependencyOptions options, ILogger logg
136136 if ( bool . TryParse ( webViewExtractionOption , out var shouldExtractWebViews ) &&
137137 shouldExtractWebViews )
138138 {
139- progressMonitor . LogInfo ( $ "Generating source files from cshtml and razor files.") ;
140-
141- var views = GetFiles ( "*.cshtml" )
142- . Concat ( GetFiles ( "*.razor" ) )
143- . ToArray ( ) ;
144-
145- if ( views . Length > 0 )
146- {
147- progressMonitor . LogInfo ( $ "Found { views . Length } cshtml and razor files.") ;
148-
149- // TODO: use SDK specified in global.json
150- var sdk = new Sdk ( dotnet ) . GetNewestSdk ( ) ;
151- if ( sdk != null )
152- {
153- try
154- {
155- var razor = new Razor ( sdk , dotnet , progressMonitor ) ;
156- razorWorkingDirectory = new TemporaryDirectory ( ComputeTempDirectory ( sourceDir . FullName , "razor" ) ) ;
157- var generatedFiles = razor . GenerateFiles ( views , usedReferences . Keys , razorWorkingDirectory . ToString ( ) ) ;
158- this . allSources . AddRange ( generatedFiles ) ;
159- }
160- catch ( Exception ex )
161- {
162- // It's okay, we tried our best to generate source files from cshtml files.
163- progressMonitor . LogInfo ( $ "Failed to generate source files from cshtml files: { ex . Message } ") ;
164- }
165- }
166- }
139+ GenerateSourceFilesFromWebViews ( ) ;
167140 }
168141
169142 progressMonitor . Summary (
@@ -178,6 +151,38 @@ public DependencyManager(string srcDir, IDependencyOptions options, ILogger logg
178151 DateTime . Now - startTime ) ;
179152 }
180153
154+ private void GenerateSourceFilesFromWebViews ( )
155+ {
156+ progressMonitor . LogInfo ( $ "Generating source files from cshtml and razor files.") ;
157+
158+ var views = GetFiles ( "*.cshtml" )
159+ . Concat ( GetFiles ( "*.razor" ) )
160+ . ToArray ( ) ;
161+
162+ if ( views . Length > 0 )
163+ {
164+ progressMonitor . LogInfo ( $ "Found { views . Length } cshtml and razor files.") ;
165+
166+ // TODO: use SDK specified in global.json
167+ var sdk = new Sdk ( dotnet ) . GetNewestSdk ( ) ;
168+ if ( sdk != null )
169+ {
170+ try
171+ {
172+ var razor = new Razor ( sdk , dotnet , progressMonitor ) ;
173+ razorWorkingDirectory = new TemporaryDirectory ( ComputeTempDirectory ( sourceDir . FullName , "razor" ) ) ;
174+ var generatedFiles = razor . GenerateFiles ( views , usedReferences . Keys , razorWorkingDirectory . ToString ( ) ) ;
175+ this . allSources . AddRange ( generatedFiles ) ;
176+ }
177+ catch ( Exception ex )
178+ {
179+ // It's okay, we tried our best to generate source files from cshtml files.
180+ progressMonitor . LogInfo ( $ "Failed to generate source files from cshtml files: { ex . Message } ") ;
181+ }
182+ }
183+ }
184+ }
185+
181186 public DependencyManager ( string srcDir ) : this ( srcDir , DependencyOptions . Default , new ConsoleLogger ( Verbosity . Info ) ) { }
182187
183188 private IEnumerable < string > GetFiles ( string pattern , bool recurseSubdirectories = true )
0 commit comments