Create NuGet package
In this guide we want to focus on how you can create and publish our own NuGet Packages on an on-premises NuGet server.
Upload NuGet Package
Save your PLC as a .library, either with CI/CD or manually in the TwinCAT IDE, make sure to set the following properties for your library
- Company: Name of your company, in Twinpack we refer to this as 'distributor name'
- Title: Name of your library as it should be seen in the TwinCAT Library Repository.
- Version: Version number in the format x.y.z or x.y.z.w. Note that some NuGet Servers do not support 4-digit version numbers, in this case, please use a 3-digit version number
In the same folder as you saved the library file, create a .nuspec file with the following content (adapt to match your specific library). The filename should match the name of the library, i.e. for the library file
MyPlcLibrary.library, the nuspec file should be calledMyPlcLibrary.nuspec<?xml version="1.0" encoding="utf-8"?> <package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd"> <metadata> <id>MyPlcLibrary</id> <version>1.0.0.0</version> <title>MyPlcLibrary</title> <icon>logo.png</icon> <iconUrl>https://myhost.me/icon.png</icon> <authors>MyCompany</authors> <description>MyPlcLibrary is an awesome library to do ...</description> <copyright>MyCompany</copyright> <tags>library</tags> </metadata> <files> <file src="MyPlcLibrary.library" target="TC3.1" /> <file src="logo.png" target="" /> </files> </package>authorsmust match the company of your PLC library (as set in the TwinCAT properties)idandtitlemust match the title of your PLC library (as set in the TwinCAT properties)versionmust match the version of your PLC library (as set in the TwinCAT properties)- In tags you can put any additional tags, which you like, but the tag
librarymust be included - In files, the .library file must be set
iconis optional and can be used to provide an icon, which is shown in the Twinpack Catalog instead of an autogenerated icon. (usingiconis supported sinceTwinpack 1.2,)iconUrlis optional and can be used to provide an icon, which is shown in the Twinpack Catalog instead of an autogenerated icon. This property is ignored ificonis used.- Other properties in the .nuspec file are optional
Use nuget to package and push the NuGet package to your NuGet server, assuming
nuget.exeis in your path environment variable and you navigated to the folder containing your .library file, this can be done withnuget.exe pack nuget.exe push MyPlcLibrary.1.0.0.nupkg -Source https://your-nuget-server -ApiKey your-api-key
Use NuGet package
In order to use the NuGet package you just uploaded to your server
- Open Twinpack in the TwinCAT IDE
- On the right, top corner click on
Configureto add your NuGet Server as a repository for Twinpack - If your repository requires authentication, you have to login. Click on the
Loginbutton and enter your personalUsernameandPassword. If your Twinpack server only supports apikeys, leave theUsernameempty and put theApiKeyinto thePasswordfield. - The repository configuration is saved by clicking
Okon thePackage serversmodal. - You can now search and install the package(s) avaiable on your NuGet Server.