This guide will walk you through creating a simple C# application that gets the current version of the SmartPackager on your Linux desktop environment. Once this is working and verifies that your environment and project are set up correctly, the guide will walk you through the steps to create a protected package .yip file.
First, you will need to install dotnet 8.0 SDK on your desktop.
Under a Debian-based Linux desktop (such as Ubuntu 22.04 or later), install the .NET 8 SDK and GLib:
sudo apt update
sudo apt install dotnet-sdk-8.0 libglib2.0-0
A later .NET SDK also works.
Verify the version, output should be 8.0.x
dotnet --version
For other distributions, check your distribution's documentation
If you prefer, many Integrated Development Environments (IDE) support dotnet 8.0 SDK. This guide will utilize only the Linux command-line, rather than any IDE, for simplicity.
Next, you will need to obtain the Dotnet PackageAPI SDK file PackageAPI.1.0.0.nupkg.
Create directory for local packages Ex. ~/LocalPackages
mkdir -p ~/LocalPackages
Copy PackageAPI.nupkg to local packages
cp PackageAPI.<version>.nupkg ~/LocalPackages
Create dotnet project ex. TestPackageAPI
mkdir TestPackageAPI
cd TestPackageAPI
dotnet new console -n TestPackageAPI
cd TestPackageAPI
Add LocalPackages to your project
dotnet nuget add source ~/LocalPackages --name LocalPackages
Verify LocalPackages was added, LocalPackages should be listed
dotnet nuget list source
Add PackageAPI package to your project
dotnet add package PackageAPI --source ~/LocalPackages
Verify package was added, PackageAPI should be listed
dotnet list package
There will be a Program.cs file in the current directory. Replace the contents of Program.cs with the following source code:
Program.cs
using PackageAPI;
class Program
{
static void Main(string[] args)
{
try
{
var api = new PackageAPI.PackageAPI();
string version = api.getVersion();
Console.WriteLine(version);
}
catch (Exception ex)
{
Console.WriteLine("Exception occurred:");
Console.WriteLine(ex);
}
}
}
Program.cs contains a standard static main entry point.
When the program is run, it instantiates an instance of the PackageAPI class and assigns it to the variable api. Calling the class method getVersion() returns the version of SmartPackager whose package code the SDK contains. This isn't the version of the PackageAPI SDK; getSdkVersion() returns that.
If using the command-line, you can issue: (or place this in a simple build.sh script, for example)
dotnet build -c <Debug|Release>
The -c option lets you set the build configuration. By default, dotnet projects build in the Debug configuration unless you override it. It compiles with debugging symbols, and without optimization. Building with dotnet build -c Release compiles optimized code, suitable for deployment.
Once built, we can run our application using:
dotnet run
This will print a string containing the version of the SmartPackager if your project and the PackageAPI SDK were configured correctly.
Creating protected .yip packages requires a private key and a package JSON template file. Once created, only the holder of that private key (or Yaskawa) can change the package or read its contents with getJson. Its name, version, vendor and type can be read without the key. Anyone with the package file can install it, so don't put secrets in it.
To create a private key, edit the Program.cs in the project created in the "Sample Dotnet Project" section. Replace the Program.cs code with this:
Program.cs
using PackageAPI;
class Program
{
static void Main(string[] args)
{
try
{
var api = new PackageAPI.PackageAPI();
var privateKeyFilePath = "private.key";
bool newKeyResult = api.generateVendorKey(privateKeyFilePath);
if (newKeyResult) {
Console.WriteLine("Key successfully created.");
}
else {
Console.WriteLine("Failed to create key.");
}
}
catch (Exception ex)
{
Console.WriteLine("Exception occurred:");
Console.WriteLine(ex);
}
}
}
Build and run the project
dotnet build -c <Debug|Release>
dotnet run
The output should be:
Key successfully created.
The private key will be written to the file "private.key". If an exception occurs, it will be caught and the cause will be written to output.
In order to create a package, you must use a .json file that describes the package. The documentation for the package json format is here: Install Package Json Format
Once you have created your private key file and package template .json file, you can create a protected package .yip file.
Create a new dotnet project or edit the Program.cs from the project created in "Sample Dotnet Project". Replace the Program.cs code with the following.
The following code assumes:
Program.cs
using PackageAPI;
class Program
{
static void Main(string[] args)
{
try
{
var api = new PackageAPI.PackageAPI();
string pkgFilePath = "protected_pkg.yip";
string pkgTemplateJsonFilePath = "pkg_template.json";
string privateKeyFilePath = "private.key";
string archiveDirPath = "ArchiveDir";
string pkgVariables = "";
var createPkgResult = api.createProtectedPackage(pkgFilePath,
pkgTemplateJsonFilePath,
archiveDirPath,
privateKeyFilePath,
pkgVariables);
if (createPkgResult) {
Console.WriteLine("Protected package successfully created.");
}
else {
Console.WriteLine("Failed to create protected package: " + api.getLastError());
}
}
catch (Exception ex)
{
Console.WriteLine("Exception occurred:");
Console.WriteLine(ex);
}
}
}
dotnet build -c <Debug|Release>
dotnet run
If successful, the output will be:
Protected package successfully created.
If an exception occurs, it will be caught and the cause will be written to output.
All of the method definitions for the Dotnet PackageAPI SDK are located at the Dotnet PackageAPI SDK Reference