NuGet Package Guide
Introduction
NuGet is the package manager for .NET. NuGet packages are essentially zip files containing reusable code, libraries, and metadata. Packages can be distributed privately or publicly via NuGet repositories. For more information, visit nuget.org.
The SplashKit NuGet package has two primary purposes:
- Provides C# bindings for SplashKit, translated from C++ using SplashKit Translator. The bindings allow users to create SplashKit projects with C#.
- Provides SplashKit native libraries for Windows (x64) and macOS. These libraries allow Windows and Mac users to create and run SplashKit projects in C# without installing the libraries separately via SplashKit Manager (SKM).
Building the Package
-
Download the SplashKit native libraries
Download the latest stable libraries from SKM. Libraries should be placed in
/tools/scripts/nuget-pkg/Libraries/win64and/tools/scripts/nuget-pkg/Libraries/macosrespectively. This step can be automated via the use of the bash script found at/tools/scripts/nuget-pkg/download-libraries.sh. -
Open the NuGet package directory
Navigate to
/tools/scripts/nuget-pkg. This directory contains configuration settings for the package, along with the associated icon and description. -
Build the package
Run one of the below commands, ensuring to replace YOUR_VERSION with the relevant version number (e.g. 1.3.0):
For debug
Terminal window dotnet build --configuration Debug -p:version=YOUR_VERSION-debugFor release
Terminal window dotnet build --configuration Release -p:version=YOUR_VERSIONThis will build the package and output to
tools/scripts/nuget-pkg/bin/as detailed in Exploring the Output. -
Check the output directories
Ensure both
ReleaseandDebugdirectories exist intools/scripts/nuget-pkg/bin/. If either is missing, create the empty directory as needed. This is to ensure the test programs run without errors.
Exploring the Output
In the tools/scripts/nuget-pkg/bin/ directory, there will be a directory corresponding to the
built package - either Debug or Release. This directory contains the NuGet package itself
(SplashKit.X.X.X.nupkg), along with separate directories for each targeted .NET version. These
directories are for referencing/testing, and can be ignored - the package itself does not depend
upon them.
Testing
A suite of test programs is provided in the form of a C# solution, with a separate project/directory for each test.
Directorytools
Directoryscripts
Directorytest
DirectoryMain/
- …
- Directory.Build.props
- Directory.Packages.props
- GlobalSettings.cs
- NuGet.config
- NuGetTests.sln
The provided tests are translations of the SplashKit core integration tests. The tests can be run
individually from their respective folders, but are best launched using the test runner located in
the Main directory.
Running the Provided Tests
-
Check local package sources
NuGet.configsets the local NuGet package sources. If one of these directories does not exist, either create it, or comment out the corresponding entry inNuGet.config. -
Set target package version
Directory.Packages.propsspecifies the target NuGet package version. Update this file to match the version being tested. -
Check target .NET versions
Directory.Build.propsspecifies .NET versions for multi-targeting. These should match the .NET versions being targeted by the package build. -
Run the test runner
Open the
Maindirectory. Run the following command, replacing TARGET_FRAMEWORK with the framework to be tested, e.g. For .NET 9, usedotnet run -f net9.0.Terminal window dotnet run -f <TARGET_FRAMEWORK> -
Select test
Input a number to build and run the corresponding test.
-
Re-run as necessary
To ensure the package is fully functional, the tests should be re-run to cover each combination of framework and architecture. Every test should produce the expected output.
Updating or Adding Tests
As noted in Running the Provided Tests, the NuGetTests solution
specifies the NuGet version and target frameworks in Directory.Packages.props and
Directory.Build.props respectively. These should be updated at a solution level, rather than
separate configurations for each test project. This ensures ease of use and reduces room for error.
Adding New Tests to the Solution
-
Create a new directory in
/tools/scripts/test, for example:Terminal window mkdir MyTest -
Inside the new directory, create a new project with
Terminal window dotnet new console -
Edit the project’s
.csprojfile to remove any<TargetFramework>tags, since this would override the solution’s multi-targeting. -
Write your new test in
Program.cs -
If loading resources (e.g. images, fonts, etc.) use the following line to utilise existing resources from the main SplashKit test suite.
SetResourcesPath(GlobalSettings.ResourcePath);
Updating Existing Tests
Existing tests can be updated by editing Program.cs in the corresponding project’s directory.
Since the test runner (Main) builds each project before running, there is no need to rebuild the
runner upon updating a test. The runner is designed to be left running during updates, to speed up
development.
If loading resources (e.g. images, fonts, etc.) use the following line to utilise existing resources from the main SplashKit test suite:
SetResourcesPath(GlobalSettings.ResourcePath);Creating Tests Outside of the Provided Solution
Normally, an end user would use dotnet add package splashkit to reference the SplashKit package.
However, this will default to the latest stable SplashKit version, skipping the locally built one.
Instead, do the following:
-
Create a new project using
Terminal window dotnet new console -
Create a
NuGet.configfile in the project (or solution) directory, specifying the path to the target package. An example can be found in/tools/scripts/test. -
Add the following to the
.csproj, replacing TARGET_VERSION with the targeted NuGet package version:<ItemGroup><PackageReference Include="splashkit" Version="<TARGET_VERSION>" /></ItemGroup> -
Add
using static SplashKitSDK.SplashKit;toProgram.cs