Skip to content
This repository was archived by the owner on Jun 13, 2024. It is now read-only.

PowerShellGet cannot publish modules with dependencies to galleries which require credentials #142

Closed
Jaykul opened this issue Jun 19, 2017 · 5 comments

Comments

@Jaykul
Copy link

Jaykul commented Jun 19, 2017

If a gallery requires Credentials for search, PowerShellGet cannot publish modules to that gallery if they have RequiredModules which are not external.

Expected Behavior

Publish-Module should publish modules, as long as their dependencies are either available on the repository being published to, or marked external.

Current Behavior

PowerShellGet cannot resolve the module dependency

Possible Solution

Pass credentials through to the dependency check

Steps to Reproduce (for bugs)

  1. Create two modules, where one depends on the other.
  2. Set up a repository where credentials are required for search and install.
  3. Attempt to publish both modules

Context

After the fixes described in the workaround for #133 we have been successfully using Visual Studio Online as a PowerShell repository. Now we need to publish modules which have dependencies, and we've found that the dependency check that PowerShellGet does does not pass the credentials through (even though it does pass the credentials to the Find-Module which tests to see if the module's already published, it does not pass them to Get-ModuleDependencies

For example:

<#1#> Get-Module Q* -list | Format-Table Name, RequiredModules

Name                       RequiredModules
----                       ---------------
Questionmark.Assemblies    {Microsoft.PowerShell.Utility}
Questionmark.Database      {Questionmark.Assemblies}

In the first one, I've marked Microsoft.PowerShell.Utility as an ExternalModuleDependencies -- even though I think PowerShellGet should be smart enough to figure out the built-in modules are ... built-in.

When I try to publish, this happens:

<#2#>  Publish-Module -Name Questionmark.Assemblies -Repository QM -NuGetApi BUG -Cred $cred
<#3#>  Publish-Module -Name Questionmark.Database -Repository QM -NuGetApi BUG-Cred $cred
Publish-PSArtifactUtility : PowerShellGet cannot resolve the module dependency
'Questionmark.Assemblies' of the module 'Questionmark.Database' on the repository 'QM'.
Verify that the dependent module 'Questionmark.Assemblies' is available in the repository 'QM'.
If this dependent module 'Questionmark.Assemblies' is managed externally, add it to the
ExternalModuleDependencies entry in the PSData section of the module manifest.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.1.2.0\PSModule.psm1:1227 char:17
+                 Publish-PSArtifactUtility -PSModuleInfo $moduleInfo `
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Publish-PSArtifactUtility], InvalidOperationException
    + FullyQualifiedErrorId : UnableToResolveModuleDependency,Publish-PSArtifactUtility

<#4#> Find-Module -Name Questionmark.Assemblies -Repository PoshCode -Credential $cred

Version    Name                                Repository           Description
-------    ----                                ----------           -----------
17.6.99... Questionmark.Assemblies             PoshCode             A dependency module for loading the assemblies commonly needed by Questionmark modules

PowerShellGet version 1.1.2

@gogbg
Copy link
Contributor

gogbg commented Jun 19, 2017

I think it is not possible to pass credentials to nuget.exe in non-interactive session. I`m dealing with it by creating/updating a user profile nuget config file every time.

@bmanikm
Copy link
Contributor

bmanikm commented Jun 19, 2017

@Jaykul This issue should be resolved with PR #93 . Could you please try with the latest version (1.1.3.1) of PowerShellGet and let us know if this issue is resolved or not?

@Jaykul
Copy link
Author

Jaykul commented Jun 19, 2017

What nuget.exe can do is mostly irrelevant -- the cmdlets support -Credential ...

When we invoke Publish-Module it calls Find-Module to determine if the module has already been published. In this first call, it passes the credential, so that works.

However, after that, it calls Publish-PSArtifactUtility (which is an internal function containing the common part of publishing scripts and modules). That calls Get-ModuleDependencies which in turn calls ValidateAndGet-RequiredModuleDetails which eventually calls ... you guessed it: Find-Module.

Although Find-Module obviously does have a -Credential parameter, none of the internal commands (Publish-PSArtifactUtility, Get-ModuleDependencies, ValidateAndGet-RequiredModuleDetails) do, so the whole process falls apart if you have any dependencies at all.

@dotps1
Copy link
Contributor

dotps1 commented Jun 19, 2017

i submitted a PR that was accepted that added this.
https://github.com/PowerShell/PowerShellGet/pull/93

@Jaykul
Copy link
Author

Jaykul commented Jun 19, 2017

You are absolutely right, @bmanikm, @dotps1 -- I can't believe I didn't see that release, but in my own defense, it came out right after I started investigating all of this! 😉 I took vacation and got sidetracked by two other more "urgent" issues in the backlog, so the whole thing took longer than it should have.

Thanks guys -- I should have thought to check for a new release when I got back. I'll close this.

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

No branches or pull requests

4 participants