1

How to Set Up a NuGet Server on Windows (Complete Walkthrough)

 3 years ago
source link: https://hackernoon.com/how-to-set-up-a-nuget-server-on-windows-complete-walkthrough-f32734zq
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How to Set Up a NuGet Server on Windows (Complete Walkthrough)

@adamtheautomatorAdam Bertram

Adam is an online business professional, Microsoft MVP, blogger, trainer, and published author.

So you've developed code. Great! Now you have to publish it to your users. But how There are many ways to accomplish this but one of the most used is NuGet. NuGet is a technology that allows you to publish code in the form of packages for others. A NuGet server is a way to make it happen.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

NuGet has become popular mostly due to its widespread adoption as a package manager and its integration with Microsoft’s developer tools. The NuGet packaging system allows developers to bundle code into packages that you can then easily distribute for others to use.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

NuGet has two main components; a client and a server. A NuGet server hosts a repository which then contains packages for distribution. The NuGet client is a client-based component that is used to create local packages and upload them to server repositories. Various clients then download these packages over HTTP/HTTPS.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

NuGet.Server is the basis of all of the other NuGet products you'll be learning about here. It's important to first learn about NuGet.Server and how to set it up before diving into other alternatives.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

By setting up plain ol' NuGet.Server with IIS will give you a lot of background knowledge about how the other NuGet server products behave.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

Prerequisites

Before we get too far, you're going to need a few things to get NuGet.Server set up.

0 reactions
heart.png
light.png
thumbs-down.png
money.png
  • Visual Studio - 2017 or newer is preferred and the Community Edition will work. This can be installed on a workstation and does not need to be installed on the server.
  • ASP.NET and web development workload for Visual Studio.
  • Windows Server - Any currently supported version of Windows Server version will work, but all of the screenshots have been taken on Windows Server 2019 Standard.

Note that you do not need NuGet.Server itself upfront. You are not required to manually download this ahead of time because it will be installed using the NuGet package manager integrated into Visual Studio.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

Creating a Visual Studio Project

To get started creating a NuGet.Server, you'll need to first create a project in Visual Studio. To do so, create a new project in Visual Studio with the ASP.Web Application (Visual C#) template as shown below.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

You can name the app whatever you want except for NuGet.Server. If you name your app NuGet.Server, it will cause a name conflict with the package that you will download later causing headaches down the road.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

Creating an ASP.NET Web Application in Visual Studio

Next, select the empty template. This will create an empty web app, which you will use to install the NuGet.Server package into. To do this, right-click on the project in the Solution Explorer and select Manage NuGet Packages as shown below.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

On the window that opens, search for NuGet.Server and select the version you want to install. Once selected, Visual Studio will start to download and install the dependencies into the project.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

Once that is done, change the project from Debug to Release so that the final server does not include the debug logging.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

Setting the Visual Studio project to Release

Next, build the project by clicking on the Build tab and selecting Build Solution.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

Building NuGet.Server project

If you left the repo location as default, the application will be built at C:\Users\<username>\source\repos\<AppName>\<AppName>. The folder will look something like what is shown below. You will need this project folder to copy to your web server.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

If you're unsure of where your project folder is at, you can always see it in your properties for the project.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

Installing IIS

Next, install the Windows features NuGet.Server requires on the server. To install all the needed roles on your server, launch an administrative PowerShell session and run the Install-WindowsFeature cmdlet with all of the necessary features as shown below.

0 reactions
heart.png
light.png
thumbs-down.png
money.png
Install-WindowsFeature Web-Server,Web-Net-Ext45,Web-Asp-Net45,Web-ISAPI-Filter,Web-ISAPI-Ext -IncludeManagementTools
0 reactions
heart.png
light.png
thumbs-down.png
money.png

Once the IIS role and other features are installed, copy over the project folder (probably C:\Users\<username>\source\repos\<AppName>\<AppName>) to a directory on your web server. The default location for web apps is C:\inetpub\wwwroot. This is the directory I will be assuming your project is in.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

Prepping the Web Config

Next, you'll need to inspect the web.config file on the web server. This file will be in the root of the build folder you copied to your web server. Open the web.config file with your favorite text editor. You will see two similar lines that start look like the following:

0 reactions
heart.png
light.png
thumbs-down.png
money.png
<compilation debug="true" targetFramework="<version>" />
0 reactions
heart.png
light.png
thumbs-down.png
money.png

For example, see below.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

Remove one of the compilation lines and leave the one with the newer version.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

Note: If you fail to do this, you will receive an internal server error message when you launch your webpage.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

Configuring IIS

Now that you have the NuGet.Server files on your web server, open IIS manager, right-click on the default website and select New Application as shown below.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

Provide a name for the application. You can see an example of what you'll be looking at below.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

Adding an IIS application

Now if you navigate to your web server URL you should see something like below.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

Take note of the package URI on the page. In the above example, it is http://172.16.8.132/NuGet/nuget. You will need this for later.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

Changing the Packages Directory

By default, packages are stored in C:\inetpub\wwwroot\<AppName>\Packages. If you'd rather change that location, you can do so in the web.config file.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

You can also map the package folder to another path. This could be used when you have a small drive that you have the web server files on, but you have another drive that is larger for containing the packages. To change the package path change the packagesPath value in the web.config.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

Once you are done making your changes to the web.config file, restart the website to  load the new settings. To do this, from IIS Manager, right-click on the website and select Manage Website and then on Restart as shown below.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

Setting an API Key in web.config

Take a look at the web.config file snippet below. By default, the API key is blank. That's a problem.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

If you'd like to password protect your NuGet packages, you can add an API key here. When an API key is added, you will be required to use this every time you need to add or delete packages from the repository.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

Once the key is added to the value for apiKey save the file. You can instead change the value for requireApiKey to false to not need an API key to add or delete packages.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

Updating NuGet.Server

Now you have your NuGet.Server set up, what's next? NuGet.Server is a Nuget package manager and has frequent updates that you will want to take advantage of.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

To update a NuGet.Server, open your previous project. This is the same path where your project is built that you located earlier. Or if you open Visual Studio, it may be listed in your recent projects.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

Once it is opened right-click on the project in the Solution Explorer and select Manage NuGet Packages. From here you can see all the packages that have updates. Select NuGet.Server and click update as shown below.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

This will update NuGet.Server and all the dependencies that require updates. It's that easy!

0 reactions
heart.png
light.png
thumbs-down.png
money.png

Next Steps

At this point, you should now have a brand new NuGet.Server instance running on your machine. Congratulations on setting that up! But this step is just the beginning.

0 reactions
heart.png
light.png
thumbs-down.png
money.png

Continue your journey and check out all of the other NuGet articles I've written!

0 reactions
heart.png
light.png
thumbs-down.png
money.png

Also published on: https://adamtheautomator.com/custom-nuget-server-setup

0 reactions
heart.png
light.png
thumbs-down.png
money.png
0 reactions
heart.png
light.png
thumbs-down.png
money.png
6
heart.pngheart.pngheart.pngheart.png
light.pnglight.pnglight.pnglight.png
boat.pngboat.pngboat.pngboat.png
money.pngmoney.pngmoney.pngmoney.png
Share this story
Read my stories

Adam is an online business professional, Microsoft MVP, blogger, trainer, and published author.

Join Hacker Noon

Create your free account to unlock your custom reading experience.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK