Can't search the gallery for modules

Hi all!

This could be because we’re in an Azure web app rather than self-hosting.

When I try to search the PowerShell Gallery for a module I know exists (e.g. “moodle”), PSU spins for a bit and then says “no data”.

The log file has this exception:

System.Management.Automation.CmdletInvocationException: NuGet provider is required to interact with NuGet-based repositories. Please ensure that ‘2.8.5.201’ or newer version of NuGet provider is installed.

Is there something I have to do in Azure to ensure the required NuGet dependency is available?

Cheers,
Matt

Product: PowerShell Universal
Version: 2.5.4

I think you’ll have to install the package provider.

Install-PackageProvider -Name NuGet -RequiredVersion 2.8.5.201 -Force

OK, silly question: Can I do that from a PSU Script? Will it install the provider into the Azure Web App VM, or at least some persistent place that PSU can see it? Or is there a way to do it from the Azure Portal?

That’s a good question. It seems like you can bootstrap it manually: Bootstrapping NuGet - PowerShell | Microsoft Docs

I’m unsure if that will be persistent.

I’m also going to see if we can just do this in PSU to avoid having to do it manually. I wonder if it’s the reasons others have seen issues with installing modules from the Gallery.

1 Like

Yeah I just tried running that Install-Package cmdlet from a PSU Script, and was met with this:

[error] Unhandled Exception - Message:'The type initializer for 'Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType' threw an exception.' Name:'TypeInitializationException' Stack Trace:'   at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType.Create(Type tInterface, OrderedDictionary`2 instanceMethods, List`2 delegateMethods, List`1 stubMethods, List`2 usedInstances)

I’m a bit hamstrung without being able to install external modules, so it’ll be awesome if you’re able to pull it off natively within PSU.

I wonder if the Azure PowerShell cmdlets could do this. Execute the install-packageprovder cmdlet remotely. I’ll do some playing.

Update: Ah, the remote command is DOS, not PowerShell. I even tried running PowerShell from the console in the web app portal, but got this:

Should I log an issue on the Issues GitHub repo for this one, Adam? I’m kinda stuck now. Shelling out to PowerShell in the console doesn’t actually work, which (now that I’ve had a closer look) is obvious as you can see the green PowerShell prompt reverts instantly back to the white DOS prompt. Even powershell.exe -command { … } doesn’t work.

I’m tracking an issue related to this here: Components not installing from the Marketplace · Issue #688 · ironmansoftware/issues · GitHub

Others were experiencing a similar issue with UD Components (also installed from the PS Gallery). So far what I’ve determined is that, this issue seems to be two fold. In some environments, the NuGet provider is not installed (like Azure Web Apps). In other environments, the PS Gallery is untrusted (stock Windows Servers). Both result in failures to query and install modules.

One thing you can do in the mean time is deploy modules into the Repository\Modules folder within your web app. PSU should automatically pick those up and import them. It actually where the Gallery functionality saves them. You could use Save-Module locally to get them into the correct folder format and then place them into local git before deploying them to Azure.

This has me thinking it also may be nice to be able to upload modules from the admin console when Gallery access isn’t available. Even Publish-PSUModule or something.

1 Like

Hmm some of the modules I’ll want to install are pretty big (e.g. the SharePoint PNP or MicrosoftTeams modules), so I kinda don’t want to have to include copies of them in the PSU deployment repo. I’ll keep an eye on the issue - fingers crossed you find an elegant solution.

Oh, wait - can I add something to the “download.ps1” file that you provided in the example repo to install the modules I need into the appropriate location, before the azure/webapps-deploy action kicks in and copies the “psu” package over to Azure?

Yeah that should definitely work. PSU is just looking in that folder and you could perform all the module management during deployment.

So I’m guessing it’s Save-Module, but there’s no “Repository” folder under the .\pu “package” that’s being deployed, right? Is there somewhere inside the non-persistent PSU installation folder that we can save modules into and it’ll consider them “installed”?

Oh, that’s a good point. Forgot the repo was for deploying the application tier and not the configuration. What I think you’ll need to do is update your environments.ps1 to look into the folder you select within the application files. You can include additional PSModulePath locations in the environments.

So for example, if you are deploying to D:\wwwroot\site, you could then have a D:\wwwroot\site\modules folder. Then in your environments configuration, include D:\wwwroot\site\modules.

I think I’m following, but I have to ask: What are the chances that you figure out an elegant fix to the core issue before I get this hack working? I feel like maybe I’m better off just waiting.

I’ll certainly figure something out before the 2.6 release. That’s due out Dec 14th. The fix may be in a nightly before then.

1 Like

Looks like there’s still an issue in 2.6. Similar error:

2021-12-14 21:08:22.173 +00:00 [ERR] Error while searching for module
System.Management.Automation.CmdletInvocationException: NuGet provider is required to interact with NuGet-based repositories. Please ensure that '2.8.5.201' or newer version of NuGet provider is installed.
 ---> System.InvalidOperationException: NuGet provider is required to interact with NuGet-based repositories. Please ensure that '2.8.5.201' or newer version of NuGet provider is installed.
   at System.Management.Automation.MshCommandRuntime.ThrowTerminatingError(ErrorRecord errorRecord)
   --- End of inner exception stack trace ---
   at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
   at System.Management.Automation.PowerShell.Worker.ConstructPipelineAndDoWork(Runspace rs, Boolean performSyncInvoke)
   at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)
   at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)
   at System.Management.Automation.PowerShell.Invoke(IEnumerable input, PSInvocationSettings settings)
   at Universal.Server.Services.ModuleDiscoveryService.FindModule(String searchText) in D:\a\universal\universal\src\Universal.Server\Services\ModuleDiscoveryService.cs:line 36

Let me know if there’s anything I can do to fix it or to help diagnose!

Cheers,
Matt

Hmmm let me take a look at this. I thought this had been resolved. We included the package management modules with PSU

1 Like

If it helps, I tried making a Script with the command “Get-PackageProvider” to see if the NuGet package provider is installed, and it threw this exception:

Dec 15, 2021 10:37 AM [error] Unhandled Exception - Message:'The type initializer for 'Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType' threw an exception.' Name:'TypeInitializationException' Stack Trace:'   at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicType.Create(Type tInterface, OrderedDictionary`2 instanceMethods, List`2 delegateMethods, List`1 stubMethods, List`2 usedInstances)
   at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterface.CreateProxy(Type tInterface, Object[] instances)
   at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterface.DynamicCast(Type tInterface, Object[] instances)
   at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterface.DynamicCast[TInterface](Object[] instances)
   at Microsoft.PackageManagement.Internal.Utility.Plugin.DynamicInterfaceExtensions.As[TInterface](Object instance)
   at Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletBase.get_PackageManagementHost()
   at Microsoft.PowerShell.PackageManagement.Cmdlets.CmdletBase.SelectProviders(String[] names)
   at Microsoft.PowerShell.PackageManagement.Cmdlets.GetPackageProvider.ProcessRecordAsync()
   at Microsoft.PowerShell.PackageManagement.Cmdlets.AsyncCmdlet.<>c__DisplayClass83_0.<AsyncRun>b__0()' 

What a weird error. Usually this can happen when assemblies aren’t loaded properly. Did you run that in the integrated environment?

Yeah the default integrated environment.

1 Like

Could it be something to do with the fact that two different versions of PowerShellGet are installed by default? Perhaps it’s loading the wrong one? Or is PowerShellGet not involved when calling Get-PackageProvider?