1

I am trying to publish my Powershell modules to a VSTS Package Management feed. So far I have:

$securePass = ConvertTo-SecureString -String $RepositoryPassword -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ($RepositoryUsername, $securePass)


Write-Debug "Adding the Repository $RepositoryName"
Register-PSRepository -Name $RepositoryName -SourceLocation $RepositorySourceUri `
                            -PublishLocation $RepositoryPublishUri -Credential $cred `
                          -PackageManagementProvider Nuget -InstallationPolicy Trusted

$PublishParams = @{
    Path = $ModuleFolderPath
    ProjectUri = $ProjectUri
    Tags = $ModuleTags
    Repository = $RepositoryName
    NugetApiKey = $NugetApiKey
}

Publish-Module @PublishParams -Force -Verbose

However, I get the following error:

Publish-PSArtifactUtility : Failed to publish module 'Framework.Logging': 'Publishing to a ******** package management feed 'https://xxx.pkgs.visualstudio.com/_packaging/PowershellModules/nuget/v2' requires it to be registered as a NuGet package source. Retry after adding this source
'https://xxx.pkgs.visualstudio.com/_packaging/PowershellModules/nuget/v2' as NuGet package source by following the instructions specified at 'https://go.microsoft.com/fwlink/?LinkID=698608''. At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\1.1.2.0\PSModule.psm1:1227 char:17 + Publish-PSArtifactUtility -PSModuleInfo $moduleInfo ` + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [Write-Error], WriteErrorException + FullyQualifiedErrorId : FailedToPublishTheModule,Publish-PSArtifactUtility

The PSRepository is passed https://xxx.pkgs.visualstudio.com/_packaging/PowershellModules/nuget/v2 as both the source and publish Uris when it is created. Any pointers as to where I am going wrong?

1 Answer 1

3

Calling this command to add package source with NuGet.exe tool:

  1. Download Nuget.exe to a folder
  2. Open Command Prompt and navigate (CD) to that folder

command:

.\nuget.exe sources add -name [sourcename, such as myPSModuleFeed] -source https://[account].pkgs.visualstudio.com/_packaging/[feedname]/nuget/v2 -username test -password [PAT] -storePasswordInClearText

Article about Personal Access token: Authenticate access with personal access tokens for Team Services and TFS

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks, however that doesn't register the feed as a PSRepository. Does VSTS Package Management work with publishing via PowerShellGet (Publish-Module) or is the only way to currently publish to Package Management via Nuget.exe?
@Carl You don't need to update your code, still use it. What I mean is that you need to add the feed to Nuget sources (not publish) and Publish-Module works fine for me. You can check the sources in Nuget.config file (%appdata%\nugget foder)
@Carl The workflow is that 1. Call Nuget command to add sources (just one time) 2. Run your PowerShell script
Thanks, that all seems good now :) thanks for your help. For future ref I've posted my full implementation here: trycatchexfinally.co.uk/posts/…

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.