Chapter 1. Using .NET Core 3.0 on Red Hat Enterprise Linux
This Getting Started Guide 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 7.
1.1. Install and Register Red Hat Enterprise Linux Copy linkLink copied to clipboard!
Install RHEL 7 using one of the following images:
- Red Hat Enterprise Linux 7 Server
- Red Hat Enterprise Linux 7 Workstation
Red Hat Enterprise Linux for Scientific Computing
See the Red Hat Enterprise Linux Installation Guide for details on how to install RHEL.
See Red Hat Enterprise Linux Product Documentation page for available RHEL versions.
Use the following command to register the system.
sudo subscription-manager register
$ sudo subscription-manager registerCopy to Clipboard Copied! Toggle word wrap Toggle overflow You can also register the system by following the appropriate steps in Registering and Unregistering a System in the Red Hat Subscription Management document.
Display a list of all subscriptions that are available for your system and identify the pool ID for the subscription.
sudo subscription-manager list --available
$ sudo subscription-manager list --availableCopy to Clipboard Copied! Toggle word wrap Toggle overflow This command displays the subscription name, unique identifier, expiration date, and other details related to it. The pool ID is listed on a line beginning with Pool ID.
Attach the subscription that provides access to the
dotNET on RHELrepository. Use the pool ID you identified in the previous step.sudo subscription-manager attach --pool=<appropriate pool ID from the subscription>
$ sudo subscription-manager attach --pool=<appropriate pool ID from the subscription>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Enable the .NET Core channel for Red Hat Enterprise 7 Server, Red Hat Enterprise 7 Workstation, or HPC Compute Node with one of the following commands, respectively.
sudo subscription-manager repos --enable=rhel-7-server-dotnet-rpms sudo subscription-manager repos --enable=rhel-7-workstation-dotnet-rpms sudo subscription-manager repos --enable=rhel-7-hpc-node-dotnet-rpms
$ sudo subscription-manager repos --enable=rhel-7-server-dotnet-rpms $ sudo subscription-manager repos --enable=rhel-7-workstation-dotnet-rpms $ sudo subscription-manager repos --enable=rhel-7-hpc-node-dotnet-rpmsCopy to Clipboard Copied! Toggle word wrap Toggle overflow Verify the list of subscriptions attached to your system.
sudo subscription-manager list --consumed
$ sudo subscription-manager list --consumedCopy to Clipboard Copied! Toggle word wrap Toggle overflow Install the
scltool.sudo yum install scl-utils
$ sudo yum install scl-utilsCopy to Clipboard Copied! Toggle word wrap Toggle overflow
1.2. Install .NET Core Copy linkLink copied to clipboard!
Install .NET Core 3.0 and all of its dependencies.
sudo yum install rh-dotnet30 -y
$ sudo yum install rh-dotnet30 -yCopy to Clipboard Copied! Toggle word wrap Toggle overflow Enable the
rh-dotnet30Software Collection environment so you can rundotnetcommands in the bash shell.This procedure installs the .NET Core 3.0 runtime with the latest 3.0 SDK. When a newer SDK becomes available, it automatically installs as a package update.
scl enable rh-dotnet30 bash
$ scl enable rh-dotnet30 bashCopy to Clipboard Copied! Toggle word wrap Toggle overflow This command does not persist; it creates a new shell, and the
dotnetcommand is only available within that shell. If you log out, use another shell, or open up a new terminal, thedotnetcommand is no longer enabled.WarningRed Hat does not recommend permanently enabling
rh-dotnet30because it may affect other programs. For example,rh-dotnet30includes a version oflibcurlthat differs from the base RHEL version. This may lead to issues in programs that do not expect a different version oflibcurl. If you want to enablerh-dotnetpermanently, add the following line to your~/.bashrcfile.source scl_source enable rh-dotnet30Run the following command to verify the installation succeeded.
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
1.3. Create an Application Copy linkLink copied to clipboard!
Create a new Console application in a directory called
hello-world.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Run the project.
cd hello-world dotnet run Hello World!
$ cd hello-world $ dotnet run Hello World!Copy to Clipboard Copied! Toggle word wrap Toggle overflow
1.4. Publish Applications Copy linkLink copied to clipboard!
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. These native libraries are part of the rh-dotnet30 Software Collection. On the other hand, SCD uses a runtime built by Microsoft. Running applications outside the rh-dotnet30 Software Collection may cause issues due to the unavailability of native libraries.
Use the following command to publish a framework-dependent application.
dotnet publish -f netcoreapp3.0 -c Release
$ dotnet publish -f netcoreapp3.0 -c ReleaseCopy to Clipboard Copied! Toggle word wrap Toggle overflow Optional: If the application is only for RHEL, trim out the dependencies needed for other platforms with these commands.
dotnet restore -r rhel.7-x64 dotnet publish -f netcoreapp3.0 -c Release -r rhel.7-x64 --self-contained false
$ dotnet restore -r rhel.7-x64 $ dotnet publish -f netcoreapp3.0 -c Release -r rhel.7-x64 --self-contained falseCopy to Clipboard Copied! Toggle word wrap Toggle overflow Enable the Software Collection and pass the application name to run the application on a RHEL system.
scl enable rh-dotnet30 -- dotnet <app>.dll
$ scl enable rh-dotnet30 -- dotnet <app>.dllCopy to Clipboard Copied! Toggle word wrap Toggle overflow This command can be added to a script that is published with the application. Add the following script to your project and update the
APPvariable.Copy to Clipboard Copied! Toggle word wrap Toggle overflow To include the script when publishing, add this ItemGroup to the
csprojfile.<ItemGroup> <None Update="<scriptname>" Condition="'$(RuntimeIdentifier)' == 'rhel.7-x64' and '$(SelfContained)' == 'false'" CopyToPublishDirectory="PreserveNewest" /> </ItemGroup><ItemGroup> <None Update="<scriptname>" Condition="'$(RuntimeIdentifier)' == 'rhel.7-x64' and '$(SelfContained)' == 'false'" CopyToPublishDirectory="PreserveNewest" /> </ItemGroup>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
1.5. Run Applications on Linux Containers Copy linkLink copied to clipboard!
This section shows how to use the dotnet/dotnet-30-runtime-rhel7 image to run a precompiled application inside a Linux container.
Create a new mvc project in a directory named
mvc_runtime_example.dotnet new mvc -o mvc_runtime_example cd mvc_runtime_example
$ dotnet new mvc -o mvc_runtime_example $ cd mvc_runtime_exampleCopy to Clipboard Copied! Toggle word wrap Toggle overflow Publish the project.
dotnet publish -f netcoreapp3.0 -c Release
$ dotnet publish -f netcoreapp3.0 -c ReleaseCopy to Clipboard Copied! Toggle word wrap Toggle overflow Create the
Dockerfile.Copy to Clipboard Copied! Toggle word wrap Toggle overflow Build your image.
podman build -t dotnet-30-runtime-example .
$ podman build -t dotnet-30-runtime-example .Copy to Clipboard Copied! Toggle word wrap Toggle overflow NoteIf you get an error containing the message
unable to retrieve auth token: invalid username/password, you need to provide credentials for theregistry.redhat.ioserver. Use the command$ podman login registry.redhat.ioto log in. Your credentials are typically the same as those used for the Red Hat Customer Portal.Run your image.
podman run -d -p8080:8080 dotnet-30-runtime-example
$ podman run -d -p8080:8080 dotnet-30-runtime-exampleCopy to Clipboard Copied! Toggle word wrap Toggle overflow -
View the result in a browser:
http://127.0.0.1:8080.