Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build.ps1 fails downloading PowerShell package #224

Open
nbarnwell opened this issue May 3, 2024 · 9 comments
Open

Build.ps1 fails downloading PowerShell package #224

nbarnwell opened this issue May 3, 2024 · 9 comments

Comments

@nbarnwell
Copy link

  1. Forked repo
  2. Executed build.ps1

Expected
Build to run

Actual
Build failed with following error:

Install-PSResource: C:\Code\Github\dotnet-adr\build.ps1:90
Line |
  90 |      Install-Module InvokeBuild -RequiredVersion $InvokeBuildModuleVer …
     |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Unable to successfully install package 'InvokeBuild': 'Object reference not set to an instance of an object.' to
     | temporary installation path.

Additional context

13:39:39 C:\Code\Github\dotnet-adr PS> get-psresourceRepository

Name      Uri                                      Trusted Priority
----      ---                                      ------- --------
PSGallery https://www.powershellgallery.com/api/v2 False   50
@nbarnwell
Copy link
Author

I noticed an additional warning:

WARNING: The cmdlet 'Install-Module' is deprecated, please use 'Install-PSResource'.

Is it worth moving to PSResourceGet?

@JamesDawson
Copy link
Contributor

Hi @nbarnwell, thanks for opening this issue - please can you share the output you get from $PSVersionTable?

@nbarnwell
Copy link
Author

HTH:

13:39:55 C:\Code\Github\dotnet-adr PS> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.4.2
PSEdition                      Core
GitCommitId                    7.4.2
OS                             Microsoft Windows 10.0.22631
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

@JamesDawson
Copy link
Contributor

Thanks for that @nbarnwell. It's a bit of puzzle, we normally see these types of issues when the script is run in a Windows PowerShell terminal (where we've forgotten to set a #requires directive), but the output above suggests otherwise.

What happens if you try to manually install the module?

Install-Module InvokeBuild -RequiredVersion 5.10.3 -Scope CurrentUser -Force -Repository PSGallery

If the above works, then I'd suggest adding the following to build.ps1 before running it again, to disable some functionality we use in our repo/org that might not work for you (anywhere before the task . FullBuild line should be fine):

$SkipPrAutoflowEnrollmentCheck = $true

@nbarnwell
Copy link
Author

That didn't work, and gave the same error. I'm convinced it's because of the tyre-fire that is PowerShellGet/CompatPowerShellGet/PSResourceGet at the moment.

@nbarnwell
Copy link
Author

Further to my previous comment, I tried it on Windows PowerShell as opposed to PowerShell (i.e. the .NET Core-based one) and that install worked. However, the build.ps1 didn't, because there's some newer syntax involved there:

PS C:\Code\Github\dotnet-adr> .\build.ps1
At C:\Code\Github\dotnet-adr\build.ps1:83 char:49
+ $ErrorActionPreference = $ErrorActionPreference ? $ErrorActionPrefere ...
+                                                 ~
Unexpected token '?' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : UnexpectedToken

@JamesDawson
Copy link
Contributor

JamesDawson commented May 14, 2024

Thanks for that @nbarnwell. Yes, the build does require PowerShell Core, so that's expected at least!

tyre-fire that is PowerShellGet/CompatPowerShellGet/PSResourceGet

Could be :-) Although I thought the real 'fun' was going to start in the next version when they enable the compat layer and switch things over.

I'll do an experiment to change the build script over to using PSResourceGet, but in the meantime would you mind sharing your output from the following?

Get-Module -ListAvailable Microsoft.PowerShell.PSResourceGet
Get-Module -ListAvailable PowerShellGet

Also, in a fresh PowerShell session, please can you share the output from running the following immediately after build.ps1 (and it failing)?

Get-Module

@nbarnwell
Copy link
Author

nbarnwell commented May 15, 2024

real 'fun' was going to start in the next version when they enable the compat layer and switch things over.

They've done that now, I think - see https://devblogs.microsoft.com/powershell/powershellget-in-powershell-7-4-updates/. They repurposed the name "PowerShellGet" to mean the compatibility layer between the old package management and the new PSResourceGet cmdlets. It used to be called "CompatPowerShellGet".

I do a lot of PowerShell module stuff with an authenticated AzDO artifacts feed, so it's unsurprising I get a lot of results for the following. I expect the source of my problem is in here somewhere:

16:23:04 C:\Users\neil.barnwell PS> Get-Module -ListAvailable Microsoft.PowerShell.PSResourceGet

    Directory: C:\program files\powershell\7\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Binary     1.0.4.1               Microsoft.PowerShell.PSResourceGet  Core,Desk {Find-PSResource, Get-InstalledPSResour16:23:05 C:\Users\neil.barnwell PS> Get-Module -ListAvailable PowerShellGet

    Directory: C:\Users\neil.barnwell\OneDrive - bybox.com\Documents\PowerShell\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Binary     3.0.20     beta20     PowerShellGet                       Desk      {Find-PSResource, Get-PSResource, Get-P…
Binary     3.0.16     beta16     PowerShellGet                       Desk      {Find-PSResource, Get-PSResource, Get-P…
Script     2.2.5.1               PowerShellGet                       Desk      {Find-Command, Find-DSCResource, Find-M…
Script     2.2.5                 PowerShellGet                       Desk      {Find-Command, Find-DSCResource, Find-M…

    Directory: C:\program files\powershell\7\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Script     2.2.5                 PowerShellGet                       Desk      {Find-Command, Find-DSCResource, Find-M…

    Directory: C:\Program Files\WindowsPowerShell\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Script     1.0.0.1               PowerShellGet                       Desk      {Install-Module, Find-Module, Save-Modu

also:

PowerShell 7.4.2
Importing ByBox Modules...
16:25:03 C:\Users\neil.barnwell PS> cd c:\Code\Github\dotnet-adr
16:25:05 C:\Code\Github\dotnet-adr PS> .\build.ps1
WARNING: The cmdlet 'Install-Module' is deprecated, please use 'Install-PSResource'.

Untrusted repository
You are installing the modules from an untrusted repository. If you trust this repository, change its Trusted value by running the Set-PSResourceRepository cmdlet. Are you sure you want to install the PSResource from 'PSGallery'?
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "N"): a
Install-PSResource: C:\Code\Github\dotnet-adr\build.ps1:90
Line |
  90 |      Install-Module InvokeBuild -RequiredVersion $InvokeBuildModuleVer|      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Unable to successfully install package 'InvokeBuild': 'Object reference not set to an instance of an object.' to temporary installation path.
16:25:13 C:\Code\Github\dotnet-adr PS> get-module

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     0.0.3                 CompatPowerShellGet                 {Find-Command, Find-DscResource, Find-Module, Find-RoleCapability…}
Manifest   7.0.0.0               Microsoft.PowerShell.Management     {Add-Content, Clear-Content, Clear-Item, Clear-ItemProperty…}
Manifest   7.0.0.0               Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object…}
Script     0.0                   PoshBookmarks                       {Clear-Bookmark, Get-Bookmark, Get-BookmarkKeys, Restore-BookmarkStatus…}
Binary     3.0.20     beta20     PowerShellGet                       {Find-PSResource, Get-PSResource, Get-PSResourceRepository, Get-PSScriptFileInfo…}
Script     2.3.5                 PSReadLine                          {Get-PSReadLineKeyHandler, Get-PSReadLineOption, Remove-PSReadLineKeyHandler, Set-PSReadLineKeyHandler…}

@JamesDawson
Copy link
Contributor

JamesDawson commented May 16, 2024

Thanks for all that @nbarnwell. I've opened a draft PR which switches the build script over to using PSResourceGet - it'll be interesting to see how it runs in your environment?

My reading of that blog post, was that the compat layer wasn't getting switched-on by default until PS 7.5? It seems like your environment has already got those bits installed, so I'll do some testing this end to see if I can at least repro the issue after having installed those beta bits.

I think the challenge will be how/if we can put guardrails in without bloating the script with more 'module installation' boilerplate. For sure a sign of 'fun times' ahead!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants