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

Setup a private Nuget server, host your own Nuget feed

Before I start talking about how to create a private Nuget server, I need to show you how do you create a Nuget package by yourself.

To create a Nuget package, you can either use Nuget.exe command line tool to do it, or use Nuget Package Explorer. Nuget Package Explorer provides the nice neat interface to allow you create a nuget package without any knowledge of command-lines syntax. To download them both, from

http://nuget.codeplex.com/releases/view/58939 (Nuget.exe)

http://nuget.codeplex.com/releases/view/59864 (Nuget Package Explorer)

After you have created your own packages, you can now setup the private Nuget feed.

1. Create a web application in Visual Studio. I am using MVC as my Nuget server application.

2. Install “NuGet.Server” package from “Package Manager Console”.

3. Configure the package folders and ApiKey

  <appSettings>
    <add key="webpages:Version" value="1.0.0.0" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <add key="apiKey" value="1234" />
    <add key="packagesPath" value="C:\MyLocalNugetFeed" />
  </appSettings>

4. Deploy your application to IIS. And you server is running.

To view the feed and download packages.

Right click “Reference” folder of your project, Click “Manage Nuget Packages”.

image

Then add “http://youdomain.com/nuget” as your feed address.

Adding new feed to package sources

You will be able to see your feeds in the list.

To publish a package

You can use Nuget Package Explorer or Nuget.exe.

Nuget.exe

image

Nuget Package Explorer, enter your publish Url and ApiKey then click Publish.

image

What are you waiting for to get your own Nuget feed and share code snippets or libraries with your mates!!

Here are some reference links may help you.

http://docs.nuget.org/docs/creating-packages/hosting-your-own-nuget-feeds

http://docs.nuget.org/docs/reference/command-line-reference

Nuget commands to find packages and install them

I have been using Nuget in Visual Studio 2010, it is a time saver and make my life a lot easier.

To use Nuget, open visual studio 2010 => Tools => Library Package Manager => Package Manager Console.

So in the console, you can type your nuget shell commands to list available packages and install them to particular project.

To list packages,


PM> get-package –listavailable Elmah

You will get a list of available packages,

image

To install a package, (such as Elmah.MVC)

PM> install-package Elmah.MVC 

Nuget will install Elmah and its all dependencies. It also setup the settings in web.config

Isn’t that awesome!

For a full reference of Nuget shell commands, check out this link

http://docs.nuget.org/docs/reference/package-manager-console-powershell-reference