Add custom package source to Visual Studio Code

47.9k views Asked by At

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.

4

There are 4 answers

4
Alvis On BEST 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>
0
maartenba On

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

2
Naren On

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

0
BearsEars On

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://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-nuget-add-source