Processing barcodes and drawings in documents in .NET 6 console applications requires the project to load Windows Forms assemblies. This article shows how to create a new .NET 6 console application that is able to process drawings and barcodes.

ASP.NET Applications

The settings applied in this tutorial is not only valid for .NET 6 console applications, but ASP.NET Core web applications, too. The UseWindowsForms flag can be used in the same way in ASP.NET Core project files.

Creating the Project

  1. In Visual Studio, create a new project and choose Console App from the project templates.

    Creating console applications

  2. In the next step, choose a name for your application and continue with Next.

  3. Select .NET 6.0 (Long-term support) and confirm with Create.

Adding Required Packages

  1. In the Solution Explorer, select your created project and choose Manage NuGet Packages... from the Project main menu.

    Browse for System.Drawing.Common and Install the latest version of the System.Drawing.Common package.

    Creating console applications

Adding TX Text Control

  1. While the project is selected in the Solution Explorer, choose Project -> Add Project Reference... to open the Reference Manager. In the opened dialog, select Browse... to select the required TX Text Control assemblies. Navigate to the installation folder of TX Text Control and select the following assemblies from the Assembly folder:

    • TXDocumentServer.dll
    • TXTextControl.dll
    • TXTextControl.Server.dll
    • TXBarcode.dll
    • TXBarcode.Windows.Forms.dll
    • TXDrawing.dll
    • TXDrawing.Windows.Forms.dll

    Create a .NET Core 6 application

    Repeat this step with the following assemblies from the Assembly/bin64 folder:

    • txic.dll
    • txkernel.dll
    • txtools.dll

    After selecting these assemblies, close the Reference Manager by confirming with OK.

  2. While the project is selected in the Solution Explorer, choose Project -> Add New Item.... Select Text File, name the file licenses.licx and close the dialog by clicking Add.

    Create a .NET Core 6 application

    Open the newly added file and add the following content:

    TXTextControl.ServerTextControl, TXTextControl.Server, Version=30.0.1500.500, Culture=neutral, PublicKeyToken=6b83fe9a75cfb638
    view raw licenses.licx hosted with ❤ by GitHub

    Set the Build Action property to Embedded Resource.

  3. Select the project in the Solution Explorer and choose Edit Project File from the Project main menu. Find the PropertyGroup entry and replace the whole node with the following code:

    view raw test.csproj hosted with ❤ by GitHub

    BinaryFormatter Information

    The above setting is required to enable the obsolete .NET BinaryFormatter while compiling the license into the assembly. We are working with Microsoft to avoid this requirement in the near future.

In the above project settings, the UseWindowsForms flag is enabling the application to load Windows Forms assemblies. In order to use this flag, the Target OS must be set to Windows which is done through the TargetFramework element in the project XML.

Now, the console application is prepared to use barcodes and drawings in your ServerTextControl documents.