Closed wekempf closed 6 months ago
Can confirm I see the same behavior. Here with $VerbosePreference = $DebugPreference = 'Continue'
:
PS C:\Users\olavb> Save-PSResource -Path 'C:\Users\olavb\Desktop\TestSaveScript' -SkipDependencyCheck -Name 'New-OnPremiseHybridWorker' -TrustRepository -Repository 'PSGallery'
DEBUG: In SavePSResource::ProcessSaveHelper()
DEBUG: In InstallHelper::BeginInstallPackages()
DEBUG: Parameters passed in >>> Name: 'New-OnPremiseHybridWorker'; VersionRange: ''; NuGetVersion: ''; VersionType: 'NoVersion'; Version: ''; Prerelease: 'False'; Repository: 'PSGallery'; AcceptLicense: 'True'; Quiet: 'False'; Reinstall: 'True'; TrustRepository: 'True'; NoClobber: 'False'; AsNupkg: 'False'; IncludeXml 'False'; SavePackage 'True'; TemporaryPath ''; SkipDependencyCheck: 'True'; AuthenticodeCheck: 'False'; PathsToInstallPkg: 'C:\Users\olavb\Desktop\TestSaveScript'; Scope ''
DEBUG: In InstallHelper::ProcessRepositories()
VERBOSE: Attempting to search for packages in 'PSGallery'
DEBUG: In InstallHelper::InstallPackages()
DEBUG: In InstallHelper::InstallPackage()
DEBUG: In V2ServerAPICalls::FindName()
DEBUG: In V2ServerAPICalls::HttpRequestCall()
DEBUG: Request url is 'https://www.powershellgallery.com/api/v2/FindPackagesById()?id='New-OnPremiseHybridWorker'&$inlinecount=allpages&$filter=IsLatestVersion and Id eq 'New-OnPremiseHybridWorker''
DEBUG: In V2ServerAPICalls::InstallVersion()
DEBUG: In V2ServerAPICalls::HttpRequestCallForContent()
DEBUG: Request url is 'https://www.powershellgallery.com/api/v2/package/New-OnPremiseHybridWorker/1.7.0'
DEBUG: In InstallHelper::TryInstallToTempPath()
DEBUG: In InstallHelper::DeleteExtraneousFiles()
DEBUG: Deleting 'C:\Users\olavb\AppData\Local\Temp\64f9062f-dc5e-45bf-89bb-d8e164c25f40\new-onpremisehybridworker\1.7\New-OnPremiseHybridWorker.nuspec'
DEBUG: Deleting 'C:\Users\olavb\AppData\Local\Temp\64f9062f-dc5e-45bf-89bb-d8e164c25f40\new-onpremisehybridworker\1.7\[Content_Types].xml'
DEBUG: Deleting 'C:\Users\olavb\AppData\Local\Temp\64f9062f-dc5e-45bf-89bb-d8e164c25f40\new-onpremisehybridworker\1.7\_rels'
DEBUG: Deleting 'C:\Users\olavb\AppData\Local\Temp\64f9062f-dc5e-45bf-89bb-d8e164c25f40\new-onpremisehybridworker\1.7\package'
DEBUG: In InstallHelper::TryMoveInstallContent()
DEBUG: In InstallHelper::MoveFilesIntoInstallPath()
VERBOSE: Installation source path is: 'C:\Users\olavb\AppData\Local\Temp\64f9062f-dc5e-45bf-89bb-d8e164c25f40\new-onpremisehybridworker\1.7'
VERBOSE: Installation destination path is: 'C:\Users\olavb\Desktop\TestSaveScript'
VERBOSE: Moving 'C:\Users\olavb\AppData\Local\Temp\64f9062f-dc5e-45bf-89bb-d8e164c25f40\new-onpremisehybridworker\1.7\New-OnPremiseHybridWorker_InstalledScriptInfo.xml' to 'C:\Users\olavb\Desktop\TestSaveScript\New-OnPremiseHybridWorker_InstalledScriptInfo.xml'
Save-PSResource: Unable to successfully install package 'New-OnPremiseHybridWorker': 'Could not find file 'C:\Users\olavb\AppData\Local\Temp\64f9062f-dc5e-45bf-89bb-d8e164c25f40\new-onpremisehybridworker\1.7\New-OnPremiseHybridWorker_InstalledScriptInfo.xml'.'
Save-PSResource: Operation is not valid due to the current state of the object.
VERBOSE: Attempting to delete 'C:\Users\olavb\AppData\Local\Temp\64f9062f-dc5e-45bf-89bb-d8e164c25f40'
VERBOSE: Successfully deleted 'C:\Users\olavb\AppData\Local\Temp\64f9062f-dc5e-45bf-89bb-d8e164c25f40'
Save-PSResource: Package(s) 'New-OnPremiseHybridWorker' could not be installed from repository 'PSGallery'.
PS C:\Users\olavb>
Seems the problem is that it tries to move New-OnPremiseHybridWorker_InstalledScriptInfo.xml
even though it's not expected to be there unless -IncludeXml
.
VERBOSE: Moving 'C:\Users\olavb\AppData\Local\Temp\64f9062f-dc5e-45bf-89bb-d8e164c25f40\new-onpremisehybridworker\1.7\New-OnPremiseHybridWorker_InstalledScriptInfo.xml' to 'C:\Users\olavb\Desktop\TestSaveScript\New-OnPremiseHybridWorker_InstalledScriptInfo.xml'
Save-PSResource: Unable to successfully install package 'New-OnPremiseHybridWorker': 'Could not find file 'C:\Users\olavb\AppData\Local\Temp\64f9062f-dc5e-45bf-89bb-d8e164c25f40\new-onpremisehybridworker\1.7\New-OnPremiseHybridWorker_InstalledScriptInfo.xml'.'
Seems related to the fix for the issue I opened here:
Also related:
Seems the problematic code is here, not checking for IncludeXml
:
There's no test for it here either, only with -IncludeXml
:
Thanks-- looking at the PRs we are able to repro
Prerequisites
Steps to reproduce
Save-PSResource works for modules.
Note: That bit about the 'file' scheme not being supported is caused by having a local directory registered as a repository. This is a separate concern and unrelated to the problem here, as I've tested on multiple machines, some without this local repository.
Save-PSResource for scripts fails.
The multiple repositories is not the cause. I get the same behavior on other machines with only PSGallery registered. Most of the messages are very poor. In particular "Operation is not valid due to the current state of the object." is developer speak and totally useless to most PowerShell users. The error reporting here should be vastly improved. The first message about the missing XML file does give a slight clue here, however, and the following "works" by some definition.
This saves the script, but also saves the XML metadata file. I'm not sure why you'd want that file, ever? Regardless, this is different behavior from saving a module. While not fully understanding the desired behavior of these cmdlets (I've posted a question in the discussions, but it appears literally no one reads or at least responds there) I would consider this to be a bug. At best it's inconsistent and unintuitive behavior, making it a usability bug, but I suspect this isn't really the expected behavior.
Expected behavior
The New-OnPremiseHybridWorker.ps1 script should be saved to the current location without the XML metadata file.
Environment data
Visuals
No response