# Creating an ASP.NET Core Web App with Docker Support and GitHub Packages

> This article shows how to create an ASP.NET Core Web App with Docker support. The TX Text Control NuGet packages are hosted on GitHub Packages to get restored during the build process.

- **Author:** Bjoern Meyer
- **Published:** 2024-01-05
- **Modified:** 2026-07-17
- **Description:** This article shows how to create an ASP.NET Core Web App with Docker support. The TX Text Control NuGet packages are hosted on GitHub Packages to get restored during the build process.
- **5 min read** (949 words)
- **Tags:**
  - ASP.NET
  - Licensing
  - Docker
  - NuGet
  - GitHub
- **Web URL:** https://www.textcontrol.com/blog/2024/01/05/creating-an-asp-net-core-web-app-with-docker-support-and-github-packages/
- **LLMs URL:** https://www.textcontrol.com/blog/2024/01/05/creating-an-asp-net-core-web-app-with-docker-support-and-github-packages/llms.txt
- **LLMs-Full URL:** https://www.textcontrol.com/blog/2024/01/05/creating-an-asp-net-core-web-app-with-docker-support-and-github-packages/llms-full.txt

---

With the [new licensing mechanism](https://www.textcontrol.com/blog/2024/01/05/tx-text-control-32-0-sp2-licensing-changes/llms-full.txt) introduced in TX Text Control 32.0 SP2, ASP.NET Core projects can be restored and built in Docker. This tutorial shows you how to create an ASP.NET Core Web application with Docker support that uses ServerTextControl. In order to be restored during the Docker build process, the TX Text Control NuGet package is stored in [GitHub Packages](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-nuget-registry).

### Creating the Application

Make sure that you downloaded the latest version of Visual Studio 2022 that comes with the [.NET 6 SDK](https://dotnet.microsoft.com/download/dotnet/6.0).

1. In Visual Studio 2022, create a new project by choosing *Create a new project*.
2. Select *ASP.NET Core Web App (Model-View-Controller)* as the project template and confirm with *Next*.
3. Choose a name for your project and confirm with *Next*.
4. In the next dialog, choose *.NET 8 (Long-term support)* as the *Framework*, disable *Configure for HTTPS* for effortless testing, check *Enable Docker* and confirm with *Create*. Make sure that *Windows* is selected as the *Docker OS*.
    
    ![Creating the .NET 6 project](https://s1-www.textcontrol.com/assets/dist/blog/2024/01/05/f/assets/visualstudio1.webp "Creating the .NET 6 project")

#### Adding the NuGet Package

5. In the *Solution Explorer*, select your created project and choose *Manage NuGet Packages...* from the *Project* main menu.
    
    Select *Text Control Offline Packages* from the *Package source* drop-down.
    
    *Install* the latest versions of the following package:
    
    
    - *TXTextControl.TextControl.ASP.SDK*
    
    ![ASP.NET Core Web Application](https://s1-www.textcontrol.com/assets/dist/blog/2024/01/05/f/assets/visualstudio2.webp "ASP.NET Core Web Application")

#### Using ServerTextControl and MailMerge

6. Find the *HomeController.cs* file in the *Controllers* folder. Replace the *Index()* method with the following code:
    
    ```
    public IActionResult Index() {
    
      using (TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl()) {
        tx.Create();
    
        // adding static text
        TXTextControl.Selection sel = new TXTextControl.Selection();
        sel.Text = "Welcome to Text Control\r\n";
        sel.Bold = true;
    
        tx.Selection = sel;
    
        // adding merge fields
        TXTextControl.DocumentServer.Fields.MergeField mergeField = 
          new TXTextControl.DocumentServer.Fields.MergeField() {
            Text = "{{company}}",
            Name = "company",
            TextBefore = "Company name: "
          };
    
        tx.ApplicationFields.Add(mergeField.ApplicationField);
    
        // alternatively load a template
        //TXTextControl.LoadSettings ls = new TXTextControl.LoadSettings() {
        //	ApplicationFieldFormat = TXTextControl.ApplicationFieldFormat.MSWord
        //};
    
        //tx.Load("template.docx", TXTextControl.StreamType.WordprocessingML, ls);
    
        // merge fields with MailMerge engine
        using (TXTextControl.DocumentServer.MailMerge mailMerge = 
          new TXTextControl.DocumentServer.MailMerge()) {
            mailMerge.TextComponent = tx;
            mailMerge.MergeJsonData("[{\"company\": \"Text Control, LLC\" }]");
          }
    
        // return result as HTML
        string result = "";
        tx.Save(out result, TXTextControl.StringStreamType.HTMLFormat);
    
        // alternatively save as PDF
        //byte[] baPdf;
        //tx.Save(out baPdf, TXTextControl.BinaryStreamType.AdobePDF);
    
        ViewBag.Document = result;
      }
    
      return View();
    }
    ```

#### Displaying the Results

7. Find the *Index.cshtml* file in the *Views -> Home* folder. Replace the complete file with the following code:
    
    ```
    @{
        ViewData["Title"] = "Home Page";
    }
    
    @Html.Raw(ViewBag.Document)
    ```

### Configure NuGet in Project

We need to configure the NuGet package source in the project. This is required to restore the TX Text Control NuGet package during the Docker build process.

> **NuGet Package Server**
> 
> Because the TX Text Control NuGet packages contain unique serial number information and are installed locally on your computer, they must be hosted in a NuGet hosting product. This tutorial uses the GitHub package registry, but there are other NuGet hosting products available, such as Azure Artifacts.

1. Open an elevated (developer) command prompt to add GitHub as a package source for NuGet.
    
    ```
    dotnet nuget add source --username USERNAME --password [TOKEN] --store-password-in-clear-text --name github "https://nuget.pkg.github.com/[NAMESPACE]/index.json"
    ```
    
    
    - Replace \[TOKEN\] with your personal access token (classic). Learn [here](https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens) how to create this token.
    - Replace \[NAMESPACE\] with your GitHub username.
    
    > **Download NuGet**
    > 
    > The **NuGet.exe** CLI is not automatically installed by Visual Studio and can be downloaded directly here:
    > 
    > <https://www.nuget.org/downloads>
2. Use the following command to push the NuGet package to GitHub.
    
    ```
    dotnet nuget push "C:\Program Files (x86)\Text Control GmbH\NuGetPackages\TXTextControl.TextControl.ASP.SDK.32.0.2.nupkg"  --api-key [TOKEN] --source "github"
    ```
    
    
    - Replace \[TOKEN\] with your personal access token (classic).
3. In your Visual Studio project, create a new file in the project's root folder named *nuget.config* and copy the following configuration into it:
    
    ```
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <packageSources>
        <clear />
    
        <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
        <add key="github" value="https://nuget.pkg.github.com/[NAMESPACE]/index.json" />
        
      </packageSources>
      <packageSourceCredentials>
        <github>
          <add key="Username" value="USERNAME" />
          <add key="ClearTextPassword" value="[TOKEN]" />
        </github>
      </packageSourceCredentials>
    
    </configuration>
    ```
    
    
    - Replace \[TOKEN\] with your personal access token (classic).
    - Replace \[NAMESPACE\] with your GitHub username.

### Project Settings

Some project settings are required.

1. Select the project in the *Solution Explorer* and choose *Edit Project File* from the *Project* main menu. Make sure that the project settings match the settings in the following example:
    
    ```
    <PropertyGroup>
      <TargetFramework>net8.0-windows</TargetFramework>
      <Nullable>enable</Nullable>
      <ImplicitUsings>enable</ImplicitUsings>
      <DockerDefaultTargetOS>Windows</DockerDefaultTargetOS>
      <PlatformTarget>x64</PlatformTarget>
      <RuntimeIdentifier>win-x64</RuntimeIdentifier>
      <Platforms>AnyCPU;x64</Platforms>
    </PropertyGroup>
    ```

### Editing the Dockerfile

Now, we need to edit the *Dockerfile* to restore the TX Text Control NuGet package during the build process.

1. Open the *Dockerfile* in the project's root folder and replace it with the following content:
    
    ```
    FROM mcr.microsoft.com/dotnet/aspnet:8.0-windowsservercore-ltsc2019 AS base
    WORKDIR /app
    EXPOSE 8080
    
    FROM mcr.microsoft.com/dotnet/sdk:8.0-windowsservercore-ltsc2019 AS build
    ARG BUILD_CONFIGURATION=Release
    WORKDIR /src
    COPY ["NuGetDockerApp/NuGetDockerApp.csproj", "NuGetDockerApp/"]
    
    COPY NuGetDockerApp/nuget.config .
    
    RUN dotnet restore "./NuGetDockerApp/./NuGetDockerApp.csproj"
    COPY . .
    WORKDIR "/src/NuGetDockerApp"
    RUN dotnet build "./NuGetDockerApp.csproj" -c %BUILD_CONFIGURATION% -o /app/build
    
    FROM build AS publish
    ARG BUILD_CONFIGURATION=Release
    RUN dotnet publish "./NuGetDockerApp.csproj" -r win-x64 -c %BUILD_CONFIGURATION% -o /app/publish /p:UseAppHost=false
    
    FROM base AS final
    WORKDIR /app
    COPY --from=publish /app/publish .
    
    # Install Visual C++ Redistributables
    
    SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
    RUN [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; \
    	Invoke-WebRequest "https://aka.ms/vs/17/release/vc_redist.x64.exe" -OutFile "vc_redist.x64.exe"; \
    	Start-Process "vc_redist.x64.exe" -ArgumentList "/passive" -wait -Passthru; \
    	Remove-Item -Force vc_redist.x64.exe;
    
    ENTRYPOINT ["dotnet", "NuGetDockerApp.dll"]
    ```
    
    
    - Replace *NuGetDockerApp* with the name of your project.

### Building the Docker Image

Press F5 to build and deploy the application using Docker.

---

## About Bjoern Meyer

As CEO, Bjoern is the visionary behind our strategic direction and business development, bridging the gap between our customers and engineering teams. His deep passion for coding and web technologies drives the creation of innovative products. If you're at a tech conference, be sure to stop by our booth - you'll most likely meet Bjoern in person. With an advanced graduate degree (Dipl. Inf.) in Computer Science, specializing in AI, from the University of Bremen, Bjoern brings significant expertise to his role. In his spare time, Bjoern enjoys running, paragliding, mountain biking, and playing the piano.

- [LinkedIn](https://www.linkedin.com/in/bjoernmeyer/)
- [X](https://x.com/txbjoern)
- [GitHub](https://github.com/bjoerntx)

---

## Related Posts

- [Building a TX Text Control Project with GitHub Actions and the Text Control NuGet Feed](https://www.textcontrol.com/blog/2026/02/09/building-a-tx-text-control-project-with-github-actions-and-the-text-control-nuget-feed/llms.txt)
- [Using a Private NuGet Feed to Build and Restore .NET Apps for Docker Deployment](https://www.textcontrol.com/blog/2025/04/11/using-a-private-nuget-feed-to-build-and-restore-dotnet-apps-for-docker-deployment/llms.txt)
