You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jun 13, 2024. It is now read-only.
Repository navigation
This repository was archived by the owner on Jun 13, 2024. It is now read-only.
PowerShellGet 2.1.4: Credential Providers | Authentication is STILL BROKEN #619
Register-PSRepository-Name Test -Source https://poshcode.pkgs.visualstudio.com/_packaging/PowerShell/nuget/v2
And get a list of modules:
Find-Module*-Repository Test
But what actually happens is that with no error I get no results.
But if I try it with nuget:
nuget sources add -Name Test -Source https://poshcode.pkgs.visualstudio.com/_packaging/PowerShell/nuget/v2
nuget list -source Test
It works fine, and I get a list of modules...
YOU'RE DOING IT WRONG
The problem is that PowerShellGet isn't looking up the credentials against the feed address.
Instead, it's looking up (or rather, relying on nuget to) the credentials against the final url with all the parameters in it. So we can make the Find-Module command work if we change the stored endpoint to this:
But this is because I've hard-coded the token to a particular search.
Of course the result is that when we don't use the environment variable (i.e. Remove-Item ENV:VSS_NUGET_EXTERNAL_FEED_ENDPOINTS) and do a Find-Module we get a "devicelogin" from the credential provider, but the credentials are cached for that specific URL, so if we Find-Module for any other specific module, or try anything else (like Install-Module), they will fail to find the cached credentials, and require going through the "devicelogin" again...
The worst part is that each time we go through the device login, you're creating a new PAT token that you'll never re-use...
I just got version 2.1.5 of PowershellGet but I'm still not truly able to use it with AzureDevops feeds at all as described in here. Here's what I did in my repro:
1). Install Windows 10 1903 from scratch
2). Run elevated powershell session
3). Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
4). Set-PSRepository -Name PSGallery -InstallationPolicy Truste
5). Install-Module -Name Package PowershellGet -Force (to install 2.1.5)
6). close powershell session and start a new one
7). Register-PSRepository -Name PrivatePSGallery -SourceLocation 'https://pkgs.dev.azure.com/myaccount/_packaging/myfeed/nuget/v2' -InstallationPolicy trusted -PackageManagementProvider nuget -Credential $vscred
($vscred is a System.Management.Automation.PSCredential object created using my Azure Devops PAT, myaccount and myfeed are our private Azure Devops account and feed names)
With this version, I get past Register-PSRepository. Previously I'd get an error about SourceLocation being an invalid web uri.
8). Install-Module -Name 'MyModule' -Repository PrivatePSGallery -Credential $vscred
but I receive an error instead.
What am I doing wrong here? I am passing a Credential parameter. Isn't this a supported use case for version 2.1.4 or newer?
I obtained a new token and used that instead to create $vscred. My issue appears to have been caused by a token which expired on June 14th. Sorry for the confusion.
Thanks for all the feedback, and patience--we've released updates to both PackageManagement and PowerShellGet yesterday to fix this and I wanted to see if that had resolved the issues you are facing?
As a workaround for this broken azure devops / azure artifacts powershell repository experience you can use a local repo and the builtin nuget commands in Azure DevOps to publish.
You will need to handle the dependencies by publishing them first or specifying as externalDependencies.
Register-PSRepository-Name PoshCode -SourceLocation https://pkgs.dev.azure.com/poshcode/_packaging/PowerShell/nuget/v2 -InstallationPolicy Trusted
# Find a module that's in that feed, it works! Huzzah!Find-Module ModuleBuilder
But then ...
# Find a module that's NOT in that feed:Find-Module PowerShellGet
At this point, it appears that whenever it fails to find a module in the Azure feed that requires credentials, it re-prompts for credentials, and regenerates a new PAT token.
If I again search for a module that does exist in my feed, it works fine. But the next time I search for one that does not exist in my feed, it prompts for credentials!
Ugh. Ok, maybe not. I don't understand. I tested this in PS5 earlier today and it worked.
Just now I ran a Find-Module without thinking in PS6, and it went back to requesting credentials when it couldn't find a module in our repo -- and NOW, PS5 seem broken again too. I don't understand at all.
Nick Hudacin (@nhudacin) we just published PowerShellGet and PackageManagement to our int gallery (www.poshtestgallery.com/api/v2) to resolve these errors. Please feel free to test these out and see if behavior is working appropriately. The credential provider should only be prompted if the -credential parameter is not passed in.
You can register the int gallery and install the respective modules by running:
Thanks Sydney Smith (@SydneyhSmith). I installed the two modules from your int gallery, closed all of my powershell windows, and opened up a fresh one. I'm getting all sorts of errors now:
~> Register-PSRepository -Name 'internal' -SourceLocation 'https://pkgs.dev.azure.com/my_org/_packaging/powershell/nuget/v2' -InstallationPolicy Trusted
Start-Process : This command cannot be run due to the error: The system cannot find the file specified.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2\PSModule.psm1:9330 char:5
+ Start-Process $filename -ArgumentList "$arguments -V minimal" `
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand
Start-Process : This command cannot be run due to the error: The system cannot find the file specified.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2\PSModule.psm1:9337 char:5
+ Start-Process $filename -ArgumentList "$argumentsNoRetry -V verbo ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand
Exception calling "Match" with "2" argument(s): "Value cannot be null.
Parameter name: input"
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2\PSModule.psm1:9346 char:5
+ $username = [System.Text.RegularExpressions.Regex]::Match($conten ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ArgumentNullException
Exception calling "Match" with "2" argument(s): "Value cannot be null.
Parameter name: input"
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2\PSModule.psm1:9347 char:5
+ $password = [System.Text.RegularExpressions.Regex]::Match($conten ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ArgumentNullException
Start-Process : This command cannot be run due to the error: The system cannot find the file specified.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2\PSModule.psm1:9330 char:5
+ Start-Process $filename -ArgumentList "$arguments -V minimal" `
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand
Start-Process : This command cannot be run due to the error: The system cannot find the file specified.
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2\PSModule.psm1:9337 char:5
+ Start-Process $filename -ArgumentList "$argumentsNoRetry -V verbo ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Start-Process], InvalidOperationException
+ FullyQualifiedErrorId : InvalidOperationException,Microsoft.PowerShell.Commands.StartProcessCommand
Exception calling "Match" with "2" argument(s): "Value cannot be null.
Parameter name: input"
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2\PSModule.psm1:9346 char:5
+ $username = [System.Text.RegularExpressions.Regex]::Match($conten ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ArgumentNullException
Exception calling "Match" with "2" argument(s): "Value cannot be null.
Parameter name: input"
At C:\Program Files\WindowsPowerShell\Modules\PowerShellGet\2.2\PSModule.psm1:9347 char:5
+ $password = [System.Text.RegularExpressions.Regex]::Match($conten ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : ArgumentNullException
Register-PSRepository : The specified repository 'internal' is unauthorized and cannot be registered. Try running
with -Credential.
At line:1 char:1
+ Register-PSRepository -Name 'internal' -SourceLocation 'https:// ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : RepositoryCannotBeRegistered,Register-PSRepository
Thanks Andy Feller (@andyfeller), we are integrating credential persistence and will likely have this out with the next release. We are integrating with Secret Management with PowerShellGet.
Here is some blog posts describing Secret Management:
This came up on my radar while trying to put this PoC together but just trying to get something working, so I hadn't delved deeper, you know? Let me dig into this and see how to incorporate to GitHub Actions.
Don't know if anybody at Microsoft still cares, but the issue persists.
I have a deployment group of buildservers and another of developer machines. They are identical in OS and most of the setup.
After spending hours reading the docs and redoing everything many times I also found that passing credentials with every command is the only way. Well if it's so, it's so...
BUT I furthermore found out that on my buildservers registering a repository behaves differently on dev vs buildservers.
I run the exact same script on both machines:
On my buildservers it runs just fine.
On the dev machines it tries to use DeviceFlow four times (times out every time) before adding the repository anyway (successfully).
The main difference I can find is that on dev machines Visual Studio is installed. On the build servers it isn't. I cannot say for sure that's the issue but that is what I suspect to be the issue...
I still think it's sad to see that the issue has persisted for years, costs the community loads of time and frustration and nobody is bothering to fix it (reliably)...
I ran into the same problem as many here, where you are constantly taken to the device flow even thought it seems like you should not be. But using the troubleshooting tips for the Azure Artifacts Credential Provider I figured out that our Azure DevOps authentication setup required multifactor authentication. Maybe that's why I was getting the device flow so much? But even if that's not it, I found a reasonable alternative that means I don't need to enter credentials all the time.
Set a user-level environment variable VSS_NUGET_EXTERNAL_FEED_ENDPOINTS to something like: '{"endpointCredentials": [{"endpoint":"https://pkgs.dev.azure.com/<organization>/_packaging/<feed>/nuget/v2", "username":"<youremail>, "password":"<pat>"}]}'
Make sure it worked with Find-Module -Repository YourFeedName
Setting up the VSS_NUGET_EXTERNAL_FEED_ENDPOINTS environment variable may make you uneasy. But for me it's like using a PAT in a nuget.config like I've done in the past. But you do have to remember to re-generate the PAT and update the environment variable when it expires.
Tom Winter (@twinter-amosfivesix) can you try using our latest prerelease version (can be found here). There is an integration with the SecretMangement module that allows for a smoother experience with handling credentials and credential persistence.
Tom Winter (@twinter-amosfivesix) that's a pretty hefty amount of prerequisites. I was just trying to come up with some simple instructions for people to install a utility module from our Azure Artifacts. For CI/CD that's fine, but just to get a module that's a lot of hoops.
alerickson I tried the latest prerelease and couldn't get it working but maybe the steps are different since all the commands changed in psg 3.0. IDK... I'm giving up on this and telling people to store their pat in a file and pass -Credential everywhere. Nothing else works.
Cody Batt (@CodyBatt) Yes credential management is different in PowerShellGetV3. It relies on Microsoft.PowerShell.SecretsManagement module, and you can look at this blogpost to get familiar with SecretsManagement, install that module and set up a vault. In order for credential persistence to work with PSGet, it needs SecretsManagement, otherwise if it's not there it will automatically give an error. After the vault is set up with SecretsManagement then all you need to do is create a PSCredentialInfo object like this example here (which assumes you have a vault named "testvault" already).
You should register (or set) the repository with the -CredentialInfo, like this example here
We'll put out a blogpost by end of this month to show all the steps for working with Credentials in PSGetV3, thank you for sharing this feedback!
Anam Navied (@anamnavi) Right, I tried to set it up with SecretsManagment and didn't get anywhere. Succinct documentation for getting it set up will be a big help.
Tom Winter (@twinter-amosfivesix) In case you rely on the command during a pipeline, you don't even need to do it manually. It suffices to add a NuGet Authenticate step which creates the environment variable for you.
That way you don't need to store a PAT somewhere. Instead it will be generated with the appropriate permissions that the agent actually has.
Sorry I never got any notifications about replies. I was just trying this again recently and I was not getting the repeated prompt for credentials. Still using PSGetV2. So not sure what was going on there.
And yes NuGet Authenticate is what you'd use in an Azure DevOps pipeline. I haven't gotten there yet.
Tom Winter (@twinter-amosfivesix) are you able to try using PowerShellGetV3? If so, please see my earlier message about using credential management with PSGetV3, thanks!
I did a deep dive today to come up with a cleaner process for using Azure Artifact Feeds that I could hand off to non-technical people. During that dive I found that the "easiest" work-around may just be to have Visual Studio installed. There's more detail below if anyone is interested.
The cleaner process for downloading from feeds using PowerShellGet v2 that I came up with today follows.
That gets you the latest version of PowerShellGet and installs the Azure Artifacts Credential Provider. You will need to restart your PowerShell window after you've done the above steps.
The VssCredentialProvider variable can have "netfx" replaced with "netcore" if you're running in PowerShell Core.
You can get around the credentials request by installing Visual Studio due to a bug where PowerShellGet presumes that $env:NUGET_PLUGIN_PATHS will be set to the location of the credential provider. This always fails on Windows since that environment variable is the root directory where Nuget gets its plugins not a direct pointer to the credential provider. The module really needs to go looking for the credential provider. Linux and MacOS work though since that case falls through to a .NET Core specific scenario and builds out the entire path to the credential provider.
Windows thus always fails the first check for the credential provider and falls back to "vswhere" to locate the provider. If you don't have Visual Studio installed then the check fails.
However, even if you solve the problem by pointing $env:NUGET_PLUGIN_PATHS to the credential provider you've only won half the battle. Your registration will work and even Find-Package will work but install-module and install-package will fail because they cannot authenticate to the feed. I've tried install-package -verbose -debug to narrow down what exactly is going wrong but without something to debug into the output isn't useful. I cannot even locate the source that is raising the issue.
I hope this helps anyone else having the same issue.
The Install-Module and Find-Module commands work properly though when registered with the same repository URI, so I know that the Azure Artifacts Credential Provider is setup properly.
What's worse though is it seems that the latest version 3.0.23 of PowerShellGet has broken the Install-Module and Find-Module commands completely; see PowerShell/PowerShellGet#58. Luckily I still have PowerShellGet v3.0.12 installed so the commands still work on my local machine, but new servers that I'm setting up are not able to connect to our Azure Artifacts feed without the -Credential parameter.
I created the AzureArtifactsPowerShellModuleHelper module a while back to help solve this issue, but found that sometimes even with that module PowerShellGet 2.2.5 still couldn't access the feed and we'd need to use the prerelease v3 version. With v3.0.23 broken though, and older v3 versions delisted and thus can't be installed, there's not much we can do when v2.2.5 has issues.
Here's a screenshot showing the issue. If you need any other information for troubleshooting let me know; I'm happy to provide anything that can help get this issue resolved.
Activity
alerickson commentedon Jun 17, 2019
Getting out a PackageMangement release today that will fix this!
tristanbarcelon commentedon Jun 19, 2019
I just got version 2.1.5 of PowershellGet but I'm still not truly able to use it with AzureDevops feeds at all as described in here. Here's what I did in my repro:
1). Install Windows 10 1903 from scratch
2). Run elevated powershell session
3). Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
4). Set-PSRepository -Name PSGallery -InstallationPolicy Truste
5). Install-Module -Name Package PowershellGet -Force (to install 2.1.5)
6). close powershell session and start a new one
7). Register-PSRepository -Name PrivatePSGallery -SourceLocation 'https://pkgs.dev.azure.com/myaccount/_packaging/myfeed/nuget/v2' -InstallationPolicy trusted -PackageManagementProvider nuget -Credential $vscred
($vscred is a System.Management.Automation.PSCredential object created using my Azure Devops PAT, myaccount and myfeed are our private Azure Devops account and feed names)
With this version, I get past Register-PSRepository. Previously I'd get an error about SourceLocation being an invalid web uri.
8). Install-Module -Name 'MyModule' -Repository PrivatePSGallery -Credential $vscred
but I receive an error instead.
What am I doing wrong here? I am passing a Credential parameter. Isn't this a supported use case for version 2.1.4 or newer?
I obtained a new token and used that instead to create $vscred. My issue appears to have been caused by a token which expired on June 14th. Sorry for the confusion.
SydneyhSmith commentedon Jun 19, 2019
Thanks for all the feedback, and patience--we've released updates to both PackageManagement and PowerShellGet yesterday to fix this and I wanted to see if that had resolved the issues you are facing?
CC: alerickson
jasonchester commentedon Jun 24, 2019
still having a lot of trouble using Publish-Script and Publish module from an azure devops pipeline...
here's the relevant snippets from my azure-pipelines.yml
even though I have specified the Credential, I am getting the device flow prompt
jasonchester commentedon Jun 24, 2019
When specifying the credentials using the environment variable, I also get an error.
jasonchester commentedon Jun 24, 2019
As a workaround for this broken azure devops / azure artifacts powershell repository experience you can use a local repo and the builtin nuget commands in Azure DevOps to publish.
You will need to handle the dependencies by publishing them first or specifying as externalDependencies.
I created a gist here of a pipeline that uses this workaround.
https://gist.github.com/jasonchester/12597c0af92e65b728644155a19f05a3
Jaykul commentedon Jun 24, 2019
Sydney Smith (@SydneyhSmith) the new release is so much better, but still broken.
EVERY TIME I search for a module that is not in the authenticated feed, I get prompted for credentials.
Simple repro:
Assuming I have installed the Nuget Credential provider using the script from their github in an elevated console:
And I have updated to the current versions of both relevant modules:
In a new window ...
But then ...
At this point, it appears that whenever it fails to find a module in the Azure feed that requires credentials, it re-prompts for credentials, and regenerates a new PAT token.
If I again search for a module that does exist in my feed, it works fine. But the next time I search for one that does not exist in my feed, it prompts for credentials!
Jaykul commentedon Jun 25, 2019
Ok, update ...
After re-installing the credential helper (with
-Force) I've been able to get this to work now ...After exiting all PowerShell windows and re-opening, I was able to register and search for modules both in my feed and the PSGallery feed.
Additionally, putting JSON in
ENV:VSS_NUGET_EXTERNAL_FEED_ENDPOINTSseems to work now too.Jaykul commentedon Jun 25, 2019
Ugh. Ok, maybe not. I don't understand. I tested this in PS5 earlier today and it worked.
Just now I ran a Find-Module without thinking in PS6, and it went back to requesting credentials when it couldn't find a module in our repo -- and NOW, PS5 seem broken again too. I don't understand at all.
nhudacin commentedon Jul 3, 2019
I'm not sure this should be closed. I'm hitting all the same errors you're hitting.
SydneyhSmith commentedon Jul 3, 2019
Nick Hudacin (@nhudacin) we just published PowerShellGet and PackageManagement to our int gallery (www.poshtestgallery.com/api/v2) to resolve these errors. Please feel free to test these out and see if behavior is working appropriately. The credential provider should only be prompted if the -credential parameter is not passed in.
You can register the int gallery and install the respective modules by running:
nhudacin commentedon Jul 3, 2019
Thanks Sydney Smith (@SydneyhSmith). I installed the two modules from your int gallery, closed all of my powershell windows, and opened up a fresh one. I'm getting all sorts of errors now:
alerickson commentedon Jul 3, 2019
Nick Hudacin (@nhudacin) you’ll need the credential provider itself installed (see: https://devblogs.microsoft.com/powershell/using-powershellget-with-azure-artifacts/#). That error isn't the most helpful but if you don’t have the credential provider installed you’ll need to use the -credential parameter
37 remaining items
StevenBucher98 commentedon Oct 28, 2021
Thanks Andy Feller (@andyfeller), we are integrating credential persistence and will likely have this out with the next release. We are integrating with Secret Management with PowerShellGet.
Here is some blog posts describing Secret Management:
andyfeller commentedon Oct 29, 2021
Thanks, Steven Bucher (@StevenBucher98)! ✨
This came up on my radar while trying to put this PoC together but just trying to get something working, so I hadn't delved deeper, you know? Let me dig into this and see how to incorporate to GitHub Actions.
itsme112358 commentedon Jul 27, 2022
Don't know if anybody at Microsoft still cares, but the issue persists.
I have a deployment group of buildservers and another of developer machines. They are identical in OS and most of the setup.
After spending hours reading the docs and redoing everything many times I also found that passing credentials with every command is the only way. Well if it's so, it's so...
BUT I furthermore found out that on my buildservers registering a repository behaves differently on dev vs buildservers.
I run the exact same script on both machines:
On my buildservers it runs just fine.
On the dev machines it tries to use DeviceFlow four times (times out every time) before adding the repository anyway (successfully).
The main difference I can find is that on dev machines Visual Studio is installed. On the build servers it isn't. I cannot say for sure that's the issue but that is what I suspect to be the issue...
I also found the fix via Add-Packagesource here: https://andrewmatveychuk.com/how-to-access-private-powershell-repository-from-azure-pipeline/
I still think it's sad to see that the issue has persisted for years, costs the community loads of time and frustration and nobody is bothering to fix it (reliably)...
twinter-amosfivesix commentedon Oct 4, 2022
I ran into the same problem as many here, where you are constantly taken to the device flow even thought it seems like you should not be. But using the troubleshooting tips for the Azure Artifacts Credential Provider I figured out that our Azure DevOps authentication setup required multifactor authentication. Maybe that's why I was getting the device flow so much? But even if that's not it, I found a reasonable alternative that means I don't need to enter credentials all the time.
The key is to setup the
VSS_NUGET_EXTERNAL_FEED_ENDPOINTSenvironment variable as talked about here. You follow mostly the steps in Use an Azure Artifacts feed as a private PowerShell repository but instead of passing credentials, you rely onVSS_NUGET_EXTERNAL_FEED_ENDPOINTS.So basically this:
VSS_NUGET_EXTERNAL_FEED_ENDPOINTSto something like:'{"endpointCredentials": [{"endpoint":"https://pkgs.dev.azure.com/<organization>/_packaging/<feed>/nuget/v2", "username":"<youremail>, "password":"<pat>"}]}'Register-PSRepository -Name "YourFeedName" -SourceLocation "https://pkgs.dev.azure.com/<organization>/_packaging/<feed>/nuget/v2" -PublishLocation "https://pkgs.dev.azure.com/<organization>/_packaging/<feed>/nuget/v2" -InstallationPolicy TrustedRegister-PackageSource -Name "YourFeedName" -Location "https://pkgs.dev.azure.com/<organization>/_packaging/<feed>/nuget/v2" -ProviderName NuGet -Trusted -SkipValidateInstall-Moduleto work.Find-Module -Repository YourFeedNameSetting up the
VSS_NUGET_EXTERNAL_FEED_ENDPOINTSenvironment variable may make you uneasy. But for me it's like using a PAT in anuget.configlike I've done in the past. But you do have to remember to re-generate the PAT and update the environment variable when it expires.alerickson commentedon Oct 10, 2022
Tom Winter (@twinter-amosfivesix) can you try using our latest prerelease version (can be found here). There is an integration with the SecretMangement module that allows for a smoother experience with handling credentials and credential persistence.
CodyBatt commentedon Nov 3, 2022
Tom Winter (@twinter-amosfivesix) that's a pretty hefty amount of prerequisites. I was just trying to come up with some simple instructions for people to install a utility module from our Azure Artifacts. For CI/CD that's fine, but just to get a module that's a lot of hoops.
alerickson I tried the latest prerelease and couldn't get it working but maybe the steps are different since all the commands changed in psg 3.0. IDK... I'm giving up on this and telling people to store their pat in a file and pass -Credential everywhere. Nothing else works.
anamnavi commentedon Nov 7, 2022
Cody Batt (@CodyBatt) Yes credential management is different in PowerShellGetV3. It relies on Microsoft.PowerShell.SecretsManagement module, and you can look at this blogpost to get familiar with SecretsManagement, install that module and set up a vault. In order for credential persistence to work with PSGet, it needs SecretsManagement, otherwise if it's not there it will automatically give an error. After the vault is set up with SecretsManagement then all you need to do is create a PSCredentialInfo object like this example here (which assumes you have a vault named
"testvault"already).You should register (or set) the repository with the
-CredentialInfo, like this example hereWe'll put out a blogpost by end of this month to show all the steps for working with Credentials in PSGetV3, thank you for sharing this feedback!
CodyBatt commentedon Nov 7, 2022
Anam Navied (@anamnavi) Right, I tried to set it up with SecretsManagment and didn't get anywhere. Succinct documentation for getting it set up will be a big help.
itsme112358 commentedon Dec 20, 2022
Tom Winter (@twinter-amosfivesix) In case you rely on the command during a pipeline, you don't even need to do it manually. It suffices to add a NuGet Authenticate step which creates the environment variable for you.
That way you don't need to store a PAT somewhere. Instead it will be generated with the appropriate permissions that the agent actually has.
twinter-amosfivesix commentedon Dec 27, 2022
Sorry I never got any notifications about replies. I was just trying this again recently and I was not getting the repeated prompt for credentials. Still using PSGetV2. So not sure what was going on there.
And yes NuGet Authenticate is what you'd use in an Azure DevOps pipeline. I haven't gotten there yet.
anamnavi commentedon Jan 9, 2023
Tom Winter (@twinter-amosfivesix) are you able to try using PowerShellGetV3? If so, please see my earlier message about using credential management with PSGetV3, thanks!
savagemonitor commentedon Feb 24, 2023
I did a deep dive today to come up with a cleaner process for using Azure Artifact Feeds that I could hand off to non-technical people. During that dive I found that the "easiest" work-around may just be to have Visual Studio installed. There's more detail below if anyone is interested.
The cleaner process for downloading from feeds using PowerShellGet v2 that I came up with today follows.
One time do this:
That gets you the latest version of PowerShellGet and installs the Azure Artifacts Credential Provider. You will need to restart your PowerShell window after you've done the above steps.
Then in PowerShell you can do this:
The VssCredentialProvider variable can have "netfx" replaced with "netcore" if you're running in PowerShell Core.
You can get around the credentials request by installing Visual Studio due to a bug where PowerShellGet presumes that
$env:NUGET_PLUGIN_PATHSwill be set to the location of the credential provider. This always fails on Windows since that environment variable is the root directory where Nuget gets its plugins not a direct pointer to the credential provider. The module really needs to go looking for the credential provider. Linux and MacOS work though since that case falls through to a .NET Core specific scenario and builds out the entire path to the credential provider.Windows thus always fails the first check for the credential provider and falls back to "vswhere" to locate the provider. If you don't have Visual Studio installed then the check fails.
However, even if you solve the problem by pointing $env:NUGET_PLUGIN_PATHS to the credential provider you've only won half the battle. Your registration will work and even
Find-Packagewill work butinstall-moduleandinstall-packagewill fail because they cannot authenticate to the feed. I've triedinstall-package -verbose -debugto narrow down what exactly is going wrong but without something to debug into the output isn't useful. I cannot even locate the source that is raising the issue.I hope this helps anyone else having the same issue.
CodyBatt commentedon Feb 25, 2023
Anam Navied (@anamnavi) did the blog post get created? Can you link it here?
deadlydog commentedon Mar 14, 2024
What is the status of this? It seems that
Install-PSResourceandFind-PSResourcestill do not work properly with Azure Artifacts and the Azure Artifacts Credential Provider in Microsoft.PowerShell.PSResourceGet v1.0.3; they result in a401 (Not Authorized)error.The
Install-ModuleandFind-Modulecommands work properly though when registered with the same repository URI, so I know that the Azure Artifacts Credential Provider is setup properly.What's worse though is it seems that the latest version 3.0.23 of PowerShellGet has broken the
Install-ModuleandFind-Modulecommands completely; see PowerShell/PowerShellGet#58. Luckily I still have PowerShellGet v3.0.12 installed so the commands still work on my local machine, but new servers that I'm setting up are not able to connect to our Azure Artifacts feed without the-Credentialparameter.I created the AzureArtifactsPowerShellModuleHelper module a while back to help solve this issue, but found that sometimes even with that module PowerShellGet 2.2.5 still couldn't access the feed and we'd need to use the prerelease v3 version. With v3.0.23 broken though, and older v3 versions delisted and thus can't be installed, there's not much we can do when v2.2.5 has issues.
Here's a screenshot showing the issue. If you need any other information for troubleshooting let me know; I'm happy to provide anything that can help get this issue resolved.
deadlydog commentedon Mar 14, 2024
I noticed afterward that this issue is for PowerShellGet v2. I've opened this new issue in the PSResourceGet repo: PowerShell/PSResourceGet#1601