Sometimes there is no Nuget packages for the assemblies and other resources you use in your applications. Fortunately, it is very easy to create your own package and publish it locally. This post will briefly describe the steps how to get started.
If you haven’t already downloaded Nuget-cli head over to https://www.nuget.org/downloads and download the latest version. Do this even if you have Visual Studio installed. Copy the nuget.exe to a convenient folder where you work with your packages. In our case at Dunite we use our local TFS-server.
Next step is to create the .nuspec file which will be used as the manifest for the nuget package. Run the following command from the folder where you copied your nuget.exe.
This creates W3D3NoseProxy.nuspec file which we now edit to its perfection. Name your package to anything you like. Start your favorite xml editor, in my case VSCode. Below I have removed the unnecessary lines and added the packageTypes section since that is recommended. In this case the package is a Dependency package since we add assemblies. You can read more about types here: https://docs.microsoft.com/en-us/nuget/create-packages/creating-a-package#setting-a-package-type
The nuget package is built with convention so all we have to do is to place files in specific directories. In our case we create a lib folder to store our assembly. You can/should create specific folders for different targets of the framework, but in the picture below I just placed the assembly directly in the bin folder. That will give me a warning during packaging of the package that I choose to ignore.
Now that our package is complete it is time to build our nuget package with the command below.
The output will be the nuget package that we want to place in our nuget repository. In my case I have shared the folder to our developer team with simple Windows file sharing.
Now that the package is created and stored in a file share so that the developer team can reach it, we head over to Visual Studio and add the package source folder in the menu Tools-Nuget package manager->Package manager settings. Click on add package source, the green plus button and enter the information for your share. Remember to hit the Update button.
With all that it is now time to add our new package to the project. Go to the Manage Nuget Packages dialog and make sure you change the ”Package source” to Dunite Package source, our what you choose to call your source. Then you can browse your own package repository.