question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dotnet restore --source is lacking Username/Password/ClearTextPassword support

See original GitHub issue

Steps to reproduce

try to add a username/ClearTextPassword in the dotnet restore --source command

Expected behavior

My nuget repository requires authentication and it is not possible to add a username/ClearTextPassword in the dotnet restore command for a source

Actual behavior

It’s not possible to add a username/ClearTextPassword for a …source

Environment data

dotnet --info output: .NET Command Line Tools (1.0.0-preview2-1-003177)

Product Information: Version: 1.0.0-preview2-1-003177 Commit SHA-1 hash: a2df9c2576

Runtime Environment: OS Name: Windows OS Version: 10.0.14393 OS Platform: Windows RID: win10-x64

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
BenjaminAbtcommented, Dec 16, 2016

Workaround: use a NuGet.Config file with your custom feed.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <!-- DefaultPushSource key is similar to the 'DefaultPushSource' key of NuGet.config schema-->
    <!-- This can be used by administrators to prevent accidental publishing of packages to nuget.org -->
    <config>
        <add key="YourFeedName" value="---feedurl---" />
    </config>

    <!-- Default Package Sources -->
    <!-- They cannot be deleted or modified but can be disabled/enabled by user -->
    <!-- The following section is similar to 'packageSources' section of NuGet.config schema -->
    <packageSources>
        <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
    </packageSources>
</configuration>

Patch it during your CI build with a powershell script.

param($file, $feedName, $uname, $pass)

$xml =[xml](Get-Content $file)

# intention is to have

# <configuration>
#    <packageSourceCredentials>
#        <feedName>
#            <add key="Username" value="[uname] />
#            <add key="ClearTextPassword" value="[pass]" />
#        </feedName>
#    </packageSourceCredentials>
# </configuration>


# create the username node and set the attributes
$userNameNode = $xml.CreateElement("add")
$userNameNode.SetAttribute("key", "Username")
$userNameNode.SetAttribute("value", $uname)

# create the password node and set the attributes
$passwordNode = $xml.CreateElement("add")
$passwordNode.SetAttribute("key", "ClearTextPassword")
$passwordNode.SetAttribute("value", $pass)

# create the feedName node and attach the username and password nodes
$feedNameNode = $xml.CreateElement($feedName)
[void] $feedNameNode.AppendChild($userNameNode)
[void] $feedNameNode.AppendChild($passwordNode)

# create the packageSourceCredentials node and append the feedName node
$credentialsNode = $xml.CreateElement("packageSourceCredentials")
[void] $credentialsNode.AppendChild($feedNameNode);

# add the packageSourceCredentials node to the document's configuration node
$xml.configuration.AppendChild($credentialsNode);

# save the file to the same location
$xml.Save($file)

Then run dotnet restore --config NuGet.Config

0reactions
TheRealPiotrPcommented, Dec 18, 2016

I went ahead and moved this to nuget/home#4126. Closing out the CLI copy.

Read more comments on GitHub >

github_iconTop Results From Across the Web

dotnet restore --source is lacking Username/Password ...
Steps to reproduce try to add a username/ClearTextPassword in the dotnet restore --source command Expected behavior My nuget repository ...
Read more >
asp.net core - dotnet restore fails from Docker container
I ran into a similar problem with dotnet restore causing the Unable to load the service index for source https://api.nuget.org/v3/index.json ...
Read more >
dotnet restore command - .NET CLI
Learn how to restore dependencies and project-specific tools with the dotnet restore command.
Read more >
Troubleshooting NuGet Package Restore in Visual Studio
A description of common NuGet restore errors in Visual Studio and how to troubleshoot them.
Read more >
NuGet Package Restore
During restore, NuGet ignores the order of package sources, and uses the package from the first source that responds to requests. If restore...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found