how to compile WPF project with environment variables but authentication failes

0 Answers 20 Views
Licensing
Peter
Top achievements
Rank 1
Iron
Iron
Peter asked on 05 Sep 2025, 03:56 PM

Hello. I have recently needed to repave my dev box. I got my latest code, setup two environment variables (username and password with the once only visible API key), as well as still have the nuget.config file and adding the proper telerik nuget server to the nuget manager. Unfortunately, I still have something wrong because when I compile, I get asked for my username and password what looks like it's the telerik nuget calls. Please help, this is driving me crazy. I'm just not able to figure this out.

 

I have ensured the nugetconfig is using the right\same environment variables as I have setup in the system environment. And the values are correct. Please help.

Peter
Top achievements
Rank 1
Iron
Iron
commented on 05 Sep 2025, 04:01 PM

I am seeing this popup.

After this popups as well.

 
Martin Ivanov
Telerik team
commented on 09 Sep 2025, 10:00 AM

Hello Peter, this dialog is displayed when the Visual Studio package manager tries to access a feed with authentication enabled (like the Telerik one). You need to enter your email address + password used to login to your telerik.com account. This stores the entered credentials in the Windows Credential Manager and in the corresponding nuget.config file (the global one by default). 

Then, the nugets will be restored using the saved credentials. The credentials will be searched in the global nuget.config or the config file in the solution folder (or recursively up in the file system hierarchy). If the config file doesn't contain the credentials you will see the popup that prompts you to enter them. Here is how my global nuget.config is defined:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="Telerik NuGet Server" value="https://nuget.telerik.com/v3/index.json" />
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="Microsoft Visual Studio Offline Packages" value="C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\" />
    <add key="Local NuGet Feed" value="C:\Temp\LocalNugetFeed" />    
  </packageSources>
  <packageSourceCredentials>
    <Telerik_x0020_NuGet_x0020_Server>
      <add key="Username" value="my-email-here@my-domain-here.com" />
      <add key="Password" value="encoded-password-here" />
    </Telerik_x0020_NuGet_x0020_Server>
  </packageSourceCredentials>
  <packageRestore>
    <add key="enabled" value="True" />
    <add key="automatic" value="True" />
  </packageRestore>
  <bindingRedirects>
    <add key="skip" value="False" />
  </bindingRedirects>
  <packageManagement>
    <add key="format" value="0" />
    <add key="disabled" value="False" />
  </packageManagement>
</configuration>

If you believe the setup is correct, you can double check if the project uses the correct nuget.config file.

And if this is correct too, then I would ask you to share the contents of your nuget.config file (by omitting all sensitive information), so I can check if there is something obvious that could cause the problem.

In case you are using Telerik NuGet Keys instead of your telerik.com email and password, you can check the following article and see if the information there helps as well.

Peter
Top achievements
Rank 1
Iron
Iron
commented on 16 Oct 2025, 08:13 PM | edited

Hi Martin. Thank you for the reply.  

Do I need to enter my username\password even though I'm using the environment variables? I don't want it to use the "saved creds", I want it to use the creds from the environment variables.

 

I have this nuget.config file in the root of my solution\projects.

<?xml version="1.0" encoding="utf-8"?>
<!-- Helpful docs https://docs.microsoft.com/en-us/nuget/reference/nuget-config-file -->
<configuration>
  <packageRestore>
    <add key="enabled" value="True" />
    <add key="automatic" value="True" />
  </packageRestore>
  <packageManagement>
    <add key="format" value="0" />
    <add key="disabled" value="False" />
  </packageManagement>
 
  <!-- Learn how to set a package source https://docs.microsoft.com/en-us/nuget/reference/nuget-config-file#packagesources -->
  <packageSources>
    <clear/>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="TelerikFromConfig" value="https://nuget.telerik.com/v3/index.json" protocolVersion="3"/>
  </packageSources>
 
  <!-- Learn how to use authenticated feeds https://docs.microsoft.com/en-us/nuget/consume-packages/consuming-packages-authenticated-feeds -->
  <!-- Learn how to setup a credential https://docs.microsoft.com/en-us/nuget/reference/nuget-config-file#packagesourcecredentials -->
  <packageSourceCredentials>
    <TelerikFromConfig>
      <add key="Username" value="%TelerikUsername%" />
      <add key="ClearTextPassword" value="%TelerikPassword%" />
        <!-- <add key="Username" value="api-key" />
        <add key="ClearTextPassword" value="NOPE" /> -->
    </TelerikFromConfig>
  </packageSourceCredentials>

</configuration>

 

and I have the corresponding environment variables setup. What am I missing?

Peter
Top achievements
Rank 1
Iron
Iron
commented on 16 Oct 2025, 08:19 PM

This is quite interesting, is this true? Is VS not using the environment variables?
Peter
Top achievements
Rank 1
Iron
Iron
commented on 16 Oct 2025, 08:22 PM

More info, when I try to do the dotnet restore, I'm getting this repeated over and over. Why is it not authorizing? It's as if it's not using the environment variables at all.

    C:\code\avanti15\DevSupportTools\BumpAtlasVersions.Tests\BumpAtlasVersions.Tests.csproj : error NU1301:

      Unable to load the service index for source https://nuget.telerik.com/v3/index.json.
        Response status code does not indicate success: 401 (Unauthorized).
Peter
Top achievements
Rank 1
Iron
Iron
commented on 16 Oct 2025, 08:42 PM

I have setup new keys, resused old ones. Nothing is working. This is very frustrating. I've even reset 
Martin Ivanov
Telerik team
commented on 20 Oct 2025, 01:40 PM

The Claude statement about the environment variables is partially true. The nuget.config file won't search by itself for environment variables - like %TELERIK_USERNAME% and %TELERIK_PASSWORD%. This is a special feature and syntax available on the YAML pipelines supported by GitHub Actions and Azure DevOps. So, if your build runs on one of these systems, then you can use the %var_name% syntax as described in the following blog post.

But if you run the build locally on your Windows machine, this variables access syntax won't work. In this case, you should store your credentials directly in the nuget.config file on your file system.

If this is your case, that means you need to use the same nuget.config (in your solution folder) both on the azure/github server (where it works) and on your local system (where it doesn't work). There is no straightforward approach to handle this situation, but there are some techniques to do so.

For example, you can create a PowerShell script that mimics the azure/github behavior and replaces the %environment_var% parts of the nuget.config file with  the corresponding values from the system environment variables of your machine. To try this approach, you can save the following script to a .ps1 file (for example named (restore.ps1) in your solution or project directory:

param (
    [string]$ConfigFile = ".\nuget.config"
)

# Ensure required environment variables exist
if (-not $env:TelerikUsername -or -not $env:TelerikPassword) {
    Write-Error "Please set environment variables 'TelerikUsername' and 'TelerikPassword' before running this script."
    exit 1
}

# Create a temporary config file with substituted values
$tempConfig = "$ConfigFile.temp"

Write-Host "Substituting credentials in $ConfigFile -> $tempConfig"
(Get-Content $ConfigFile -Raw) `
    -replace '%TelerikUsername%', $env:TelerikUsername `
    -replace '%TelerikPassword%', $env:TelerikPassword`
| Set-Content $tempConfig

# Run restore using the temporary file
Write-Host "Running dotnet restore using temporary config..."
dotnet restore --configfile $tempConfig

# Clean up (optional)
Remove-Item $tempConfig -Force

Then, you can execute it instead of only calling the dotnet restore command.

 

No answers yet. Maybe you can help?

Tags
Licensing
Asked by
Peter
Top achievements
Rank 1
Iron
Iron
Share this question
or