Nuget-Config¶
Nuget-Config Reference¶
NuGet behavior is controlled by settings in different NuGet.Config
or nuget.config
files as described in Common NuGet configurations.
nuget.config
is an XML file containing a top-level <configuration>
node, which then contains the section elements described in this topic. Each section contains zero or more items
Setting names are case-insensitive, and values can use environment variables.
Add a nuget.config
file in the root of your project repository. This is considered a best practice as it promotes repeatability and ensures that different users have the same NuGet configuration. You may need to configure clear
elements to ensure no user or machine specific configuration is applied.
Example:¶
In the config file, the <packageSourceCredentials>
element contains child nodes for each applicable source name (spaces in the name are replaced with x0020). That is, for sources named "Contoso" and "Test Source", the config file contains the following when using encrypted passwords:
<packageSourceCredentials>
<Contoso>
<add key="Username" value="user@contoso.com" />
<add key="Password" value="..." />
</Contoso>
<Test_x0020_Source>
<add key="Username" value="user" />
<add key="Password" value="..." />
</Test_x0020_Source>
</packageSourceCredentials>
When using unencrypted passwords stored in an environment variable:
<packageSourceCredentials>
<Contoso>
<add key="Username" value="user@contoso.com" />
<add key="ClearTextPassword" value="%ContosoPassword%" />
</Contoso>
<Test_x0020_Source>
<add key="Username" value="user" />
<add key="ClearTextPassword" value="%TestSourcePassword%" />
</Test_x0020_Source>
</packageSourceCredentials>
Using a Local Folder as a NuGet Source¶
For development scenarios, you can use a local folder as a NuGet package source. This is useful for testing packages before publishing them to a remote feed.
To configure a local folder (for example, ./deps
) as a package source, add an entry to the <packageSources>
section and optionally set the repositoryPath
in your nuget.config
:
<configuration>
<packageSourceCredentials>
<Contoso>
<add key="Username" value="user@contoso.com" />
<add key="Password" value="..." />
</Contoso>
<Test_x0020_Source>
<add key="Username" value="user" />
<add key="Password" value="..." />
</Test_x0020_Source>
</packageSourceCredentials>
<config>
<add key="repositoryPath" value="./deps" />
</config>
</configuration>
- The
local
source points to the./deps
directory relative to your solution or project. - The
repositoryPath
setting ensures that any packages you restore or create locally are placed in the./deps
folder.
Tip:
You can add, remove, or update packages in the local folder manually or by using thedotnet pack
ornuget pack
commands.
For more details, see the NuGet documentation on package sources.