The TX Text Control NuGet packages are not publicly available on nuget.org because they contain licensing information required for deployment. These packages are typically installed through the developer setup, which registers a local NuGet source on the developer's machine.
While this works well for local development, it can become a challenge when deploying applications, especially in automated environments such as CI/CD pipelines or Docker containers. An effective solution is to upload the licensed NuGet packages to a private feed, such as GitHub Packages, to make them accessible during the build and publish process.
Why Are TX Text Control Packages Not on NuGet.org?
TX Text Control packages are licensed components. Unlike open source or public libraries, they have licensing information embedded in the package. Because of these limitations, they are not distributed via public feeds. Instead, developers install them through the TX Text Control setup, which registers a local source such as:
C:\Program Files (x86)\Text Control GmbH\NuGetPackages
This approach doesn't work with build servers or Docker containers. To solve this, you can host the packages in a private NuGet feed, like GitHub Packages.
Uploading TX Text Control Packages to GitHub Packages
GitHub Packages is a package hosting service that allows you to host and manage packages in your GitHub repositories. It supports multiple package formats, including NuGet, npm, Docker, and more. With GitHub Packages, you can easily share your packages with your team or the public, while keeping them secure.
Creating a GitHub Personal Access Token
To upload TX Text Control packages to GitHub Packages, follow these steps:
-
Install the TX Text Control setup on your local machine. This will register the local NuGet source.
-
Create a GitHub personal access token (PAT) with the scope write:packages and read:packages. You'll use this token to authenticate when you publish.
-
While logged in to your GitHub account, open the token settings:
-
Click on Generate new token and select Generate new token (classic).
-
Give your token a descriptive name, select the expiration date, and check the scopes write:packages and read:packages.
-
Click on Generate token. Make sure to copy the token immediately, as you won't be able to see it again. Store the token securely. You will need it to authenticate when you publish the packages.
-
Publishing TX Text Control Packages
Once you have the personal access token (PAT), you can publish the TX Text Control packages to GitHub Packages. Follow these steps:
-
Open PowerShell or Command Prompt and use the following command to set up the GitHub Packages source:
dotnet nuget add source --username YOUR_GITHUB_USERNAME --password YOUR_GITHUB_PAT --store-password-in-clear-text --name github "https://nuget.pkg.github.com/YOUR_GITHUB_USERNAME/index.json"
Replace YOUR_GITHUB_USERNAME with your GitHub username and YOUR_GITHUB_PAT with the personal access token you created earlier.
-
Use the following command to publish the TX Text Control packages:
dotnet nuget push "C:\Program Files (x86)\Text Control GmbH\NuGetPackages\TXTextControl.TextControl.Core.SDK.33.0.0.nupkg" --source "github" --api-key YOUR_GITHUB_PAT
Replace TXTextControl.TextControl.Core.SDK.33.0.0.nupkg with the path to the TX Text Control package you want to publish. This sample uses the TX Text Control .NET Core SDK package.
Adding the GitHub Packages Source to Your Project
-
In your .NET project, create a file named nuget.config in the root directory. This file will contain the configuration for the NuGet sources.
-
In the nuget.config file, add the following content:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters<?xml version="1.0" encoding="utf-8"?> <configuration> <packageSources> <!-- Default NuGet.org --> <add key="nuget.org" value="https://api.nuget.org/v3/index.json" /> <!-- GitHub Packages --> <add key="github" value="https://nuget.pkg.github.com/YOUR_GITHUB_USERNAME/index.json" /> </packageSources> <packageSourceCredentials> <github> <add key="Username" value="YOUR_GITHUB_USERNAME" /> <add key="ClearTextPassword" value="YOUR_GITHUB_PAT" /> </github> </packageSourceCredentials> </configuration>
Restoring TX Text Control in Docker Builds
In your Dockerfile, make sure that the nuget.config file is copied to the image. This ensures that the Docker build process can access the TX Text Control packages from GitHub Packages.
Here is an example of a Dockerfile that includes the nuget.config file:
# See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging. | |
# This stage is used when running from VS in fast mode (Default for Debug configuration) | |
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base | |
WORKDIR /app | |
EXPOSE 8080 | |
EXPOSE 8081 | |
# This stage is used to build the service project | |
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build | |
ARG BUILD_CONFIGURATION=Release | |
WORKDIR /src | |
COPY ["tx-web-api-core.csproj", "tx-web-api-core/"] | |
COPY ["nuget.config", "tx-web-api-core/"] | |
RUN dotnet restore "./tx-web-api-core/tx-web-api-core.csproj" | |
WORKDIR "/src/tx-web-api-core" | |
COPY . . | |
RUN dotnet build "tx-web-api-core.csproj" -c $BUILD_CONFIGURATION -o /app/build | |
# This stage is used to publish the service project to be copied to the final stage | |
FROM build AS publish | |
ARG BUILD_CONFIGURATION=Release | |
RUN dotnet publish "./tx-web-api-core.csproj" -c $BUILD_CONFIGURATION -r linux-x64 -o /app/publish /p:UseAppHost=false | |
# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration) | |
FROM base AS final | |
WORKDIR /app | |
COPY --from=publish /app/publish . | |
ENTRYPOINT ["dotnet", "tx-web-api-core.dll"] |
In this example, the Dockerfile copies the nuget.config file to the project directory in the image. The dotnet restore command will use this configuration to restore the TX Text Control packages from GitHub Packages.
Defining the Target Runtime
Pay attention to line 29 in the Dockerfile. The -r linux-x64 option is used to publish the application for the Linux x64 runtime. This is important because the TX Text Control packages are platform-specific, and you need to ensure that the correct version is restored for the target platform.
After building the Docker image, you can run the container and use TX Text Control in your application.
Conclusion
By following these steps, you can successfully upload TX Text Control packages to GitHub Packages and use them in your projects. This approach allows you to manage your dependencies more effectively, especially in automated environments such as CI/CD pipelines and Docker containers.