19
19
using System . IO ;
20
20
using System . Linq ;
21
21
using System . Management . Automation ;
22
+ using System . Reflection ;
22
23
using System . Text . RegularExpressions ;
23
24
using Tools . Common . Issues ;
24
25
using Tools . Common . Loaders ;
@@ -43,7 +44,7 @@ public HelpAnalyzer()
43
44
public AnalysisLogger Logger { get ; set ; }
44
45
public string Name { get ; private set ; }
45
46
46
- // TODO: Remove IfDef code
47
+ // TODO: Remove IfDef code
47
48
#if ! NETSTANDARD
48
49
private AppDomain _appDomain ;
49
50
#endif
@@ -95,6 +96,7 @@ public void Analyze(IEnumerable<string> scopes, IEnumerable<string> modulesToAna
95
96
var helpLogger = Logger . CreateLogger < HelpIssue > ( "HelpIssues.csv" ) ;
96
97
foreach ( var baseDirectory in scopes . Where ( s => Directory . Exists ( Path . GetFullPath ( s ) ) ) )
97
98
{
99
+ PreloadSharedAssemblies ( baseDirectory ) ;
98
100
foreach ( var directory in Directory . EnumerateDirectories ( Path . GetFullPath ( baseDirectory ) ) )
99
101
{
100
102
if ( modulesToAnalyze != null &&
@@ -114,6 +116,30 @@ public void Analyze(IEnumerable<string> scopes, IEnumerable<string> modulesToAna
114
116
}
115
117
}
116
118
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
+
117
143
private void AnalyzeMamlHelp (
118
144
IEnumerable < string > scopes ,
119
145
string directory ,
@@ -158,7 +184,7 @@ private void AnalyzeMamlHelp(
158
184
h . Assembly = cmdletFileName ;
159
185
} , "Cmdlet" ) ;
160
186
161
- // TODO: Remove IfDef
187
+ // TODO: Remove IfDef
162
188
#if NETSTANDARD
163
189
var proxy = new CmdletLoader ( ) ;
164
190
#else
@@ -169,7 +195,7 @@ private void AnalyzeMamlHelp(
169
195
var helpRecords = CmdletHelpParser . GetHelpTopics ( helpFile , helpLogger ) ;
170
196
ValidateHelpRecords ( cmdlets , helpRecords , helpLogger ) ;
171
197
helpLogger . Decorator . Remove ( "Cmdlet" ) ;
172
- // TODO: Remove IfDef code
198
+ // TODO: Remove IfDef code
173
199
#if ! NETSTANDARD
174
200
AppDomain . Unload ( _appDomain ) ;
175
201
#endif
@@ -229,13 +255,13 @@ private void AnalyzeMarkdownHelp(
229
255
powershell . AddScript ( script ) ;
230
256
var cmdletResult = powershell . Invoke ( ) ;
231
257
var nestedModules = new List < string > ( ) ;
232
- foreach ( var module in cmdletResult )
258
+ foreach ( var module in cmdletResult )
233
259
{
234
- if ( module != null && module . ToString ( ) . StartsWith ( "." ) )
260
+ if ( module != null && module . ToString ( ) . StartsWith ( "." ) )
235
261
{
236
262
nestedModules . Add ( module . ToString ( ) . Substring ( 2 ) ) ;
237
- }
238
- else if ( module != null )
263
+ }
264
+ else if ( module != null )
239
265
{
240
266
nestedModules . Add ( module . ToString ( ) ) ;
241
267
}
@@ -270,7 +296,7 @@ private void AnalyzeMarkdownHelp(
270
296
h . Assembly = assemblyFileName ;
271
297
} , "Cmdlet" ) ;
272
298
processedHelpFiles . Add ( assemblyFileName ) ;
273
- // TODO: Remove IfDef
299
+ // TODO: Remove IfDef
274
300
#if NETSTANDARD
275
301
var proxy = new CmdletLoader ( ) ;
276
302
#else
@@ -280,7 +306,7 @@ private void AnalyzeMarkdownHelp(
280
306
var cmdlets = module . Cmdlets ;
281
307
allCmdlets . AddRange ( cmdlets ) ;
282
308
helpLogger . Decorator . Remove ( "Cmdlet" ) ;
283
- // TODO: Remove IfDef code
309
+ // TODO: Remove IfDef code
284
310
#if ! NETSTANDARD
285
311
AppDomain . Unload ( _appDomain ) ;
286
312
#endif
@@ -290,7 +316,7 @@ private void AnalyzeMarkdownHelp(
290
316
script = $ "Import-LocalizedData -BaseDirectory { parentDirectory } -FileName { psd1FileName } -BindingVariable ModuleMetadata; $ModuleMetadata.FunctionsToExport;";
291
317
cmdletResult = PowerShell . Create ( ) . AddScript ( script ) . Invoke ( ) ;
292
318
var functionCmdlets = cmdletResult . Select ( c => c . ToString ( ) ) . ToList ( ) ;
293
- foreach ( var cmdlet in functionCmdlets )
319
+ foreach ( var cmdlet in functionCmdlets )
294
320
{
295
321
var metadata = new CmdletMetadata ( ) ;
296
322
metadata . VerbName = cmdlet . Split ( "-" ) [ 0 ] ;
@@ -302,7 +328,7 @@ private void AnalyzeMarkdownHelp(
302
328
ValidateHelpMarkdown ( helpFolder , helpFiles , helpLogger ) ;
303
329
304
330
Directory . SetCurrentDirectory ( savedDirectory ) ;
305
-
331
+
306
332
}
307
333
308
334
private void ValidateHelpRecords ( IList < CmdletMetadata > cmdlets , IList < string > helpRecords ,
@@ -321,7 +347,7 @@ private void ValidateHelpRecords(IList<CmdletMetadata> cmdlets, IList<string> he
321
347
ProblemId = MissingHelp ,
322
348
Remediation = string . Format ( "Add Help record for cmdlet {0} to help file." , cmdlet . Name )
323
349
} ;
324
- if ( cmdlet . ClassName != null )
350
+ if ( cmdlet . ClassName != null )
325
351
{
326
352
issue . Description = $ "Help missing for cmdlet { cmdlet . Name } implemented by class { cmdlet . ClassName } ";
327
353
}
@@ -335,16 +361,16 @@ private void ValidateHelpRecords(IList<CmdletMetadata> cmdlets, IList<string> he
335
361
336
362
foreach ( var helpRecord in helpRecords )
337
363
{
338
- if ( ! cmdletDict . ContainsKey ( helpRecord ) )
364
+ if ( ! cmdletDict . ContainsKey ( helpRecord ) )
339
365
{
340
366
Console . Error . WriteLine ( $ "Help record { helpRecord } has no cmdlet.") ;
341
- }
367
+ }
342
368
}
343
369
}
344
370
345
371
private void ValidateHelpMarkdown ( string helpFolder , IList < string > helpRecords , ReportLogger < HelpIssue > helpLogger )
346
372
{
347
- foreach ( var helpMarkdown in helpRecords )
373
+ foreach ( var helpMarkdown in helpRecords )
348
374
{
349
375
var file = Path . Combine ( helpFolder , helpMarkdown + ".md" ) ;
350
376
var content = File . ReadAllText ( file ) ;
0 commit comments