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.
Instead of clearing nuGet cache using the below command, we can clear it from Visual Studio.
Fot that, go to General tab -> “Clear All NuGet Cache”.
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.
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.
Output
We can add required details and external references to nuspec file.
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\.
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.
- Verify the details and click on Submit.
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.
I am ending things here. I hope this is informative.