1919using System . IO ;
2020using System . Linq ;
2121using System . Management . Automation ;
22+ using System . Reflection ;
2223using System . Text . RegularExpressions ;
2324using Tools . Common . Issues ;
2425using Tools . Common . Loaders ;
@@ -43,7 +44,7 @@ public HelpAnalyzer()
4344 public AnalysisLogger Logger { get ; set ; }
4445 public string Name { get ; private set ; }
4546
46- // TODO: Remove IfDef code
47+ // TODO: Remove IfDef code
4748#if ! NETSTANDARD
4849 private AppDomain _appDomain ;
4950#endif
@@ -95,6 +96,7 @@ public void Analyze(IEnumerable<string> scopes, IEnumerable<string> modulesToAna
9596 var helpLogger = Logger . CreateLogger < HelpIssue > ( "HelpIssues.csv" ) ;
9697 foreach ( var baseDirectory in scopes . Where ( s => Directory . Exists ( Path . GetFullPath ( s ) ) ) )
9798 {
99+ PreloadSharedAssemblies ( baseDirectory ) ;
98100 foreach ( var directory in Directory . EnumerateDirectories ( Path . GetFullPath ( baseDirectory ) ) )
99101 {
100102 if ( modulesToAnalyze != null &&
@@ -114,6 +116,30 @@ public void Analyze(IEnumerable<string> scopes, IEnumerable<string> modulesToAna
114116 }
115117 }
116118
119+ private static void PreloadSharedAssemblies ( string directory )
120+ {
121+ var sharedAssemblyFolder = Path . Combine ( directory , "Az.Accounts" , "NetCoreAssemblies" ) ;
122+ if ( Directory . Exists ( sharedAssemblyFolder ) )
123+ {
124+ foreach ( var file in Directory . GetFiles ( sharedAssemblyFolder ) )
125+ {
126+ try
127+ {
128+ Console . WriteLine ( $ "PreloadSharedAssemblies: Starting to load assembly { file } .") ;
129+ Assembly . LoadFrom ( file ) ;
130+ }
131+ catch ( Exception e )
132+ {
133+ Console . WriteLine ( $ "PreloadSharedAssemblies: Failed to load assembly { Path . GetFileNameWithoutExtension ( file ) } with { e } ") ;
134+ }
135+ }
136+ }
137+ else
138+ {
139+ Console . WriteLine ( $ "PreloadSharedAssemblies: Could not find directory { sharedAssemblyFolder } .") ;
140+ }
141+ }
142+
117143 private void AnalyzeMamlHelp (
118144 IEnumerable < string > scopes ,
119145 string directory ,
@@ -158,7 +184,7 @@ private void AnalyzeMamlHelp(
158184 h . Assembly = cmdletFileName ;
159185 } , "Cmdlet" ) ;
160186
161- // TODO: Remove IfDef
187+ // TODO: Remove IfDef
162188#if NETSTANDARD
163189 var proxy = new CmdletLoader ( ) ;
164190#else
@@ -169,7 +195,7 @@ private void AnalyzeMamlHelp(
169195 var helpRecords = CmdletHelpParser . GetHelpTopics ( helpFile , helpLogger ) ;
170196 ValidateHelpRecords ( cmdlets , helpRecords , helpLogger ) ;
171197 helpLogger . Decorator . Remove ( "Cmdlet" ) ;
172- // TODO: Remove IfDef code
198+ // TODO: Remove IfDef code
173199#if ! NETSTANDARD
174200 AppDomain . Unload ( _appDomain ) ;
175201#endif
@@ -229,13 +255,13 @@ private void AnalyzeMarkdownHelp(
229255 powershell . AddScript ( script ) ;
230256 var cmdletResult = powershell . Invoke ( ) ;
231257 var nestedModules = new List < string > ( ) ;
232- foreach ( var module in cmdletResult )
258+ foreach ( var module in cmdletResult )
233259 {
234- if ( module != null && module . ToString ( ) . StartsWith ( "." ) )
260+ if ( module != null && module . ToString ( ) . StartsWith ( "." ) )
235261 {
236262 nestedModules . Add ( module . ToString ( ) . Substring ( 2 ) ) ;
237- }
238- else if ( module != null )
263+ }
264+ else if ( module != null )
239265 {
240266 nestedModules . Add ( module . ToString ( ) ) ;
241267 }
@@ -270,7 +296,7 @@ private void AnalyzeMarkdownHelp(
270296 h . Assembly = assemblyFileName ;
271297 } , "Cmdlet" ) ;
272298 processedHelpFiles . Add ( assemblyFileName ) ;
273- // TODO: Remove IfDef
299+ // TODO: Remove IfDef
274300#if NETSTANDARD
275301 var proxy = new CmdletLoader ( ) ;
276302#else
@@ -280,7 +306,7 @@ private void AnalyzeMarkdownHelp(
280306 var cmdlets = module . Cmdlets ;
281307 allCmdlets . AddRange ( cmdlets ) ;
282308 helpLogger . Decorator . Remove ( "Cmdlet" ) ;
283- // TODO: Remove IfDef code
309+ // TODO: Remove IfDef code
284310#if ! NETSTANDARD
285311 AppDomain . Unload ( _appDomain ) ;
286312#endif
@@ -290,7 +316,7 @@ private void AnalyzeMarkdownHelp(
290316 script = $ "Import-LocalizedData -BaseDirectory { parentDirectory } -FileName { psd1FileName } -BindingVariable ModuleMetadata; $ModuleMetadata.FunctionsToExport;";
291317 cmdletResult = PowerShell . Create ( ) . AddScript ( script ) . Invoke ( ) ;
292318 var functionCmdlets = cmdletResult . Select ( c => c . ToString ( ) ) . ToList ( ) ;
293- foreach ( var cmdlet in functionCmdlets )
319+ foreach ( var cmdlet in functionCmdlets )
294320 {
295321 var metadata = new CmdletMetadata ( ) ;
296322 metadata . VerbName = cmdlet . Split ( "-" ) [ 0 ] ;
@@ -302,7 +328,7 @@ private void AnalyzeMarkdownHelp(
302328 ValidateHelpMarkdown ( helpFolder , helpFiles , helpLogger ) ;
303329
304330 Directory . SetCurrentDirectory ( savedDirectory ) ;
305-
331+
306332 }
307333
308334 private void ValidateHelpRecords ( IList < CmdletMetadata > cmdlets , IList < string > helpRecords ,
@@ -321,7 +347,7 @@ private void ValidateHelpRecords(IList<CmdletMetadata> cmdlets, IList<string> he
321347 ProblemId = MissingHelp ,
322348 Remediation = string . Format ( "Add Help record for cmdlet {0} to help file." , cmdlet . Name )
323349 } ;
324- if ( cmdlet . ClassName != null )
350+ if ( cmdlet . ClassName != null )
325351 {
326352 issue . Description = $ "Help missing for cmdlet { cmdlet . Name } implemented by class { cmdlet . ClassName } ";
327353 }
@@ -335,16 +361,16 @@ private void ValidateHelpRecords(IList<CmdletMetadata> cmdlets, IList<string> he
335361
336362 foreach ( var helpRecord in helpRecords )
337363 {
338- if ( ! cmdletDict . ContainsKey ( helpRecord ) )
364+ if ( ! cmdletDict . ContainsKey ( helpRecord ) )
339365 {
340366 Console . Error . WriteLine ( $ "Help record { helpRecord } has no cmdlet.") ;
341- }
367+ }
342368 }
343369 }
344370
345371 private void ValidateHelpMarkdown ( string helpFolder , IList < string > helpRecords , ReportLogger < HelpIssue > helpLogger )
346372 {
347- foreach ( var helpMarkdown in helpRecords )
373+ foreach ( var helpMarkdown in helpRecords )
348374 {
349375 var file = Path . Combine ( helpFolder , helpMarkdown + ".md" ) ;
350376 var content = File . ReadAllText ( file ) ;
0 commit comments