28

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.

Codor
  • 16,805
  • 9
  • 30
  • 51
Tomino
  • 5,050
  • 6
  • 32
  • 47

4 Answers4

40

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>
Alvis
  • 2,821
  • 4
  • 32
  • 39
  • Hi, this finally seems to be working. And it's finally described in documentation. [openiddict docs](https://github.com/openiddict/openiddict-core) – Tomino Jun 08 '17 at 10:11
  • 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. – anand shukla Aug 11 '20 at 06:59
  • What is the next step after adding the Package source in nuget.config? – Sudhir Goswami Nov 06 '20 at 09:25
3

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

maartenba
  • 3,204
  • 14
  • 27
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

Naren
  • 549
  • 8
  • 9
  • 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. – Jonas Rembratt Apr 16 '21 at 11:30
1

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

BearsEars
  • 338
  • 1
  • 3
  • 15