@@ -218,12 +218,22 @@ private string NormalizeProfileNameToAbsolutePath(string profileName)
218
218
private static string GetModuleRootDirPath ( )
219
219
{
220
220
string asmDirLocation = Path . GetDirectoryName ( typeof ( CompatibilityRule ) . Assembly . Location ) ;
221
-
222
- string topDir = Path . GetFileName ( asmDirLocation ) ;
223
-
224
- string nonNormalizedRoot = "PSScriptAnalyzer" . Equals ( topDir , StringComparison . OrdinalIgnoreCase )
225
- ? Path . Combine ( asmDirLocation )
226
- : Path . Combine ( asmDirLocation , ".." ) ;
221
+ // We check our assembly location and then parent, looking for PSScriptAnalyzer.psd1,
222
+ // because the assembly might be in the root of the module or in a child directory (ex: coreclr).
223
+ // That's the base where we will find our compatibility zip file.
224
+ // We can't hunt for the directory 'PSScriptAnalyzer' because we may be installed in
225
+ // PSScriptAnalyzer/1.18.0 or PSScriptAnalyzer.
226
+ const string psdFile = "PSScriptAnalyzer.psd1" ;
227
+ string nonNormalizedRoot = asmDirLocation ;
228
+ string psmPath = Path . Combine ( nonNormalizedRoot , psdFile ) ;
229
+ if ( ! File . Exists ( psmPath ) ) {
230
+ nonNormalizedRoot = Path . Combine ( nonNormalizedRoot , ".." ) ;
231
+ psmPath = Path . Combine ( nonNormalizedRoot , psdFile ) ;
232
+ if ( ! File . Exists ( psmPath ) ) {
233
+ // Couldn't find it, give up
234
+ return String . Empty ;
235
+ }
236
+ }
227
237
228
238
return Path . GetFullPath ( nonNormalizedRoot ) ;
229
239
}
0 commit comments