Developer Blog

19/09/2024 by Troy Via

Kvaser NuGet Packages and Visual Studio

A new feature of our .NET wrapper makes porting applications between operating systems much easier. By linking to the repository in Visual Studio, NuGet automatically grabs the right version of the libraries when you create a new project. This is a real quality of life improvement and can be taken advantage of by anyone using VB .NET or C#. This guide walks through the process of setting this up in Visual Studio.

Starting in version 5.45.724 of the CANlib SDK installation package, the .NET wrappers were updated for easier use. These improvements include:

  • Architecture dependencies have been removed. All wrapper assemblies are built for Any CPU
  • All wrappers have been redesigned to support .NET Standard 2.0 and .NET 6.0
  • The .Net Standard 2.0 wrappers are for Windows only when developing for .NET Framework 4.6.1 and higher, .NET Core 2.0 and higher and .NET 5.0 and higher.
  • The .NET 6.0 wrappers are for both Windows and Linux when developing for .NET 6.0 and higher. These are preferred for new development.
  • NuGet packages have been added for all wrappers. The NuGet packages contain the assemblies for both .NET Standard 2.0 and .NET 6.0. The NuGet package automatically selects the correct assembly based on your project settings.

This article will focus on how to use the last improvement by explaining how to install the Kvaser NuGet packages into Visual Studio and how to add the Kvaser NuGet packages to your project.

I will be using Visual Studio 2022 to demonstrate.

Adding the Kvaser NuGet Packages to Visual Studio 

Launch Visual Studio 2022 and choose Continue without code.

In the menu, select Tools -> NuGet Package Manager Settings.

In the Options dialog, select Package Sources under NuGet Package Manager.

If you get a solid white pane instead of settings like the screen shown below, select General and then select Package Sources again.

When the settings are shown correctly, click on the green plus symbol to add a package.

Then enter an appropriate name like Kvaser Packages and use the ‘…’ button to browse to the CANlib SDK dotnet file installation directory: C:\Program Files (x86)\Kvaser\CANlib\dotnet\.

Then press the Select button to choose the directory.

Press the Update button to load the Kvaser package information into the Package sources.

Press the OK button to save your changes and exit the dialog.

The Kvaser packages have now been added to Visual Studio’s NuGet Package Manager allowing the packages to be added to your projects.

Adding Kvaser NuGet Packages to Your Project

For demonstration purposes I will create a new Visual Basic console application.  I could have chosen a C#, C++, or F# console application.  These same steps work with Windows Form, WPF, Class Library, and DLL applications.

To create a new project, select File -> New -> Project… in the menu.

I have my project templates filtered to only Visual Basic templates.  Click on the VB Console App in the list of project templates and then click the Next button.

Set the Project name, Location, and Solution name as desired then click the Next button.

Choose your desired Framework version from the drop-down list.  For this example, .  Then click the Create button.

Right click on the project in the Solution Explorer and select Manage NuGet Packages… from the popup menu.

Click on the Package source drop down and select Kvaser Packages.

Click on the Browse button to see what Kvaser packages you can install.

Select a package you want to use, and the right pane will fill with information about the package.

Click the Install button to add the package to the project.

You will get a warning that Visual Studio is about to make changes to the solution.  Just click the Apply button.

The NuGet Packet Manager now indicates the package is installed.  Installed packages are also listed as a dependency in the Solution Explorer.

Repeat these steps (selecting a package and pressing Install) for each Kvaser package you need in your project.  Then close the NuGet Packet Manager.

You can now add lines to your code that use the Kvaser Packages installed.

And you should not get any build or runtime errors unless you forgot to install the Kvaser drivers.

We hope this makes integrating our library into your software easier.  If you have any questions or suggestions, please contact Kvaser support at support@kvaser.com.

Author Image

Troy Via

Troy Via is a software and support engineer at Kvaser Inc. Troy has authored several training videos for Kvaser and is a key member of the product development team. He also participates in NMEA discussions on behalf of Kvaser. When he’s not working, he’s an avid gamer.