Defining NuGet restore sources in the csproj

  • Gérald Barré

If you use an internal NuGet server or just want to be explicit on the sources to use to restore package, you need to set the source in the NuGet configuration. You can use the dotnet nuget command to manage sources:

dotnet nuget add source --name
dotnet nuget add source --name myTeam --username user --password pass

However, this means that every developer needs to set the source on their machine. Also, you need to configure sources on the CI machine.

Instead, you can set the configuration for your project directly in the csproj file using the <RestoreSources> element.

<Project Sdk="Microsoft.NET.Sdk">


    <PackageReference Include="SixLabors.ImageSharp" Version="1.0.0-unstable1129" />


If you need a more advanced NuGet configuration, you still need to use a nuget.config file in your repository.

Do you have a question or a suggestion about this post? Contact me!

Follow me:
Enjoy this blog?Buy Me A Coffee