Setup a private nuget server

Deploy nuget server project

Nuget Server package on nuget.org:
https://www.nuget.org/packages/NuGet.Server/2.11.3/

The project source:
https://github.com/NuGet/NuGet.Server

deploy the project to IIS, and configure the web.config

1. set the apiKey for pushing packages to the server
2. set packagesPath to store all the packages, the default will be ~/Packages (you need to give write permissions for the app pool user)

Pushing packages

1. using nuget CLI

https://docs.microsoft.com/en-us/nuget/tools/nuget-exe-cli-reference

nuget.exe push -Source {NuGet package source URL} -ApiKey key {your_package}.nupkg

2. using dotnet core CLI

https://docs.microsoft.com/en-us/dotnet/articles/core/tools/dotnet-nuget-push


dotnet pack --configuration release
dotnet nuget push foo.nupkg -k 4003d786-cc37-4004-bfdf-c4f3e8ef9b3a -s http://customsource/

Enable authentication for accessing nuget server

1. enable windows authentication on the server site on IIS
2. create a windows user
3. adding the repository source with username and password (using nuget CLI), it will be saved into the global nuget.config file. (normally in Nuget has a global nuget.config, saved in \Users\%AppUSer%\AppData\Roaming\NuGet)
nuget.exe sources add -name {feed name} -source {feed URL} -username {username} -password {PAT} -StorePasswordInClearText

If you don’t have the username & password, it will return a 401 unauthorized error. In visual studio, it will prompt a dialog asking for credentials.

Restore nuget packages using nuget config per solution

If you work on a new machine, and checkout source code of a project, you will need to configure the nuget source, username, password etc. To enable developers restore the packages and build the project without any hassles, we can create a nuget.config per solution.


<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSourceCredentials>
<AWS_x0020_Nuget>
<add key="Username" value="spnugetuser" />
<add key="ClearTextPassword" value="SearchParty2017" />
</AWS_x0020_Nuget>
</packageSourceCredentials>
<packageSources>
<add key="AWS Nuget" value="http://nuget.searchparty.com/nuget" />
</packageSources>

</configuration>

Then you can call

nuget restore

or

dotnet restore

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s