Skip to content

Commit 65c4408

Browse files
author
Kapil Borle
committed
Add module manifest keys for PS v3 and v4
1 parent 56695c3 commit 65c4408

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

Engine/Helper.cs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,12 +1604,9 @@ public bool GetNamedArgumentAttributeValue(NamedAttributeArgumentAst namedAttrib
16041604

16051605
public static IEnumerable<string> GetModuleManifestKeys(Version powershellVersion)
16061606
{
1607-
string[] keys = new string[] { };
1607+
var keys = new List<string>();
16081608

1609-
// default to version 5.0.10586.494
1610-
if (powershellVersion == null)
1611-
{
1612-
keys = new string[] {
1609+
var keysCommon = new List<string> {
16131610
"RootModule",
16141611
"ModuleVersion",
16151612
"GUID",
@@ -1633,12 +1630,18 @@ public static IEnumerable<string> GetModuleManifestKeys(Version powershellVersio
16331630
"CmdletsToExport",
16341631
"VariablesToExport",
16351632
"AliasesToExport",
1636-
"DscResourcesToExport",
16371633
"ModuleList",
16381634
"FileList",
16391635
"PrivateData",
16401636
"HelpInfoURI",
16411637
"DefaultCommandPrefix"};
1638+
1639+
keys.AddRange(keysCommon);
1640+
1641+
// default to version 5.0
1642+
if (powershellVersion == null || powershellVersion.Equals(new Version("5.0")))
1643+
{
1644+
keys.Add("DscResourcesToExport");
16421645
}
16431646
return keys;
16441647
}
@@ -1647,11 +1650,23 @@ public static bool IsModuleManifest(string filepath)
16471650
{
16481651
Token[] tokens;
16491652
ParseError[] errors;
1653+
if (filepath == null)
1654+
{
1655+
throw new ArgumentNullException("filepath");
1656+
}
1657+
if (!Path.GetExtension(filepath).Equals(".psd1", StringComparison.OrdinalIgnoreCase))
1658+
{
1659+
return false;
1660+
}
16501661

16511662
//using parsefile causes the parser to crash!
16521663
string fileContent = File.ReadAllText(filepath);
16531664
var ast = Parser.ParseInput(fileContent, out tokens, out errors);
16541665
var hast = ast.Find(x => x is HashtableAst, false) as HashtableAst;
1666+
if (hast == null)
1667+
{
1668+
return false;
1669+
}
16551670
var keys = GetModuleManifestKeys(null);
16561671
int matchCount = 0;
16571672
foreach(var pair in hast.KeyValuePairs)

0 commit comments

Comments
 (0)