diff --git a/src/code/InstallHelper.cs b/src/code/InstallHelper.cs index 16dcda959..c45865b92 100644 --- a/src/code/InstallHelper.cs +++ b/src/code/InstallHelper.cs @@ -926,7 +926,7 @@ private bool TryInstallToTempPath( try { var pathToFile = Path.Combine(tempInstallPath, $"{pkgName}.{normalizedPkgVersion}.zip"); - using var fs = File.Create(pathToFile); + using FileStream fs = File.Create(pathToFile); responseStream.Seek(0, System.IO.SeekOrigin.Begin); responseStream.CopyTo(fs); fs.Close(); @@ -943,8 +943,8 @@ private bool TryInstallToTempPath( File.Delete(pathToFile); - var moduleManifest = Path.Combine(tempDirNameVersion, pkgName + PSDataFileExt); - var scriptPath = Path.Combine(tempDirNameVersion, pkgName + PSScriptFileExt); + string moduleManifest = Path.Combine(tempDirNameVersion, pkgName + PSDataFileExt); + string scriptPath = Path.Combine(tempDirNameVersion, pkgName + PSScriptFileExt); bool isModule = File.Exists(moduleManifest); bool isScript = File.Exists(scriptPath); @@ -980,6 +980,15 @@ private bool TryInstallToTempPath( return false; } + // Get module actual name with correct casing + string moduleManifestActualFileName = Path.GetFileNameWithoutExtension( + Directory.GetFiles( + tempDirNameVersion, + $"{pkgName}.psd1" + )[0] + ); + _cmdletPassedIn.WriteVerbose($"pkgName: \"{pkgName}\", actual name of manifest: \"${moduleManifestActualFileName}"); + if (!Utils.TryReadManifestFile( manifestFilePath: moduleManifest, manifestInfo: out Hashtable parsedMetadataHashtable, @@ -1032,6 +1041,15 @@ private bool TryInstallToTempPath( return false; } + + // Get script actual name with correct casing + string scriptActualFileName = Path.GetFileNameWithoutExtension( + Directory.GetFiles( + tempDirNameVersion, + $"{pkgName}.ps1" + )[0] + ); + _cmdletPassedIn.WriteVerbose($"pkgName: \"{pkgName}\", actual name of script: \"{scriptActualFileName}\""); } else { @@ -1040,6 +1058,15 @@ private bool TryInstallToTempPath( _cmdletPassedIn.WriteVerbose($"This resource is not a PowerShell package and will be installed to the modules path: {installPath}."); isModule = true; + + // Get actual name from .nuspec file + string resourceNuspecFileName = Path.GetFileNameWithoutExtension( + Directory.GetFiles( + tempDirNameVersion, + $"{pkgName}.nuspec" + )[0] + ); + _cmdletPassedIn.WriteVerbose($"pkgName: \"{pkgName}\", actual name of nuspec file: \"{resourceNuspecFileName}\""); } installPath = _savePkg ? _pathsToInstallPkg.First() : installPath; diff --git a/src/code/Utils.cs b/src/code/Utils.cs index 308c3b2e7..5f6fdfc57 100644 --- a/src/code/Utils.cs +++ b/src/code/Utils.cs @@ -1343,8 +1343,8 @@ private static bool TryReadPSDataFile( throw new PSArgumentNullException(nameof(filePath)); } - string contents = System.IO.File.ReadAllText(filePath); - var scriptBlock = System.Management.Automation.ScriptBlock.Create(contents); + string contents = File.ReadAllText(filePath); + var scriptBlock = ScriptBlock.Create(contents); // Ensure that the content script block is safe to convert into a PSDataFile Hashtable. // This will throw for unsafe content.