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 Copiar enlaceEnlace copiado en el portapapeles!
.NET Core 2.1 is included in the AppStream repositories for RHEL 8. The AppStream repositories are enabled by default on RHEL 8 systems.
Install .NET Core 2.1 and all of its dependencies:
$ sudo yum install dotnet-sdk-2.1 -yRun 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 Copiar enlaceEnlace copiado en el portapapeles!
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.Run the project.
$ cd hello-world $ dotnet run Hello World!
1.3. Publish Applications Copiar enlaceEnlace copiado en el portapapeles!
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 Copiar enlaceEnlace copiado en el portapapeles!
Use the following command to publish a framework-dependent application.
$ dotnet publish -f netcoreapp2.1 -c ReleaseOptional: 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 Copiar enlaceEnlace copiado en el portapapeles!
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 Copiar enlaceEnlace copiado en el portapapeles!
This section shows how to use the ubi8/dotnet-21-runtime 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 --no-restore $ cd mvc_runtime_exampleRestore 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.AppCreate 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"] EOFBuild your image.
$ podman build -t dotnet-21-runtime-example .Run your image.
$ podman run -d -p8080:8080 dotnet-21-runtime-example- View the result in a browser: http://127.0.0.1:8080.