We are working on automating our builds using Cake Build and we use NuGet packages from nuget.org but we also have our own NuGet Feed server which has a username/password authentication to access. How do we utilize Cake Build with a custom NuGet feed server with authentication?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
Cake utilizes the
NuGet.exe
for installing tools, addins and the NuGet aliases.Unless you have a source specified in the
#tool
/#addin
directives or provided to the NuGet aliases, thenNuGet.exe
will look fornuget.config
in current path and eventually end up at current users global settings (%AppData%\NuGet\NuGet.config
).You have a couple of options, if you don't want to change anything in Cake files or your repository, then you can store your credentials for your user globally and
NuGet.exe
will pick these up example:disclaimer some versions of
NuGet.exe
and dotnet CLI have issues with encrypted passwords, an workaround for this is adding the-StorePasswordInClearText
like this:Then your credentials are saved in plain text, which works with the drawback that your credentials are saved in plain text.
You can also override
nuget.config
settings by specifying a specific source for#tool
/#addin
directives and NuGet aliases.#tool directive
Below is an example to illustrate providing a source for the
#tool
directivebecomes
and i.e. for the official V2 nuget feed
#addin directive
Below is an example to illustrate providing a source for the
#addin
directivebecomes
and i.e. for the official V2 nuget feed
NuGet aliases
The NuGet aliases have commands like NuGetAddSource and NuGetHasSource for working directly with sources, these are great if you for example wish to add sources to a CI before a NuGet restore step like below:
The above will just add sources to your existing
nuget.config
, but you can also override the NuGet source for the NuGetInstall & NuGetRestore aliases.NuGetInstall
The NuGetInstall alias has overloads that take an NuGetInstallSettings tool settings class which has an Source property which you can use to override which feeds are used, example:
NuGetRestore
Similarly the NuGetRestore alias has overloads that lets you specify an NuGetRestoreSettings which has an Source property which you can use to override which feeds are used, example:
Conclusion
There's a few ways to address your issue.
Also you can get improved NuGet restore/install performance by specifying a source when you have multiple sources configured on your machine, but the current project only uses official ones as it then skips looking thru all configured feeds and goes streight to the source.
But if your feed has authentication then you will need to add credentials for those using
nuget.exe
or NuGetAddSource alias.Tip for those using MyGet, it has pre-authenticated url:s you could use without adding a source, but just specifying the Source property for Restore/Install, this is sensitive information so don't store them in your build scripts but rather as i.e. environment variables.