dotnet-outdated: Cannot connect to a private nuget server (Azure DevOps)

I have tried to run dotnet outdated but it does not work on my computer. I have dotnet SDK 5.0.100 and the latest version of the tool 3.1.0. I also have the latest version of Microsoft.NuGet.CredentialProvider

Errors occurred while analyzing dependencies for some of your projects. Are you sure you can connect to all your configured NuGet servers? Unable to find DOTNET_HOST_PATH environment variable. If you use credential providers for your NuGet sources you need to have this set to the path to the dotnet executable.

I can set manually DOTNET_HOST_PATH but it still cannot connect to my private nuget source server :

$Env:DOTNET_HOST_PATH = "$env:ProgramFiles\dotnet\dotnet.exe"

Errors occurred while analyzing dependencies for some of your projects. Are you sure you can connect to all your configured NuGet servers?

Nuget server was added with the dotnet nuget add source command (with username and PAT token as password). The dotnet command dotnet list package --outdated works well.

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 8
  • Comments: 25 (8 by maintainers)

Most upvoted comments

Here in 2024, and none of these workarounds have worked for me. It’s clear that changes to the tool are needed to support using with Private NuGet Feeds from Azure DevOps.

I think the PR #493 could be rebased and adjusted to work in main again. This would at least give some logging to show exactly what is failing. For me, it runs locally, but not inside the pipeline and I have absolutely no idea why.

I’m going to dive into the code a bit more tomorrow, and see if I can get a custom build running in the pipeline with better logging. If I find anything I will add it here.

The problem still occurs in Azure Pipelines. I have also tried, as suggested by @PartTimeLegend to add the Nuget Authenticate step before this but I keep getting the following error for my private feeds in Azure Devops:

Errors occurred while analyzing dependencies for some of your projects. Are you sure you can connect to all your configured NuGet servers?

Unable to find DOTNET_HOST_PATH environment variable. If you use credential providers for your NuGet sources you need to have this set to the path to the `dotnet` executable.

Any suggestions on how to fix this?

On my private vsts agent, dotnet executable is located under /usr/bin/dotnet So you may be able to hard set the env variable, that should fix it.

variables :
  DOTNET_HOST_PATH: '/usr/bin/dotnet'

Alright, I got it working finally!!!

Essentially I did what @polferov posted, and added credentials into the config file and that seemed to work. I have no idea why the credential provider doesn’t work, but I have found a slightly easier way to do this in Azure DevOps now.

My pipeline tasks:

###
  - script: dotnet tool install --global dotnet-outdated-tool
    displayName: Install dotnet outdated
  - task: NuGetAuthenticate@1
    inputs:
      nugetServiceConnections: Private NuGet Feed
      forceReinstallCredentialProvider: true
  - task: DotNetCoreCLI@2
    displayName: restore solution nuget packages
    inputs:
      command: restore
      projects: ${{ parameters.SolutionFileDirectory }}/${{ parameters.SolutionFile }}
      feedsToUse: config
      nugetConfigPath: ${{ parameters.SolutionFileDirectory }}/nuget.config
      workingDirectory: ${{ parameters.SolutionFileDirectory }}
  - task: DotNetCoreCLI@2
    displayName: Run dotnet outdated
    inputs:
      command: custom
      custom: 'outdated'
      arguments: '-of Markdown -o outdated-results.md -utd'
      projects: ${{ parameters.ApplicationDirectory }}/${{ parameters.ApplicationProjectFile }}
      workingDirectory: ${{ parameters.SolutionFileDirectory }}
###

My nuget.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <clear />
    <add key="PrivateFeed" value="https://private-feed.dev/v3/index.json" />
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
  </packageSources>
  <packageSourceCredentials>
    <PrivateFeed>
        <add key="Username" value="VSTS" />
        <add key="ClearTextPassword" value="%VSS_NUGET_ACCESSTOKEN%" />
    </PrivateFeed>
  </packageSourceCredentials>
</configuration>

The NuGetAuthenticate@1 task adds the VSS_NUGET_ACCESSTOKEN environment variable for the rest of the job (source), so I use that as my access token in the config file using the % characters (source).

I’m still going to submit my PR for the “Specify NuGet config” change, in case you want a different nuget.config for pipelines than for devs locally. I might also create a new formatter that looks better in Azure DevOps as currently the colouring formatting doesn’t work.

I hope someone reads this and finds it helpful.

Just a heads up for anyone that ends up here like I did trying to debug this error message.

In my case, it was due to my nuget.config file being in a sub-folder and not the root folder of my source ie with other dotnet commands and tools I was specifying the config or the config wasn’t required so I didn’t think of this as being my issue at first. Once I moved it, my self-hosted build agent was able to run the tool just fine.

Ideally this tool would allow us to specify the path to the config file but it’s not a huge deal for me to move it and now everything is working well.

Here’s what worked for me (in a local setting, not in a pipeline):

  1. Definitely use the Azure Artifacts credential provider, but…
  2. Don’t use “dotnet restore --interactive” to get the credentials into it during a restore, but rather…
  3. Run the credentials provider manually (dotnet run .\pathToThePluginFolder\CredentialProvider.Microsoft.dll -U yourArtifactsUri -C). More info on the parameters here (in the help section).
  4. Make peace with the fact that more than one token might be requested

While before, dotnet restore would regularly forget any credentials, they seem to be stored for good now.

I was able to use the Nuget Authenticate task before it in order to get things working again. My issue seemed to be that dotnet-outdated-tool doesn’t appear to read the credentials used elsewhere in the pipeline.