Programming Languages on Power

 View Only

Installing and running a sample .NET Hello World application on IBM Power

By Sapana Khemkar posted Tue December 27, 2022 01:05 AM

  

 

In this blog, you will learn how to write a sample Hello World application in C# and F#, either using a .NET rpm package or a .NET container image.

Prerequisite

A system with Linux (RHEL 8.7 or 9.1) on IBM Power must be available to you.

Note: If you need access to Power hardware, see Accelerate your open source development with access to IBM Power resources. It lists several free and low-cost options. If you are an open source developer, you might want to consider the Oregon State University - Open Source Lab option.

Install .NET

Installing .NET using the YUM or DNF software package manager is the easiest way to install .NET. Complete the following steps to install .NET.

1.      Run the following command in  terminal to install .NET

sudo yum install dotnet-sdk-7.0

2.      Use either of the following commands to verify if the installation is successful.

dotnet --info
dotnet --version

Use the container image

Pull the container image and run it using the docker run command.

docker run -it registry.access.redhat.com/ubi8/dotnet-70

Your output will look something like below

$ sudo docker run -it registry.access.redhat.com/ubi8/dotnet-70
Unable to find image 'registry.access.redhat.com/ubi8/dotnet-70:latest' locally
latest: Pulling from ubi8/dotnet-70
Digest: sha256:996b4778d020e490e9e1f4941d930e16dab3930e2cfbe38de8b4d5f7d972483b
Status: Downloaded newer image for registry.access.redhat.com/ubi8/dotnet-70:latest

Build/Run C# Hello World console app

1.      Create a template application using the dotnet new command. Use the -lang option to specify the language for template. It can be C#, F#, or Visual Basic. Default is C#. Use the –o option to provide an output directory and the -f option for the framework version.

dotnet new console -o <OutputDirectory>  

 

Sample output is as follows:

bash-4.4$ dotnet new console -o HelloWorld
The template "Console App" was created successfully.

Processing post-creation actions...
Restoring /opt/app-root/src/HelloWorld/HelloWorld.csproj:
Determining projects to restore...
Restored /opt/app-root/src/HelloWorld/HelloWorld.csproj (in 492 ms).
Restore succeeded.

You can see Program.cs and HelloWorld.csproj in the HelloWorld directory.

2.      Run your code using the dotnet run command from the project directory. Your output should look as follows:

bash-4.4$ cd HelloWorld/
bash-4.4$ dotnet run
Hello, World!

 

3.      Similarly, you can create a sample console application for F# using the dotnet new console command. However, you need to pass one additional parameter, -lang “F#”.

 Sample output for console application for F# is given below:

bash-4.4$ dotnet new console -lang "F#" -o FSharpHelloWorld
The template "Console App" was created successfully.

Processing post-creation actions...
Restoring /opt/app-root/src/FSharpHelloWorld/FSharpHelloWorld.fsproj:
Determining projects to restore...
Restored /opt/app-root/src/FSharpHelloWorld/FSharpHelloWorld.fsproj (in 1.32 sec).
Restore succeeded.


bash-4.4$ cd FSharpHelloWorld/
bash-4.4$ ls
FSharpHelloWorld.fsproj Program.fs obj
bash-4.4$ dotnet build
MSBuild version 17.4.0+18d5aef85 for .NET
Determining projects to restore...
All projects are up-to-date for restore.
FSharpHelloWorld -> /opt/app-root/src/FSharpHelloWorld/bin/Debug/net7.0/FSharpHelloWorld.dll

Build succeeded.
0 Warning(s)
0 Error(s)

Time Elapsed 00:00:15.86
bash-4.4$ dotnet run
Hello from F#

 Conclusion

In this blog you have learned to install .NET on a system with IBM Power and run a sample, HelloWorld application in C# and F# languages. Now, you are ready to implement your own .NET application on Power.

 References

·         How to install .NET 7

·         .NET fundamentals

·         .NET Tutorial
 

 


#Featured-area-1#Featured-area-3-home

Permalink