Este contenido no está disponible en el idioma seleccionado.

Chapter 1. Using .NET Core 2.1 on Red Hat Enterprise Linux


This Getting Started Guide for RHEL 8 describes how to install .NET Core 2.1 on Red Hat Enterprise Linux (RHEL). See Red Hat Enterprise Linux documentation for more information about RHEL 8.

1.1. Install .NET Core

.NET Core 2.1 is included in the AppStream repositories for RHEL 8. The AppStream repositories are enabled by default on RHEL 8 systems.

  1. Install .NET Core 2.1 and all of its dependencies:

    $ sudo yum install dotnet-sdk-2.1 -y
  2. Run the following command to verify the installation:

    $ dotnet --info
    .NET Core SDK (reflecting any global.json):
     Version:   2.1.300
     Commit:    xxxxxxxxxx
    
    Runtime Environment:
     OS Name:     rhel
     OS Version:  8
     OS Platform: Linux
     RID:         rhel.8-x64
     Base Path:   /usr/lib64/dotnet/sdk/2.1.300/
    
    Host (useful for support):
      Version: 2.1.0
      Commit:  N/A
    
      .NET Core SDKs installed:
      2.1.300 [/usr/lib64/dotnet/sdk]
    
    .... omitted

1.2. Create an Application

  1. Create a new Console application in a directory called hello-world.

    $ dotnet new console -o hello-world
      The template "Console Application" was created successfully.
    
      Processing post-creation actions...
      Running 'dotnet restore' on hello-world/hello-world.csproj...
      Restoring packages for /home/<USER>/hello-world/hello-world.csproj...
      Generating MSBuild file /home/<USER>/hello-world/obj/hello-world.csproj.nuget.g.props.
      Generating MSBuild file /home/<USER>/hello-world/obj/hello-world.csproj.nuget.g.targets.
      Restore completed in 224.85 ms for /home/<USER>/hello-world/hello-world.csproj.
    
      Restore succeeded.
  2. Run the project.

    $ cd hello-world
    $ dotnet run
    Hello World!

1.3. Publish Applications

The .NET Core 2.1 applications can be published to use a shared system-wide version of .NET Core or to include .NET Core. These two deployment types are called framework-dependent deployment (FDD) and self-contained deployment (SCD), respectively.

For RHEL, we recommend publishing by FDD. This method ensures the application is using an up-to-date version of .NET Core, built by Red Hat, that includes a specific set of native dependencies. On the other hand, SCD uses a runtime built by Microsoft.

1.3.1. Publish .NET Core Applications

  1. Use the following command to publish a framework-dependent application.

    $ dotnet publish -f netcoreapp2.1 -c Release
  2. Optional: If the application is only for RHEL, trim out the dependencies needed for other platforms with these commands.

    $ dotnet restore -r rhel.8-x64
    $ dotnet publish -f netcoreapp2.1 -c Release -r rhel.8-x64 --self-contained false

1.3.2. Publish ASP.NET Core Applications

When using the Microsoft SDK, ASP.NET Core 2.1 web applications are published with a dependency on the ASP.NET Core shared framework. This is a set of packages that are expected to be available on the runtime system.

When publishing on RHEL, these packages are included with the application. To include the packages using the Microsoft SDK, the MicrosoftNETPlatformLibrary property must be set to Microsoft.NETCore.App in the project file as shown below.

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <MicrosoftNETPlatformLibrary>Microsoft.NETCore.App</MicrosoftNETPlatformLibrary>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.App" Version="2.1" />
  </ItemGroup>
</Project>

As an alternative, this property can be set when publishing the application.

$ dotnet publish -f netcoreapp2.1 -c Release -r rhel.8-x64 --self-contained false /p:MicrosoftNETPlatformLibrary=Microsoft.NETCore.App

1.4. Run Applications on Linux containers

This section shows how to use the ubi8/dotnet-21-runtime image to run a precompiled application inside a Linux container.

  1. Create a new mvc project in a directory named mvc_runtime_example.

    $ dotnet new mvc -o mvc_runtime_example --no-restore
    $ cd mvc_runtime_example
  2. Restore and publish the project.

    $ dotnet restore -r rhel.8-x64
    $ dotnet publish -f netcoreapp2.1 -c Release -r rhel.8-x64 --self-contained false /p:MicrosoftNETPlatformLibrary=Microsoft.NETCore.App
  3. Create the Dockerfile.

    $ cat > Dockerfile <<EOF
    FROM registry.access.redhat.com/ubi8/dotnet-21-runtime
    
    ADD bin/Release/netcoreapp2.1/rhel.8-x64/publish/ .
    
    CMD ["dotnet", "mvc_runtime_example.dll"]
    EOF
  4. Build your image.

    $ podman build -t dotnet-21-runtime-example .
  5. Run your image.

    $ podman run -d -p8080:8080 dotnet-21-runtime-example
  6. View the result in a browser: http://127.0.0.1:8080.

Report a bug

Red Hat logoGithubredditYoutubeTwitter

Aprender

Pruebe, compre y venda

Comunidades

Acerca de la documentación de Red Hat

Ayudamos a los usuarios de Red Hat a innovar y alcanzar sus objetivos con nuestros productos y servicios con contenido en el que pueden confiar. Explore nuestras recientes actualizaciones.

Hacer que el código abierto sea más inclusivo

Red Hat se compromete a reemplazar el lenguaje problemático en nuestro código, documentación y propiedades web. Para más detalles, consulte el Blog de Red Hat.

Acerca de Red Hat

Ofrecemos soluciones reforzadas que facilitan a las empresas trabajar en plataformas y entornos, desde el centro de datos central hasta el perímetro de la red.

Theme

© 2026 Red Hat
Volver arriba