Creating a C# function block library

With Visual Studio, you can program functions, function blocks, and function containers in C# which you can subsequently import using the PLCnext Technology engineering software, PLCnext Engineer and use on a PLCnext Technology device.


Before proceeding, make sure to have the workbench prepared properly.

  1. Create a new project
    • In Visual Studio, from the top menu bar, open File > New  > Project... 
    • In the dialog that opens, select Installed > Templates > Visual C# > PLCnext 
      Find it here:Click to show a screenshot 


    • Select the Firmware Library template for  from the list
    • Select a name and storage location and click OK

⇒ A new, empty eCLR library project is created.


  1. Create a new function, function bock, or function container

    → The template code sheet for the selected element opens.

⇒ A default code sheet for the selected type of element is created.


  1. Create the code
    • In the template code sheet, create the code for the function, function block, or function container 
      Note the "TODO" comment section in the code:Click to show a screenshot
      FB template dialog box
    • Observe the comments in the template, and the Known Issues and Constraints section of the online help
      Here you find the online help file:Click to show where to find that

      In Visual Studio, open your C# project and expand the EclrFirmwareLibrary branch in the Solution Explorer in the upper right corner of the screen.


      In the eCLR-Programming-Reference.chm file, the eCLR base class libraries' description is at hand while programming.

      Known issues and constraints of the current version are linked on the start page of this online help file. 

      In addition, the Readme.txt file contains a "cheat sheet" for common procedures in programming, along with a short overview how the IEC 61131-3 data types are matching to .NET and C# data types.

    • Create the entire project by pressing F6.

⇒ A *.pcwlx library is being stored in either the Release or the Debug directory of the project.


Proceed with importing the library into PLCnext Engineer to use your C# function or function block in an automation project.