DOTNET On Red Hat Enterprise Linux Cheat Sheet Developer2
DOTNET On Red Hat Enterprise Linux Cheat Sheet Developer2
Cheat sheet
Desktop applications, phone apps, web sites, web services, and even Linux daemons can be written in one or more of
the supported .NET languages: C#, Visual Basic, and F#.
Because .NET can now run on Linux, the world of microservices has opened up to .NET developers as well. Running a
.NET program in a Linux container is as simple as it is in any other language.
This cheat sheet covers the basics of installing .NET on Red Hat Enterprise Linux (RHEL), how to get a simple
program running, and how to run a program in a Linux container. Finally, a list of valuable resources is included.
Installation
To install the .NET Core SDK on RHEL, use the following command:
Build options
When you build a .NET application, you have output options: Portable (the default) or Standalone.
Portable application
By default, running dotnet build will build your program as a Portable Application. This means the compiler will create
{appname}.dll ; for example, helloworld.dll . This DLL can then be copied to any machine hosting an installation
of .NET Core and it will run, regardless of operating system. For example, you could copy the DLL from a Mac onto a
Linux machine (which has .NET Core installed) and it will execute.
developers.redhat.com redhat-developer @rhdevelopers
Standalone application
.NET Core allows you to compile an application so that it will run on a machine that does not have .NET installed.
Further, you can cross-compile from any operating system to any operating system. For example, you can compile
your application on your Windows 10 machine and then install and run it on a Linux machine that does not have .NET
Core installed. This powerful feature of .NET Core does not exist in the previous .NET Framework. To create a
standalone application, you use the dotnet publish command.
Note that the standalone application does not create an .exe file. Like the Portable application, it creates a DLL that is
run by the dotnet host. The standalone application avoids the need for a .NET Core installation by copying all of the
necessary bits to the directory where you build the application. That is, you are not copying one file to the target; you
must copy the entire directory and any sub-directories.
mkdir helloworld
cd helloworld
dotnet new console
dotnet run
dotnet —help
The —-help flag will display help for the lowest-level available based on the dotnet command you’ve typed.
dotnet —help gives you broad help about the dotnet command, while dotnet new —help gives you more detailed help
about the dotnet new command, and so on.
For example, to create an MVC ASP.NET web site, you would run the following command:
This creates a web site using C# as the language. Adding the —language F# flag will create source code in F#.
dotnet restore
The dotnet restore command will retrieve the dependency libraries needed for your application as defined in the
project file. By default, the command will download the libraries from https://www.nuget.org.
Note that dotnet restore will run automatically when building an application unless you use the -—no-restore flag.
dotnet add
The dotnet add command is used to insert a reference into your project file. While you can, if you wish, manually edit
your project file, this command makes it easier to add a reference. For example, if you wish to reference the NuGet
package “Json.NET” in your project, you would use the following command:
mkdir myexample
cd myexample
dotnet new myexample
developers.redhat.com redhat-developer @rhdevelopers
curl localhost:8080/weatherforecast
developers.redhat.com redhat-developer @rhdevelopers
Valuable resources
The following web sites are excellent sources of information regarding .NET Core development:
• dot.net: This vanity URL will redirect you to Microsoft’s official .NET Core page. From there you can download
and install .NET Core, find documentation, etc.
• live.asp.net: This URL will direct you to the weekly ASP.NET Core Community Standup, a live webcast (also
recorded and available on YouTube) of the newest happenings regarding ASP.NET and .NET Core.
• redhatloves.net: This vanity URL directs you to the .NET on Linux section of the Red Hat Developer program.
This program contains resources such as books, blog posts, videos, and free software—including the Red Hat
Development Suite. This suite includes RHEL, Virtual Box, Vagrant, docker, kubernetes, and OpenShift.
• github.com/aspnet: The home of the ASP.NET Core code, including EntityFramework (which is included in this
repo but is not a part of ASP.NET).