Chapter 1. Using .NET Core 3.0 on Red Hat Enterprise Linux 8

This Getting Started Guide for RHEL 8 describes how to install .NET Core 3.0 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 3.0 is included in the AppStream repositories for RHEL 8. The AppStream repositories are enabled by default on RHEL 8 systems.

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

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

    $ dotnet --info
    .NET Core SDK (reflecting any global.json):
     Version:   3.0.100
     Commit:    xxxxxxxxxx
    
    Runtime Environment:
     OS Name:     rhel
     OS Version:  8
     OS Platform: Linux
     RID:         rhel.8-x64
     Base Path:   /usr/lib64/dotnet/sdk/3.0.100/
    
    Host (useful for support):
      Version: 3.0.0
      Commit:  xxxxxxxxxx
    
    .NET Core SDKs installed:
      3.0.100 [/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...
      Restore completed in 87.21 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 3.0 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. Use the following command to publish a framework-dependent application.

    $ dotnet publish -f netcoreapp3.0 -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 netcoreapp3.0 -c Release -r rhel.8-x64 --self-contained false

1.4. Run Applications on Linux Containers

This section shows how to use the ubi8/dotnet-30-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
    $ cd mvc_runtime_example
  2. Publish the project.

    $ dotnet publish -f netcoreapp3.0 -c Release
  3. Create the Dockerfile.

    $ cat > Dockerfile <<EOF
    FROM registry.access.redhat.com/ubi8/dotnet-30-runtime
    
    ADD bin/Release/netcoreapp3.0/publish/ .
    
    CMD ["dotnet", "mvc_runtime_example.dll"]
    EOF
  4. Build your image.

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

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

Report a bug