Publish-PSResource Run Under Windows Powershell Tries to Load .NET Core Assembly
Prerequisites
- [X] Write a descriptive title.
- [X] Make sure you are able to repro it on the latest released version
- [X] Search the existing issues.
Steps to reproduce
Manually trying the method outlined by @dbrennand in his last comment an another issue using Windows Powershell (5.1), I got a new error with PowerShellGet 3.0.17:
PS> Publish-PSResource -Credential $cred -Repository RepName -Path .\path\to\module.psd1
Publish-PSResource : Could not load file or assembly 'System.Security.Cryptography.ProtectedData, Version=4.0.2.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file
specified.
At line:1 char:1
+ Publish-PSResource -Credential $cred -Repository RepoName -Path .\path\to...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidResult: (:) [Publish-PSResource], ArgumentException
+ FullyQualifiedErrorId : PushNupkgError,Microsoft.PowerShell.PowerShellGet.Cmdlets.PublishPSResource
The type appeared as though it was available on my system as I could use the accelerators to do tab-completion of methods on the referenced type. Looking into my GAC, it looked like the PublicKeyToken was associated with a different version of the System.Security assembly:
Directory: C:\Windows\assembly\GAC_MSIL\System.Security\2.0.0.0__b03f5f7f11d50a3a
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 2021-05-12 3:31 274432 System.Security.dll
Searching further for 'PowerShellGet' and 'System.Security.Cryptography.ProtectedData' revealed an unrelated issue which indicated that there's a .NET Core assembly named 'System.Security.Cryptography.ProtectedData.dll'. This gave a hint that Publish-PSResource/PowerShellGet was maybe trying to load the .NET Core assembly (which I don't have installed).
With that in mind, I installed PowerShell 7.2 and ran Publish-PSResource from there, successfully publishing the module without issue.
Expected behavior
PS> Publish-PSResource -Credential (get-secret PSRepository) -Repository Repo -Path .\Documents\WindowsPowerShell\Modules\moduleName\moduleName.psd1 -Verbose
Vault SecretStore requires a password.
Enter password:
*************************
VERBOSE: Performing the operation "Publish-PSResource" on target "Publish resource 'C:\Users\user\Documents\WindowsPowerShell\Modules\moduleName\moduleName.psd1' from the machine".
VERBOSE: Creating new nuspec file.
VERBOSE: The newly created nuspec is: C:\Users\user\AppData\Local\Temp\64d5dc26-f293-40ae-8ba6-79a3dc2a760d\moduleName.nuspec
VERBOSE: Successfully packed the resource into a .nupkg
VERBOSE: Successfully published the resource to '<nuget feed URI>'
VERBOSE: Deleting temporary directory 'C:\Users\user\AppData\Local\Temp\64d5dc26-f293-40ae-8ba6-79a3dc2a760d'
Actual behavior
PS> Publish-PSResource -Credential (get-secret PSRepository) -Repository Repo -Path .\Documents\WindowsPowerShell\Modules\moduleName\moduleName.psd1 -Verbose
Vault SecretStore requires a password.
*************************
VERBOSE: Performing the operation "Publish-PSResource" on target "Publish resource
'C:\Users\user\Documents\WindowsPowerShell\Modules\moduleName\moduleName.psd1' from the machine".
VERBOSE: Creating new nuspec file.
VERBOSE: The newly created nuspec is:
C:\Users\user\AppData\Local\Temp\f0ae87df-1c0c-4b97-aaa3-dc60418caca5\moduleName.nuspec
VERBOSE: Searching in repository Repo
VERBOSE: credential successfully set for repository: Repo
VERBOSE: Successfully packed the resource into a .nupkg
Publish-PSResource : Could not load file or assembly 'System.Security.Cryptography.ProtectedData, Version=4.0.2.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file
specified.
At line:1 char:1
+ Publish-PSResource -Credential (get-secret PSRepository) -Repository ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidResult: (:) [Publish-PSResource], ArgumentException
+ FullyQualifiedErrorId : PushNupkgError,Microsoft.PowerShell.PowerShellGet.Cmdlets.PublishPSResource
VERBOSE: Deleting temporary directory 'C:\Users\user\AppData\Local\Temp\f0ae87df-1c0c-4b97-aaa3-dc60418caca5'
Error details
Publish-PSResource : Could not load file or assembly 'System.Security.Cryptography.ProtectedData, Version=4.0.2.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file
specified.
At line:1 char:1
+ Publish-PSResource -Credential (get-secret PSRepository) -Repository ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidResult: (:) [Publish-PSResource], ArgumentException
+ FullyQualifiedErrorId : PushNupkgError,Microsoft.PowerShell.PowerShellGet.Cmdlets.PublishPSResource
Environment data
ModuleType Version Name ExportedCommands
---------- ------- ---- ----------------
Binary 3.0.17 powershellget {Find-PSResource, Get-PSResource, Get-PSResourceRepository...
Script 2.2.5 PowerShellGet {Find-Command, Find-DscResource, Find-Module, Find-RoleCap...
Key : PSVersion
Value : 5.1.19041.1682
Name : PSVersion
Key : PSEdition
Value : Desktop
Name : PSEdition
Key : PSCompatibleVersions
Value : {1.0, 2.0, 3.0, 4.0...}
Name : PSCompatibleVersions
Key : BuildVersion
Value : 10.0.19041.1682
Name : BuildVersion
Key : CLRVersion
Value : 4.0.30319.42000
Name : CLRVersion
Key : WSManStackVersion
Value : 3.0
Name : WSManStackVersion
Key : PSRemotingProtocolVersion
Value : 2.3
Name : PSRemotingProtocolVersion
Key : SerializationVersion
Value : 1.1.0.1
Name : SerializationVersion
Visuals
No response