Look At NuGet Packages In VS 2017 - Part Two

In a previous article, we created a nuGet package targeting .NET Standard in VS 2017 and NuGet 4.0. Here, we will look into a few more nuGet features supported in VS 2017. We can add local or remote path as nuGet package source, apart from the default one [nuget.org] by going to Tools -> Options -> “NuGet Package Manager” -> “Package Sources” -> Click on "Add", as shown below.

VS 2017

Instead of clearing nuGet cache using the below command, we can clear it from Visual Studio.

VS 2017
 
Fot that, go to General tab -> “Clear All NuGet Cache”.

VS 2017

Also, we can use the same options window to enable downloading of missing NuGet packages during the build automatically.

In VS 2017, we don’t have built-in support for generating NuGet packages for applications targeting .NET Framework instead of .NET Core\Standard. In those cases, we can use post build event to create a package by calling nuget.exe.

Let’s create a sample class library targeting .NET Framework with the name as NugetFrameworkDemo with below post-build commands.

VS 2017

Here, nuspec file contains metadata like id, version, dependencies and we can generate a sample one for a project with required tokens by running the below command.

VS 2017

Output

VS 2017

We can add required details and external references to nuspec file.

VS 2017

Nuget.config is an XML file that controls settings of NuGet like repository path, dependencies, and package sources with user name, password etc. In VS 2017, machine-wide NuGet.Config is located at C:\ProgramFiles(x86)\NuGet\Config\.

VS 2017

Once a package is created, the same can be published to NuGet (or) JFrog for making it available to others by following the below steps.

  • Go to Nuget.org and register with NuGet\Microsoft account.
  • Click on “Upload Package” and select your package.

    VS 2017

  • Verify the details and click on Submit.

    VS 2017

Once the package is scanned for viruses and indexed, it will be available in search results and for installation (or) restore.

We can even use nuGet push command for publishing the package, which needs API key available under your user account on nuget.org.

VS 2017

VS 2017

I am ending things here. I hope this is informative.