Add custom package source to Visual Studio Code

29,776

Solution 1

To add to the answer, adding a nuget.config in the project solves it for the project. Adding to the root is ok. The config could look like this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="MyGet" value="https://www.myget.org/F/aspnet-contrib/api/v3/index.json" />
  </packageSources>
</configuration>

Solution 2

Another option that worked for me and was actually needed as part of my CI/CD pipeline is to use dotnet nuget add source <repo-url> --name <repo-name>

Simply call that before you call dotnet restore or dotnet build

Reference: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-nuget-add-source

Solution 3

Note - if your custom package source is password protected, then the credentials should also be part of the config file.

<packageSourceCredentials>
  <MyGet> <!--package src name-->
    <add key="Username" value="something" />
    <add key="ClearTextPassword" value="thepassword" />
  </MyGet>
</packageSourceCredentials>

And for anyone wondering why the credentials have to be in clear text (which defeats the whole purpose of having credentials in the first place, since this config file will also go into source control).

This is an open issue in dotnet / nuget cli. Ref github issue # 5909 & 1851

Solution 4

You can add a NuGet.config file and specify the package source in there. Some reference docs: https://docs.microsoft.com/en-us/nuget/schema/nuget-config-file

Share:
29,776
Tomino
Author by

Tomino

Software engineer in Zlín, Czech Republic Freelancer Sunseed Development s.r.o.

Updated on August 02, 2022

Comments

  • Tomino
    Tomino over 1 year

    Does anybody know how to add custom package source to Visual Studio Code?

    E.g. I'd like to add https://www.myget.org/F/aspnet-contrib/api/v3/index.json as a package source and drive these packages through project.json.

  • Tomino
    Tomino over 6 years
    Hi, this finally seems to be working. And it's finally described in documentation. openiddict docs
  • anand shukla about 3 years
    This worked for me too. I was searching for adding nuget.config for solution and i found below code from microsoft's github code repository.
  • Sudhir Goswami
    Sudhir Goswami about 3 years
    What is the next step after adding the Package source in nuget.config?
  • Jonas Rembratt over 2 years
    Just like with the any file you might keep around with sensitive dta in them, the nuget.config file needds to be included in your .gitignore file.
  • manymanymore
    manymanymore almost 2 years
    For me the nuget.config works only in the VS, but not VS Studio. So, this answer is wrong or incomplete.
  • Alexander over 1 year
    This is the most important part if you are using only Visual Studio Code. If Visual Studio and Visual Studio Code are installed, this can easily be done on Tools -> Options -> Nuget. But if on a machiner there is ony VS Code -> this is the only way to go! Thank you a lot!