Repository Management with Nexus
24.6. .NET Integration

24.6. .NET Integration

24.6.1. Consume .NET Components From NuGet Gallery

The NuGet project provides a package and dependency management solution for .NET developers. It is integrated directly into Visual Studio and makes it easy to add, remove and update libraries and tools in Visual Studio and on the command line for projects that use the .NET Framework. Nexus can act as a proxy between your developer’s Visual Studio instances and the public NuGet Gallery.

When you configure Nexus Professional to act as a proxy for NuGet Gallery you gain a more reliable build that depends on locally cached copies of the components you depend on. If NuGet Gallery has availability problems, your developers can continue to be productive. Caching components locally will also result in a faster response for developers downloading .NET dependencies.

In this example, you will…

  • Configure your Visual Studio instance to download NuGet packages from your local Nexus server
  • Consume components from NuGet Gallery via Nexus

Let’s get started

Your Nexus Professional Trial instance has been preconfigured with the following NuGet repositories:

  • A Proxy Repository for NuGet Gallery
  • A Hosted Repository for your internal .NET components
  • A Group which combines both the NuGet Gallery Proxy and the Hosted NuGet Repository
figs/web/eval-nuget.png

Figure 24.8. NuGet Repositories In Repository List


To consume .NET components from Nexus Professional you will need to install the NuGet feature in Visual Studio as referenced in Section 24.1.6, “Microsoft Visual Studio And NuGet” and configure it appropriately:

  1. Open Nexus Professional, click on Repositories in the left-hand navigation menu and locate the NuGet Group repository group. This is the aggregating group from which Visual Studio should download packages. Click on this repository group in the list of repositories.
  2. Select the NuGet tab below the list of repositories with the NuGet Group selected and copy the URL in the Package Source field to your clipboard. The value should be http://localhost:8081/nexus/service/local/nuget/nuget-group/
  3. Now in Visual Studio, right-click on a Visual Studio project and select Add Library Reference
  4. In the Add Library Package Reference click on the Settings button in the lower left-hand corner.
  5. This will bring up an Options button. Remove the initial NuGet repository location and replace it with a reference to your Nexus instance. Clicking Add to add the reference to your Nexus Instance.
  6. Click on OK to return to the Add Library Package Reference dialog.
  7. Select the Online item in the left-hand side of the dialog, at this point Visual Studio will interrogate your Nexus instance for a list of NuGet packages.
  8. You can now locate the package you need and install it.
  9. To verify that the NuGet package components are being served from Nexus you can return to the Nexus web interface and browse the local storage of your NuGet proxy repository.

Note

Watch this video of the steps being performed in Visual Studio.

The above instructions were created using Visual Studio 10 Web Developer Express. Your configuration steps may vary if you are using a different version of Visual Studio.

24.6.2. Publish And Share .NET Components With NuGet

Nexus Professional can improve collaboration and control while speeding .NET development. NuGet defines a packaging standard that organizations can use to share code.

If your organization needs to share .NET components you can publish these components to a hosted NuGet repository on Nexus Professional. This makes it easy for projects within your organization to start publishing and consuming NuGet packages using Nexus as a central hub for collaboration.

Once NuGet packages are published to your Nexus Professional instance they are automatically be added to the NuGet repository group and your internal packages will be as easy to consume as packages from NuGet Gallery.

In this example, you will…

  • Publish NuGet packages to a Hosted NuGet repository
  • Distribute custom .NET components using Nexus Professional

Let’s get started:

  1. Follow the example from Section 24.6, “.NET Integration” to set up proxying of NuGet packages from Nexus
  2. Activate the NuGet API Security Realm → Read more…
  3. Create a NuGet Package in Visual Studio → Read more…
  4. Publish a NuGet Package to Nexus Professional → Read more…