Skip to content

Commit

Permalink
Change logic for finding the module base to hunt for the module .psd1…
Browse files Browse the repository at this point in the history
… file (PowerShell#1176)

This is because we might be installed in a versioned directory, rather than
the a directory name PSScriptAnalyzer, we'll be in PSScriptAnalyzer/1.18.0
  • Loading branch information
JamesWTruher authored and bergmeister committed Mar 22, 2019
1 parent 07f8be2 commit 3c8665a
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions Rules/CompatibilityRules/CompatibilityRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,22 @@ private string NormalizeProfileNameToAbsolutePath(string profileName)
private static string GetModuleRootDirPath()
{
string asmDirLocation = Path.GetDirectoryName(typeof(CompatibilityRule).Assembly.Location);

string topDir = Path.GetFileName(asmDirLocation);

string nonNormalizedRoot = "PSScriptAnalyzer".Equals(topDir, StringComparison.OrdinalIgnoreCase)
? Path.Combine(asmDirLocation)
: Path.Combine(asmDirLocation, "..");
// We check our assembly location and then parent, looking for PSScriptAnalyzer.psd1,
// because the assembly might be in the root of the module or in a child directory (ex: coreclr).
// That's the base where we will find our compatibility zip file.
// We can't hunt for the directory 'PSScriptAnalyzer' because we may be installed in
// PSScriptAnalyzer/1.18.0 or PSScriptAnalyzer.
const string psdFile = "PSScriptAnalyzer.psd1";
string nonNormalizedRoot = asmDirLocation;
string psmPath = Path.Combine(nonNormalizedRoot, psdFile);
if ( ! File.Exists(psmPath) ) {
nonNormalizedRoot = Path.Combine(nonNormalizedRoot, "..");
psmPath = Path.Combine(nonNormalizedRoot, psdFile);
if ( ! File.Exists(psmPath) ) {
// Couldn't find it, give up
return String.Empty;
}
}

return Path.GetFullPath(nonNormalizedRoot);
}
Expand Down

0 comments on commit 3c8665a

Please sign in to comment.