Using .NET 7 on Fedora Linux

.NET 7 is now available in Fedora Linux. This article briefly describes what .NET is, some of its recent and interesting features, how to install it, and presents some examples showing how it can be used.

.NET 7

.NET is a platform for building cross platform applications. It allows you to write code in C#, F#, or VB.NET. You can easily develop applications on one platform and deploy and execute them on another platform or architecture.

In particular, you can develop applications on Windows and run them on Fedora Linux instead! This is one less hurdle if you want to move from a proprietary platform to Fedora Linux. It’s also possible to develop on Fedora and deploy to Windows. Please note that in this last scenario, some Windows-specific application types, such as GUI Windows applications, are not available.

.NET 7 includes a number of new and exciting features. It includes a large number of performance enhancements to the runtime and the .NET libraries, better APIs for working with Unix file permissions and tar files, better support for observability via OpenTelemetry, and compiling applications ahead-of-time. For more details about all the new features in .NET 7, see https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotnet-7.

Fedora Linux builds of .NET 7 can even run on the IBM Power (ppc64le) architecture. This is in addition to support for 64-bit ARM/Aarch64 (which Fedora Linux calls aarch64 and .NET calls arm64), IBM Z (s390x) and 64-bit Intel/AMD platforms (which Fedora Linux calls x86_64 and .NET calls x64).

.NET 7 is a Standard Term Support (STS) release, which means upstream will stop maintaining it on May 2024. .NET in Fedora Linux will follow that end date. If you want to use a Long Term Support (LTS) release, please use .NET 6 instead. .NET 6 reaches its end of Life on November 2024. For more details about the .NET lifecycle, see https://dotnet.microsoft.com/en-us/platform/support/policy/dotnet-core.

If you are looking to set up a development environment for developing .NET applications on Fedora Linux, take a look at https://fedoramagazine.org/set-up-a-net-development-environment/.

The .NET Special Interest Group (DotNetSIG) maintains .NET in Fedora Linux. Please come and join us to improve .NET on Fedora Linux! You can reach us via IRC (#fedora-devel) or mailing lists (dotnet-sig@lists.fedoraproject.org) if you have any feedback, questions, ideas or suggestions.

How to install .NET 7

To build C#, F# or VB.NET code on Fedora Linux, you will need the .NET SDK. If you only want to run existing applications, you will only need the .NET Runtime.

Install the .NET 7 Software Development Kit (SDK) using this command:

sudo dnf install -y dotnet-sdk-7.0

This installs all the dependencies, including a .NET runtime.

If don’t want to install the entire SKD but just want to run .NET 7 applications, you can install either the ASP.NET Core runtime or the .NET runtime using one of the following commands:

sudo dnf install -y aspnetcore-runtime-7.0
sudo dnf install -y dotnet-runtime-7.0

This style of package name applies to all versions of .NET on all versions of Fedora Linux. For example, you can install .NET 6 using the same style of package name:

sudo dnf install -y dotnet-sdk-6.0

To make certain .NET 7 is installed, run dotnet –info to see all the SDKs and Runtimes installed.

License and Telemetry

The .NET packages in Fedora Linux are built from fully Open Source source code. The primary license is MIT. The .NET packages in Fedora Linux do not contain any closed source or proprietary software. The Fedora .NET team builds .NET offline in the Fedora Linux build system and removes all binaries present in the source code repositories before building .NET. This gives us a high degree of confidence that .NET is built from reviewed sources.

The .NET packages in Fedora Linux do not collect any data from users. All telemetry is disabled in the Fedora builds of .NET. No data is collected from anyone running .NET and no data is sent to Microsoft. We run tests to verify this for every build of .NET in Fedora Linux.

“Hello World” in .NET

After installing .NET 7, you can use it to create and run applications. For example, you can use the following steps to create and run the classic “Hello World” application.

Create a new .NET 7 project in the C# language:

dotnet new console -o HelloWorldConsole

This will create a new directory named HelloWorldConsole and create a trivial C# Hello World that prints hello world.

Then, switch to the project directory:

cd HelloWorldConsole

Finally, build and run your the application:

dotnet run

.NET 7 will build your program and run it. You should see a “Hello world” output from your program.

“Hello Web” in .NET

You can also use .NET to create web applications. Lets do that now.

First, create a new web project, in a separate directory (not under our previous project):

dotnet new web -o HelloWorldWeb

This will create a simple Hello-World style application based on .NET’s built-in web (Empty ASP.NET Core) template.

Now, switch to that directory:

cd HelloWorldWeb

Finally, build and run the application:

dotnet run

You should see output like the following that shows the web application is running.

Building…
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://localhost:5105
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
Content root path: /home/omajid/temp/HelloWorldWeb

Use a web browser to access the application. You can find the URL in the output at the “Now listening on:” line. In my case that’s http://localhost:5105:

firefox http://localhost:5105

You should see a “Hello World” message in your browser.

Using .NET with containers

At this point, you have successfully created, built and run .NET applications locally. What if you want to isolate your application and everything about it? What if you want to run it in a non-Fedora OS? Or deploy it to a public/private/hybrid cloud? You can use containers! Let’s build a container image for running your .NET program and test it out.

First, create a new project:

dotnet new web -o HelloContainer

Then, switch to that project directory:

cd HelloContainer

Then add a Dockerfile that describes how to build a container for our application.

FROM fedora:37
RUN dnf install -y dotnet-sdk-7.0 && dnf clean all
RUN mkdir /HelloContainer/
WORKDIR /HelloContainer/
COPY . /HelloContainer/
RUN dotnet publish -c Release
ENV ASPNETCORE_URLS="http://0.0.0.0:8080"
CMD ["dotnet" , "bin/Release/net7.0/publish/HelloContainer.dll"]

This will start with a default Fedora Linux container, install .NET 7 in it, copy your source code into it and use the .NET in the container to build the application. Finally, it will set things up so that running the container runs your application and exposes it via port 8080.

You can build and run this container directly. However, if you are familiar with Dockerfiles, you might have noticed that it is quite inefficient. It will re-download all dependencies and re-build everything on any change to any source file. It produces a large container image at the end which even contains the full .NET SDK. An option is to use a multi-stage build to make it faster to iterate on the source code. You can also produce a smaller container at the end that contains just your application and .NET dependencies.

Overwrite the Dockerfile with this:

FROM registry.fedoraproject.org/fedora:37 as dotnet-sdk
RUN dnf install -y dotnet-sdk-7.0 && dnf clean all

FROM registry.fedoraproject.org/fedora:37 as aspnetcore-runtime
RUN dnf install -y aspnetcore-runtime-7.0 && dnf clean all

FROM dotnet-sdk as build-env
RUN mkdir /src
WORKDIR /src
COPY *.csproj .
RUN dotnet restore
COPY . .
RUN dotnet publish -c Release -o /publish

FROM aspnetcore-runtime as app
WORKDIR /publish
COPY --from=build-env /publish .
ENV ASPNETCORE_URLS="http://0.0.0.0:8080"
EXPOSE 8080
ENTRYPOINT ["dotnet", "HelloContainer.dll"]

Now install podman so you can build and run the Dockerfile:

sudo dnf install -y podman

Build the container image:

podman build -t hello-container .

Now, run the container we just built:

podman run -it -p 8080:8080 hello-container

A note about the arguments. The port is configured with the -p flag so that port 8080 from inside the container is available as port 8080 outside too. This allows you to connect to the application directly. The container is run interactively (-it) so you can see the output and any errors that come up. Running interactively is usually not needed when deploying an application to production.

Finally, connect to the container using a web browse. For example:

firefox http://localhost:8080

You should see a “Hello World” message.

Congratulations! You now have a .NET application running inside a Fedora container!

Conclusion

This was a whirlwind overview of .NET 7 in Fedora Linux and covers building and running an application using plain Fedora RPM packages as well as creating an application for a .NET application using only Fedora Linux.

If you have an interest in using or improving .NET on Fedora Linux, please join us!

Fedora Project community

30 Comments

  1. Özgür

    ms is confused what to follow nodejs or go or rust or anything else 🙂

    • hammerhead corvette

      I came here to say this very same statement !

  2. David Brownburg

    Great job!

  3. Jim

    “All telemetry is disabled in the Fedora builds of .NET.” Thank you, Fedora team.

  4. Brian Reading

    Great article. This is exactly the thing that a lot of enterprise developers can use to switch to Fedora Linux. In fact, I use this toolchain and a similar workflow to produce applications for my own organization. For a long time, an enterprise developer tasked with writing a C#/.NET application might use Windows at work, but go home to Linux. Now, it’s possible to stay where we’re comfortable and have the luxury of not only deploying from our preferred workstation OS, but also developing on it.

    A lot of people don’t know, but, for those pesky legacy projects still using the old .NET Framework, you can still remain in Fedora, and use the “Visual Studio Code Remote – SSH” extension to SSH into a Windows machine (yes, OpenSSH is now native and built-in to Windows). Of course this requires a Windows VM somewhere, but because it doesn’t need to be local, you could even have this somewhere on your corporate network. I never had luck using this with Active Directory domain account credentials, but setting-up a local user on that Windows VM allows you to work with this extension.

    I hope this info helps someone, and gets another enterprise developer out of the painful experience of doing work in Windows.

  5. Mr Leslie Satenstein

    Am I right to think that if I have a windows laptop/desktop at home, that from Fedora, using the dotnet addins, I can run the windows software on that laptop as if it is local to my Fedora system?
    If so, does it restrict me to have all the data files and files that I wish to create, to be only on that target .net partner?
    Does the dotnet interface make those foreign files accessible to me in read/write mode?

    • If the Windows software is a dotnet assembly that doesn’t happen to require any Windows-specific system calls, yes, dotnet was designed in the early days with portability in mind. Excerpted from “Assemblies in .NET“:

      In many cases, you can install a .NET-based application simply by copying its files to the target computer. For more information, see Assembly manifest.

      • Unfortunately, that’s not going to work with modern .NET (.NET Core or .NET 5 and later). The model of carrying around specific assembly files was mostly applicable to the Windows-only .NET Framework. Maybe Mono (which tries to emulate .NET Framework) could work?

    • No, .NET 7 isn’t really meant for that. It’s more for developers so they can build their applications so it works on both Windows and Linux (and macOS). It’s likely that an application that’s been built to only run on Windows and never tested on Linux will not work at all on Linux, even now that we have .NET 7.

      If you goal is to take an existing Windows graphical application and run it on Fedora, I think there are better alternatives than .NET.

      For applications, consider looking into Wine, which is a project designed to take Windows applications and run them on Linux: https://wiki.winehq.org/Wine_User%27s_Guide#What_is_Wine.3F

      For games designed for Windows, consider using Proton: https://fedoramagazine.org/play-windows-games-steam-play-proton/

      If you want to share data, Fedora should be able to read/write to Windows disks if it’s the same machine (with some caveats, I think). If it’s another computer, look into sharing files: https://fedoramagazine.org/files-connect-to-a-windows-file-share/

      • Marc

        Well, then the last three years of my professional carreer was a lie?

        Of course you can mix Windows and Linux between development and production environments using dotnet (not .NET Framework <=4.8). You have to understand what .Net Standard is and you have to get a feeling for its limitations (that boil down to GDI+ and related stuff like Windows Forms and WPF), but when you are doing web stuff you probably wont even notice a difference

        • You are right, of course. I read the original question as coming from an end-user (not a developer) and focusing on Windows GUI applications. Like you say, for command line applications and web stuff, specially stuff that’s being actively developed (and not a version from a 5-year old application), .NET on Linux works really well. I do all my development on Fedora. I don’t even have a Windows machine for .NET 🙂

    • Marc

      You have to understand the difference between
      – .net Framework (1.0 – 4.8) that came out 2001 (or so) and is still maintained but under a proprietary license and strictly windows and x86/AMD64 only.
      – “dotnet core” (1.0 – 3.1), later on only “.net” 5.0-7.0: open source under MIT license, designed to run under different architectures and operating systems

      dotnet core/.net 5 recently gained more compatibility with the “old” framework, so that you can more easily port an old application to .net 5+, but be aware that everything that touches windows-only stuff won’t work on Linux and macOS (mostly GUI applications, but also stuff like e.g. the windows registry)

  6. Erling Jacobsen

    It is not clear if this can run Windows GUI programs developed on Windows

    • I referred to it in the article here but not in enough detail, I think:

      Windows-specific application types, such as GUI Windows applications, are not available

      The GUI libraries needed to run Windows GUI applications targeting modern .NET (.NET 7, .NET 6, .NET 5 or .NET Core) are both Windows-specific and also proprietary. So if you have a .NET GUI application that works on Windows, it wont work on Fedora Linux.

      Worse, most Windows GUI applications are probably targeting .NET Framework. Unlike modern .NET, NET Framework is entirely proprietary and Windows-only. So even non-GUI, command line .NET Framework applications will not work on Linux.

      It’s possible to port modern .NET applications to an open source cross-platform .NET UI like Avalonia (see https://avaloniaui.net/). But that’s a manual step the application developers need to take.

      Another option that might be worth exploring be Mono. Mono is supposed to be somewhat compatible with .NET Framwork applications, but I don’t know if that has been a focus of the project since Microsoft acquired the primary developers of Mono. Maybe reach out to https://fedoraproject.org/wiki/SIGs/Mono ?

      • Erkki Ruohtula

        This unfortunately makes it not too useful. Just about every useful Windows C# program one might want to port has a GUI. For making cross-platform non-GUI applications there are plenty of non-proprietary languages one can use, and in my opinion should use, instead of Microsoft-controlled C#.

    • Dave

      It cannot.

  7. Drew K.

    Thank you for this article. It is timely as I have Fedora installed on my laptop and need to get back into ASP.NET programming for work.

    Work is primarily a Microsoft shop; except the LAMP stack websites I have been working in. Now with management changes, the ASP.NET Intranet may finally get some updated love it desperately needs.

  8. Ilia

    By the way, it is very easy to run Android Xamarin app under .net 6 or .net 7 under Fedora.

    All what you need – is to install android workload and several environment variables

  9. serdar

    can we use dotnet core sdk version 3.1 on fedora? if we can, how can install dotnet core sdk 3.1? or only dotnet 7 and 6 usable?

    • Yes, .NET Core 3.1 is available, but only until Fedora 36. You can install it using

      dnf install dotnet-sdk-3.1

      on Fedora 36.

      .NET Core 3.1 has been a part of Fedora since Fedora 32. You can see our announcement for that in the Fedora 32 Release Notes at https://docs.fedoraproject.org/en-US/fedora/f32/release-notes/developers/Development_Dotnet/

      However, I don’t recommend using .NET Core 3.1 anymore.

      .NET Core 3.1 reached it’s end of life in December 2022: https://dotnet.microsoft.com/en-us/platform/support/policy/dotnet-core#lifecycle. Upstream is no longer maintaining it. That means .NET Core 3.1 is no longer receiving any security or bug fixes. New security issues in .NET are identified and fixed around every month or so, and those fixes aren’t being done in 3.1 anymore.

      To discourage users from using the vulnerable version of .NET Core 3.1, we finally removed it in Fedora 37.

      If you want to stay up to date with all the security and other bug fixes, I suggest upgrading to .NET 6 or 7, both of which are available in Fedora 36 and 37.

      • serdar

        understood, why I am asking for dotnet sdk 3.1 is because I have to work with it for a while, but as you said I will move to other versions which are being updated. I took a look at the docs that you post and page of f36, it says: “Upstream .NET maintainers declared that .NET 5 has reached its End of Life on May 10, 2022. Accordingly, Fedora 36 does not include a .NET 5 SDK or Runtime. Fedora 36 still includes .NET Core 3.1 and .NET 6.0, though.”
        accordingly, I have one more question about fedora that supports dotnet 3.1, is all version of fedora 36 supports dotnet 3.1 or is there any specific version for my case?
        by the way sorry for my questions if improper, but I am newby in the linux world. thank you for your answer in advance.

        • Marc

          Older runtimes can be targeted with newer SDKs. So you can perfectly build an app targeting netcoreapp3.1 using the SDK 6.0 or 7.0. You’ll need the runtime installed, though. If it disappeared from the official package sources, you can just download the needed runtime from Microsoft at https://dotnet.microsoft.com/en-us/download/dotnet/3.1 and unpack the tar.gz into /usr/lib64/dotnet/shared/Microsoft.NETCore.App/3.1.xx

          • I would recommend against this. Mixing and matching SDKs and Runtimes from different builds and different OS’s is likely to lead to subtle bugs that no one can help you resolve.

            If you really want to use .NET Core 3.1, I would suggest going all-in on the Microsoft download. Or consider using an environment – like a container – that lets you install .NET Core 3.1 even if your primary OS is Fedora 37.

        • Generally, a term like “Fedora 36” roughly means “Fedora 36 as it was released, along with all other package updates that have since been released for it”. In other words, you install Fedora 36 and then do something like a dnf upgrade to get the latest version of Fedora 36. There aren’t any sub-versions or patch versions, per-se. Just plain Fedora.

          And yes, a recent-ish version of .NET Core 3.1 is available in the Fedora 36 you can use today.

          • Sorry, slight clarification: You can mix and match different SDK and Runtime versions. Like you say, using 6.0 SDK to target 3.1 should work just fine. I was recommending against mixing SDKs/Runtimes produced by different OS’s and/or builders. So please feel free to use 6.0 SDK and 3.1 Runtime from one vendor (eg, Fedora 36), but don’t mix Fedora 36 with Fedora 37, or Microsoft’s build with Fedora 37’s. There are some subtle behavior differences that can crop up and bite you in the most unexpected ways.

  10. This is really a grat thing.

  11. Max

    Better to keep away from all MS stuff to not to regret later.

  12. Anon Amous the 3rd.

    When some people are messing with vbasic, others are coding in rust! The pop os desktop called Cosmic that is coded in rust is coming soon. The next linux kernel will be made with RUST. In a world where windows has been winning since about 1970, rust is more of a thing than net7. Besides, there is lots of talk that net 8 is going to be coded in LUA, and net9 will be coded in pure css.

Comments are Closed

The opinions expressed on this website are those of each author, not of the author's employer or of Red Hat. Fedora Magazine aspires to publish all content under a Creative Commons license but may not be able to do so in all cases. You are responsible for ensuring that you have the necessary permission to reuse any work on this site. The Fedora logo is a trademark of Red Hat, Inc. Terms and Conditions