Skip to content

Commit b9a114f

Browse files
author
Kapil Borle
committed
Fix issues with retrieving keys from mof file
1 parent e623f57 commit b9a114f

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

Rules/UseIdenticalMandatoryParametersDSC.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,10 @@ private string[] GetKeys(string fileName)
160160

161161
private string GetMofFilepath(string filePath)
162162
{
163-
var mofFilePath = Path.GetFileNameWithoutExtension(filePath) + ".schema.mof";
163+
var mofFilePath = Path.Combine(
164+
Path.GetDirectoryName(filePath),
165+
Path.GetFileNameWithoutExtension(filePath)) + ".schema.mof";
166+
164167
return File.Exists(mofFilePath) ? mofFilePath : null;
165168
}
166169

@@ -172,7 +175,7 @@ private Tuple<string, Version> GetModuleInfo(string fileName)
172175
return null;
173176
}
174177

175-
var moduleName = moduleManifest.Name;
178+
var moduleName = Path.GetFileNameWithoutExtension(moduleManifest.Name);
176179
Token[] tokens;
177180
ParseError[] parseErrors;
178181
var ast = Parser.ParseFile(moduleManifest.FullName, out tokens, out parseErrors);
@@ -199,8 +202,10 @@ private Tuple<string, Version> GetModuleInfo(string fileName)
199202
return null;
200203
}
201204

205+
var valueAst = moduleVersionKvp.Item2.Find(a => a is StringConstantExpressionAst, false);
206+
var versionText = valueAst == null ? null : ((StringConstantExpressionAst)valueAst).Value;
202207
Version version;
203-
Version.TryParse(moduleVersionKvp.Item2.Extent.Text, out version);
208+
Version.TryParse(versionText, out version); // this handles null so no need to check versionText
204209
return version == null ? null : Tuple.Create(moduleName, version);
205210
}
206211

0 commit comments

Comments
 (0)