LazyMagic

Nuget

In this step we will configure Microsoft's Nuget package manager.

Nuget provides a comprehensive and reliable solution for sharing build artifacts, like libraries, with other team members. Using packages has many advantages and is highly recommended.

Nuget is used by dotnet to resolve packages for use in your projects. Packages are resolved (retrieved) from one or more sources. The default nuget package sources, for a machine with Visual Studio IDE installed, include:

  • C:\Users\username\AppData\Roaming\NuGet\NuGet.Config
  • C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.FallbackLocation.config
  • C:\Program Files (x86)\Nuget\Config\Microsoft.VisualStudio.Offline.config

These files define source locations of NuGet packages. They are listed in order from highest to lowest priority. See How Nuget Settings are Applied for Microsoft's detailed description of how nuget settings are applied.

Earlier, we added Users\username\Nuget.Config to your workstation, now we will add \Users\username\source\repos\_Dev\MagicPets\Nuget.Config, so the list looks like this:

  • C:\Users\username\source\repos\_Dev\MagicPets\Nuget.Config
  • C:\Users\username\Nuget.Config
  • C:\Users\username\AppData\Roaming\NuGet\NuGet.Config
  • C:\Program Files (x86)\NuGet\Config\Microsoft.VisualStudio.FallbackLocation.config
  • C:\Program Files (x86)\Nuget\Config\Microsoft.VisualStudio.Offline.config

These files are listed in order from highest to lowest priority with configurations having higher priority overriding configurations with lower priority.

_Dev\MagicPets\Nuget.Config

We use a Nuget.Config file in the _Dev\MagicPets folder to allow each MagicPets solution to reference locally produced nuget packages.

This file is not tracked by git and needs to be created manually. So create a Nuget.Config file in the _Dev\MagicPets folder with the content below.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <packageSources>
        <add key="MagicPets" value="./Service/Packages" />
    </packageSources>
</configuration>
How it works:

When you build the MagicPetsService, client C# SDK libraries are generated, packaged, and placed in the solution's Packages folder. These packaged libraries are used by C# clients, like the StoreApp, to make calls to the service.

By using local packages, your local StoreApp solution can access the packages without restoring the packages from a remote registry like Nuget.org or a registry hosted on GitHub. This approach will reduce the number of interim package versions inherit in the use of a registry.

For the development environment, you may modify and deploy system changes even if you have only cloned the LazyMagicPets repositories.

Test and Prod

Use of local packages is only recommended for Development environments. Test and Production environments should restore packages from either a GitHub registry or Nuget.org. For most proprietary systems, application specific packages are often shared in private GitHub Nuget registries.