@@ -42,8 +42,8 @@ public class UseCompatibleCmdlets : AstVisitor, IScriptRule
4242 private string scriptPath ;
4343 private bool IsInitialized ;
4444 private bool hasInitializationError ;
45- private string referenceFile ;
46- private readonly string defaultReferenceFile = "desktop-5.1.14393.206-windows.json " ;
45+ private string referencePlatform ;
46+ private readonly string defaultReferencePlatform = "desktop-5.1.14393.206-windows" ;
4747
4848 public UseCompatibleCmdlets ( )
4949 {
@@ -278,15 +278,21 @@ private void SetupCmdletsDictionary()
278278 object referenceObject ;
279279 if ( ruleArgs . TryGetValue ( "reference" , out referenceObject ) )
280280 {
281- referenceFile = referenceObject as string ;
282- if ( referenceFile == null )
281+ referencePlatform = referenceObject as string ;
282+ if ( referencePlatform == null )
283283 {
284284 return ;
285285 }
286286 }
287287 else
288288 {
289- referenceFile = defaultReferenceFile ;
289+ referencePlatform = defaultReferencePlatform ;
290+ }
291+
292+ // check if the reference file has valid platformSpec
293+ if ( ! IsValidPlatformString ( referencePlatform ) )
294+ {
295+ return ;
290296 }
291297
292298 object modeObject ;
@@ -336,7 +342,7 @@ private void SetupCmdletsDictionary()
336342 /// </summary>
337343 private bool ContainsReferenceFile ( string directory )
338344 {
339- return File . Exists ( Path . Combine ( directory , referenceFile ) ) ;
345+ return File . Exists ( Path . Combine ( directory , referencePlatform + ".json" ) ) ;
340346 }
341347
342348 /// <summary>
@@ -379,6 +385,16 @@ private string GetShippedSettingsDirectory()
379385 return settingsPath ;
380386 }
381387
388+ private bool IsValidPlatformString ( string fileNameWithoutExt )
389+ {
390+ string psedition , psversion , os ;
391+ return GetVersionInfoFromPlatformString (
392+ fileNameWithoutExt ,
393+ out psedition ,
394+ out psversion ,
395+ out os ) ;
396+ }
397+
382398 /// <summary>
383399 /// Gets PowerShell Edition, Version and OS from input string
384400 /// </summary>
0 commit comments