It is a common problem when a team in an organization creates a component which can be leveraged by multiple teams, but does not keep it in a common shareable repository to which everyone has access.
Most of the teams depend on checking in the common component in to a shared source control to which other teams get a reference to use it. This process of adding a reference has several challenges:
- Version control of the component
- Accidently deleting the component
- Authorization ( Permissions) at the source control
In this blog, I will illustrate the creation and use of a local NuGet repository that would facilitate the leverage of common components.
Creating a package:
- Get the NuGet command line (http://nuget.codeplex.com/releases/view/58939 )
- Open Command prompt and navigate to directory path where NuGet command line has been installed.
- Run “nuget spec”. This will create a “Package.nuspec” file. This is the base file which holds the schema to create a NuGet package.
- Navigate to the directory where Package.nuspec has been created and create a folder “Content”. Use the “Content” folder to drop the required libraries to be referenced.
- Open Package.nuspec in a notepad and edit it.
- Save the file and close it.
- Open command prompt and run “nuget pack”. On success, a .nupkg file will be created.
- Copy the *.nupkg file and place it in a shared folder.
Adding the package source:
- Open Visual Studio and navigate to Tools > Library Package Manager > Package Manager Settings.
- Click on OK and a new Package source will be added.
Using the package:
- Right click on the project and select “Manage Nuget Packages”.
- Click on the package we created and the assemblies added in the “Content” folder of the package will be added as reference in your project.
Shared NuGet packages take advantage of all the functionalities offered by NuGet packages. These include version management, adding components locally, and modifying the configuration.