How to Publish and Install DotNet SDK with NuGet
A package manager, based on a central installation database, is a tool that automatically installs, updates and removes distributions of software. With a package manager, users do not need to manually download an application installer. There are many package managers working for different programming languages and platforms, such as Maven, npm, pip, apt-get, Yum, Homebrew and so on. In this post, let’s take a glimpse of how to publish and install packages with NuGet.
What is NuGet
NuGet is the package manager for the Microsoft development platform. Users could use NuGet via command line tool, Visual Studio or NuGet Package Explorer.
Download
- Windows x86 Commandline
- Visual Studio 2013
- Visual Studio 2015
- Visual Studio 2015 Preview
- NuGet Package Explorer
You can also install NuGet Package Manager in Visual Studio. Select the Tools > Extensions and Updates menu option, and then search for NuGet:
Once the extension is installed, you can find it from the Tools > NuGet Package Manager menu option:
How to Publish a Package
Before creating a package, we need to know how to layout the directory structure:
- tools – the folder is for PowerShell scripts and programs that accessible from the Package Manager Console.
- lib – the folder is for .dll files which are added as assembly references when the package is installed.
- content - files in the folder are copied to the root of your application when the package is installed.
- build – the folder is for MSBuild targets files that are automatically inserted into the .csproj file of the application.
Let’s create a package for Dynamic .NET TWAIN with NuGet Package Explorer. You can either use command line tool or GUI tool according to your preference.
Select the File > New menu option to create a new package. Edit the package metadata:
Select the Content > Add > Lib Folder menu option to create the lib folder. Right-click on the lib folder and select Add .NET folder:
Add existing .dll files to the corresponding folders:
Click File > Save As to generate the package Dynamsoft.DotNet.TWAIN.6.1.1.nupkg. You can use a file archiver to view the structure of .nupkg file:
To publish the package, you need to register https://www.nuget.org for an account.
Find your API key:
You can now publish your package via online submission:
Or via NuGet Package Explorer:
If you prefer using the command line to update and remove packages, please read the article: Managing Packages Using the Package Manager Console.
How to Install a Package
Create a new WPF or WinForm project. Select Tools > NuGet Package Manager to choose Manage NuGet Packages for Solution or Package Manager Console.
Install a package via GUI:
Install a package via command line:
After installing the package, the references of Dynamic .NET TWAIN have been added automatically:
The snippet of testing code:
using Dynamsoft.DotNet.TWAIN;
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
DynamicDotNetTwain t = new DynamicDotNetTwain();
}
}
}