Create your private team NuGet and manage your source code

Intro.

The major purpose from this post is to give simple and clear hands on how to create your first Nuget repository and publish Nugets to it to use in other projects, and indeed hands on how to build your project as a Nuget package.

As one of the products i am working on now, the arch. is a MicroService oriented which is perfect for the Product, but when we think more behind the scene , how can we organize the whole solution artifacts and components separately with respect to the fact to still have some common services to handle such a generic or shared logic.

Here i found to build our own solution NuGet repository is a suitable idea to handle the whole things instead of us.

How To start

  1. Define the common services, (e.g. ImageProcessing Service), Encryption Service, System Models or MicroService Models (usually these models is shared between the MicroServices).
  2. Define the Naming convention you will use later for (Nuget Name, Description, Author).

How to create a Nget packege for the progect ?

  1. Assuming you have a separate project performing a functionality to use later in various projects (e.g. ImageCompression Service).
  2. There are many ways to package your project as a Nuget, but in this case i will use an easy and stable way to  “Create a Nuget Package With Every Successful Build”.

Steps …

  1. In project (e.g. ImageCompression), install Nuget package from nuget.org with Id (CreateNewNuGetPackageFromProjectAfterEachBuild), you can do it by the Visual Studio Nuget Manager or directly from the Tools > Nuget Package Manager > Package Manager Console.
  2. Installing this Nuget will add a (_CreateNewNuGetPackage) folder in the project, (Config.ps1) is the file where you can customise to change the way the Nuget qill be created.
  3. If you build your project now, a .nupkg file will be created with AssemplyName and extra info about the build (e.g. Debug or Release, X86 or AllCPU or whatever …), read the coming points to figure out how to change the Nuget Info. and Name.
  4. And to control the Nuget Information (Name, Description, Author, Version), follow these points.
  5. Open the project (AssemblyInfo.cs) file inside (Properties), Setting the [AssemblyDescription] will set the Nuger Description,  Setting the [AssemblyCompany] will set the Nuget Author.
  6. Open (Config.ps1), find [$versionNumber = “”] at line 19, set the version number or keep it empty and it will use the default build version, find [$appendConfigurationAndPlatformToNuGetPackageFileName = $true] at line 50, keep it true and the Nuget name will contains the Platform and Configuration info (e.g. Comp.ImageCompression.1.0.0.0.Debug.AnyCPU.nupkg) or set to false and it will be shorter like (e.g. Comp.ImageCompression.1.0.0.0.nupkg)
  7. Now you have the  Nuget (.nupkg) and you are ready to publish.

 

Publish your Nuget

We are here talking about your private repository starting from (Local machine repository to cloud hosted repository).

Local Machine Repository

  1. Create a Directory at your local machine (e.g. c:\\MyNugetRepo) and push your .nupkg file(s) to it.
  2. from Visual Studio, open Tools > Nuget Package Manager > Package Manager Settings
  3. open from left menu, Nuget Package Manager > Package Source
  4. Click on the green (+) Btn. to add new source
  5. Write the source Name and Source to (c:\\MyNugetRepo)
  6. Click ok and now you have a new custom private local machine Nuget Source.

 

Site (Shared Repository)

I mean a shared Site (URL), either network on company IIS server or to cloud site to access from outside the network,. its all depends on your need.

  1. Create a new project of type (ASP.net Empty Web Application)
  2. Install the Nuget Package (Nuget.Server) by .net foundation  on this Application, this will re structure the whole app to be a Nuget Feed App.
  3. a (Packages) folder now created and ready to contain all your .nupkg(s)
  4. Publish the App to (IIS) or (Cloud based site) (e.g. AZURE app service)
  5. When publish done, open the site and the default page should be ibstructions for the Nuget(s) repository URL and also how to push new .nupkg, for me, you can push new Nuget package to this Repository by simply add the .nupkg to the (Packages) folder and re publish again.
  6. be noted that you will need to use the URL (e.g. http:// mysiterepo:2255/nuget) as the Repository Source.
  7. also note that ot might take few minutes until the package displayed in the list of available packages after installation.

 

More Info …

The (CreateNewNuGetPackageFromProjectAfterEachBuild) handles the dependencies from the installed packages, so ant project installed packages will be added to the project package dependencies.

Advertisements