Set up a .NET development environment

Photo reused from previous post C# Fundamentals: Hello World

Since the release of .NET Core, .NET developers are able to develop applications for and in GNU/Linux using languages like C#. If you are a .NET developer wanting to use Fedora Linux as your main workstation, this article is for you. I’ll demonstrate how to set up a full development environment for .NET on Fedora Linux, including an IDE/Text Editor, Azure Functions and an SSL certificate for a secure https site. There are multiple options for Text Editor and IDE, but here we cover Visual Studio Code and Rider. The last one is not free but it is a great option for those familiar with Visual Studio on Windows.

Install .NET SDK

Until recently the Microsoft repositories were required in the list of sources to be able to install dotnet through dnf. But that is no longer the case. Fedora has added the dotnet packages to their repositories, so installation is quite simple. Use the following two commands to install the latest dotnet (.NET 5 at the moment) and the previous (.NET Core 3.1), if you want it.

sudo dnf install dotnet 
sudo dnf install dotnet-sdk-3.1

That’s it! Easier than ever!

Install NodeJS

If you want to develop Azure Functions or use Azurite to emulate storage, you will need to have NodeJS installed. The best way to do this is to first install nvm to allow installation of NodeJS in user space. This means you may then install global packages without ever using sudo.

To install nvm, follow these instructions in order to have the latest version. As of today the latest version is 0.38. Check the github site in the instructions for the latest version.

sudo dnf install curl
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash

Once you have nvm installed, just run nvm install lts/* to install the latest LTS version of node or check here for more options.

Install a .NET IDE

Visual Studio Code

Check this guide in case something’s changed, but as of today the process to install Visual Studio Code is to import the Microsoft key, add the repository, and install the corresponding package.

sudo rpm --import https://packages.microsoft.com/keys/microsoft.asc
sudo sh -c 'echo -e "[code]\nname=Visual Studio Code\nbaseurl=https://packages.microsoft.com/yumrepos/vscode\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/vscode.repo'
sudo dnf check-update
sudo dnf install code

Now install the C# extension from Microsoft.

C# Extension

That’s pretty much it.

JetBrains Rider

JetBrains Toolbox

If you come from Visual Studio on Windows, this tool will feel more familiar to you. It’s not free, but you have 30 days to try it out and see if you like it or not before buying a license. You can check here for more information.

There are several ways to install Rider, but the easiest and cleanest way is to install the JetBrains Toolbox and let it manage the installation for you. To install it, navigate to this link and click on the Download button. Make sure that the .tar.gz option is selected.

If you feel more comfortable using the UI, then go to the directory where you downloaded the file using the file explorer of your Desktop Environment (nautilus, dolphin, etc.), right click on it and extract its content. Then go inside the extracted directory, right click on the jetbrains-toolbox file and click on Properties. Make sure that the Allow executing file as program checkbox under the Permissions tab is checked and close the Properties window. Now double click the jetbrains-toolbox file.

If you have trouble following that in your DE, or if you prefer using the console, open a terminal and navigate to the directory where you downloaded the file. Then extract the content of the file, navigate into the extracted directory, add execution permissions to the AppImage and execute it. The version numbers that I am using might differ from yours, so autocomplete with the TAB key instead of using copy-and-paste to avoid errors.

tar -xzvf jetbrains-toolbox-1.20.8352.tar.gz
cd jetbrains-toolbox-1.20.8352
chmod +x jetbrains-toolbox
./jetbrains-toolbox

It takes a few seconds or minutes, depending on your system and internet connection, until a small Toolbox window opens. After that you can delete the downloaded files. You will be able to open the JetBrains Toolbox from your app menu, the AppImage installs the application under ~/.local/share/JetBrains.

JetBrains Toolbox
JetBrains Toolbox

Rider

In the JetBrains Toolbox, search for the Rider app and click Install. If you want to change where it’s going to be installed and other options, check first the settings (top right corner).

When the installation finishes, open Rider. The first screen you’ll see is to opt-in in sending anonymous statistics to the JetBrains team. You can choose whatever you prefer there. The second one is to import your settings. If you’ve never used Rider before, click on Do not import settings and OK. After that, you’ll be prompted to choose a theme and keymap. Choose whatever feels more comfortable. Click next on every other screen until you reach the License window. If you have already bought a license, complete your JB Account or corresponding information. If you want to use the trial period, switch to Evaluate for free and click on Evaluate. Do the same for dotCover and dotTrace on the Plugins section on the left panel. Then click Continue.

That’s it! You now have Rider installed. You can change the options selected going to Configure -> Settings on the initial screen or File -> Settings on the editor.

Azure Functions and Azurite

To be able to develop Azure Functions you need to install the azurite node package. The azurite package allows you to emulate storage which is needed for some types of Azure Functions.

npm install -g azurite

You can read more about Azurite and how to use it here.

Visual Studio Code

To develop Azure Functions with VSCode, you need to also install the azure-functions-core-tools package. As of today, the latest version is v3. Check here to find the latest version and more information on how to use the tool. Run npm i -g azure-functions-core-tools@3 –unsafe-perm true if you want to install v3 or npm i -g azure-functions-core-tools@2 –unsafe-perm true if you want to install v2.

Then you just need to install the Azure Functions extension from Microsoft. Once the extension is installed, you can go to the Azure icon on the left panel and create a new Azure Function from the templates.

JetBrains Rider

On Rider, you first need to install the Azure Toolkit for Rider plugin. Once the plugin is installed, restart the IDE. Then go to Settings -> Tools -> Azure -> Functions. If you want to manage the azure-functions-core-tools by yourself manually, install the package like described in the Visual Studio Code section and then specify the Azure Functions Core Tools Path by hand. Otherwise, if you want Rider to handle updates and the package automatically, click on Download latest version… and make sure that the option Check updates for Azure Function Core tools on startup is checked.

Then navigate to Tools -> Azure -> Azurite and on the Azurite package path dropdown, select your installation of Azurite. It should look something like ~/.nvm/versions/node/v14.16.1/lib/node_modules/azurite.

Click Save and now you are ready to create Azure Functions. If you click New Solution you should see the Azure Functions templates on the menu.

Create a SSL Certificate for your .NET apps

You won’t be able to trust the .NET certificate generated by dotnet dev-certs https –trust. That command has no effect on Fedora Linux.

This article doesn’t cover the details for easy-rsa or the concepts for the SSL Certificate. If you are interested into learning more about this, please check these sources:

First, install the easy-rsa tool. Then create your own certificate authority (CA), set your system to trust it, sign your certificate and set .NET to use the certificate.

Start with the package install and set up the working directory.

sudo dnf install easy-rsa
cd ~
mkdir .easyrsa
chmod 700 .easyrsa
cd .easyrsa
cp -r /usr/share/easy-rsa/3/* ./
./easyrsa init-pki

Now, create a file called vars with the CA details. If you know what you are doing, feel free to change these values.

cat << EOF > vars
set_var EASYRSA_REQ_COUNTRY    "US"
set_var EASYRSA_REQ_PROVINCE   "Texas"
set_var EASYRSA_REQ_CITY       "Houston"
set_var EASYRSA_REQ_ORG        "Development"
set_var EASYRSA_REQ_EMAIL      "local@localhost.localdomain"
set_var EASYRSA_REQ_OU         "LocalDevelopment"
set_var EASYRSA_ALGO           "ec"
set_var EASYRSA_DIGEST         "sha512"
EOF

Now, build the CA and trust it. When you run the first command it will prompt for the CA name, you can just press enter to leave the default value.

./easyrsa build-ca nopass
sudo cp ./pki/ca.crt /etc/pki/ca-trust/source/anchors/easyrsaca.crt
sudo update-ca-trust

Next, create the request for our CA and sign it. After executing the last command, type yes and press enter.

mkdir req
cd req
openssl genrsa -out localhost.key
openssl req -new -key localhost.key -out localhost.req -subj /C=US/ST=Texas/L=Houston/O=Development/OU=LocalDevelopment/CN=localhost
cd ..
./easyrsa import-req ./req/localhost.req localhost
./easyrsa sign-req server localhost

Now, place all the needed files inside a common directory and create the pfx cert. After the final command you will be prompted for a password. Type anything you want. Be sure to remember your password and keep it secret.

cd ~
mkdir .certs
cp .easyrsa/pki/issued/localhost.crt .certs/localhost.crt
cp .easyrsa/req/localhost.key .certs/localhost.key
cd .certs
openssl pkcs12 -export -out localhost.pfx -inkey localhost.key -in localhost.crt

Finally, edit the ~/.bashrc file and add the following environment variables.

cat << EOF >> ~/.bashrc
# .NET
export ASPNETCORE_Kestrel__Certificates__Default__Password="PASSWORD"
export ASPNETCORE_Kestrel__Certificates__Default__Path="/home/YOUR_USERNAME/.certs/localhost.pfx"
EOF

Remember to replace PASSWORD for your actual password and YOUR_USERNAME for your actual username.

Reboot your system (there are other ways to do this, but rebooting is the easiest and fastest one). And that’s it! You can now develop using .NET with https on your Fedora Linux system!

For Developers

33 Comments

  1. GNOME Web should be a default browser.

    • teh404guy

      this comment is not related to the article
      also until gnome web gets web extensions support
      it wont be for a while

    • Frederik

      GNOME Web is buggy as hell and leaking memory all over the place. I love it, but it’s not ready for general use at all.

  2. The Fedora Magazine is drifting away from Freedom principle. It would be better if only free and open source software was proposed in this article. Like using VSCodium, Emacs, or Vim as IDE instead of the proprietary VSCode pulled from Microsoft repository and JetBrains + Rider.

    Also, while good and trusted DNF modules do exist in Fedora to install select version of Node, why does this article encourage bad practice of

    curl -o- https://random.site/install.sh | bash
    • Thank you for commenting, but I respectfully disagree.
      Fully open source tools like Emacs or Vim are incredibly awesome, but they are not beginner friendly. Specially to use as a full IDE. If you feel comfortable using them to that point, then chances are that you don’t need a guide on how to set up your environment so only fragments of this guide will be useful for you. Most .NET developers are used to Visual Studio, so offering a similar tool (like Rider) on GNU/Linux is a nice alternative. Regarding VSCode, a lot of .NET developers are already using it and it is nice to know that you can keep using the same tool if you switch to another OS.
      And as for using “curl -o- https://random.site/install.sh | bash”, it’s not from a random site. It’s from the official GitHub repo for nvm (link that I left on the guide) and you can easily check the content of the script. I also think it’s far worse practice to install packages globally using “sudo npm i -g some-package.”

      • What you day is true. There is no dening in this. But nonetheless, FOSS alternatives do exist and are on par with proprietary equivalent. For example, VSCode can be easily swapped with VSCodium for a 99.99% compatibility. There is also Monodevelop which is a great IDE.

        While downloading code from official nvm repository and piping it to bash can be safe in this particular instance it is generally a bad idea especially when we can use DNF modules instead.

        I must insist that we are here and use Fedora because we want FOSS.

        • You are right on VSCodium as a FOSS equivalent to VSCode (according to Microsoft the only difference is branding and telemetry), so if anyone is interested, here is the link and if you scroll down there are instructions to add the repo and install it using DNF: https://vscodium.com/

          I tried Monodevelop and it didn’t work for me, it crashed constantly.

          I don’t agree on using NodeJS from DNF if you are a developer. Usually managing different versions of node and npm is needed and that’s what nvm is for. Also installing packages globally with sudo it’s extremely dangerous. I am not trying to promote using curl and pipe to bash for everything, but in this case developers are safer using this method.

          My opinion is that there is nothing wrong in using non-FOSS. In this particular case, people coming from Visual Studio switching to Monodevelop are losing a lot of features that they might actually need. By switching to Rider they don’t lose anything. Some of us love Fedora and try to use FOSS where we can, but are also ok when that is not possible.

        • Ralf

          I don’t think that FOSS has anything to do with the collection of telemetry data.
          In Germany, for example, there had been some policy raids yesterday with the aim of combating child pornography. There are a lot of legal disputes right now and data is being logged everywhere.

          • Dragnucs

            Sure telemetry has nothing to do with FOSS, but licencjng does. There is this FOSS text editor in source code by Microsoft. WhenD packages it, it adds an icon, telemetry and publishes under a proprietary licence and calls the end product VSCode. There is an independent team that takes thebsame source code, adds a different icon, but publisjesbthe binary as FOSS still, and call the end product VSCodium.

            • Ralf

              That’s a problem that I wasn’t aware of in the time of writing. Thanks for your comment.

        • Marc

          The compatibility is way lower: the .net debugger can only be used when running the vscode package provided by Microsoft, it’s their licensing rule. I tried the FOSS option, but it will complain.

          You may only use the Microsoft .NET Core Debugger (vsdbg) with
          Visual Studio Code, Visual Studio or Visual Studio for Mac software

          to help you develop and test your applications.

          See also: https://github.com/dotnet/core/issues/505

          However, thanks for mentioning Rider. It is the best IDE I’ve ever worked with, and it feels so often just right. Also, when you are working with Android Studio or IntelliJ IDEA you’ll feel comfortable in a minute.

          And sssssh… I’ll tell you a secret: when enabling some plugins (typescript, angular, jsx) you’ll enjoy frontend development even more in Rider, forget about vscode. (and the urge to license webstorm)

      • Tom Woods

        May I just say, some of us work in organizations where there are certain standards we have to follow. I was very excited to see this article because I think it will mean I can stay on Fedora for an upcoming Azure function project. I try to do this whenever I can, and I keep a corporate compliant Windows VM around for the times when I can’t. Anything that keeps me from having to use that VM is progress for me. Thank you for putting this together, Federico.

  3. Ralf

    The article is very interesting! Certificates should be even more promoted, since I still receive a lot of unencrypted traffic or links to pages without certificate.

    Rider seems to be a cool solution/alternative.
    Thanks Frederico!

    • Thank you Ralf!
      I’m glad you enjoyed it! I agree with you, certificates are a must in almost every scenario.

  4. dragonbite

    This is great information.
    When I started with Linux I had the goal to do everything I do in Windows, but in Linux. Doing anything in .NET I didn’t think I had the technical experience to set it up and program in it. Now I may actually have a chance!
    I am not an expert even though it is my profession, and I’ve been tapped to work with our external LAMP sites but our Intranet is ASP.NET.

    • Hey! I’m glad that you find this useful!

      What you are saying is basically the reason why I wrote this article, so that people that is starting with Linux can set up the .NET development environment quickly and easily.

      Keep in mind that this will work perfectly with .NET Core, .NET 5 and most likely .NET 6 when it comes out, but it requires extra work and headaches for .NET Framework (and it usually ends in failure due to the strong dependencies that .NET Framework has to Windows).

      Thank you for your comment!

    • Ralf

      C# is a great language. Microsoft worked on .NET Core and it’s fantastic that you are independent of the underlying operating system. I think you need to use ASP.NET Core, which is much faster that .NET, is a kind of slim line version and works on both platforms.
      Vim is nice, but the learning curve is very steep and I don’t assume you want to spend your time with learning keybindings for two weeks? So please go ahead and use an IDE as suggested in the article. That’s at least my humble opinion, without being an professional developer.

    • steal3rd

      For the LAMP crowd interested in .NET, there is the very interesting Peachpie project that compiles PHP as a .NET Core executable.

      https://www.peachpie.io/

      It doesn’t transpile PHP to C#, it compiles PHP to an executable. For all intents and purposes the Peachpie project adds PHP as another .NET language. PHP code is available to conventional .NET code, and vice versa.

  5. Anonymous

    MonoDevelop is an awesome IDE for C#.

    I have been using it for years and it was always stable. I have used Visual Studio on Win too but MonoDevelop beats it in terms of simplicity of use. It has just enough and not too much.

    Don’t think there is a use for JetBrains there.

    • Thank you for commenting.
      First let me say that I am glad that MonoDevelop works for you and it’s all you need. I agree with you that it’s an awesome project, but for me it lacks features that I constantly use and Rider has. I think that JetBrains did an awesome IDE there. Is not FOSS, but people working on Visual Studio on Windows are used to some features that they are not always willing to sacrifice.

  6. Nathan Mourey

    Please in the future replace things like YOUR_USER_NAME_HERE with $HOME, it’s portable and promotes proper Unix/Linux thinking. Instead of hard coding path names and breaking future applications that get build by programmers that embed paths in programs instead of just getting an environment variable that will work on all *nix’s.

  7. Andreas

    Thanks for a great article! I’m a .Net developer by trade and this setup with Jetbrains Rider on Fedora Workstation is what I’m hoping to substitute my current Visual Studio + Resharper on Windows setup with any day now! 😉 There’re still those legacy .NET Framework projects to maintain though…

    • Thank you for commeting! I am glad that you find this helpful! 🙂 Those legacy .NET Framework are a headache

  8. Rhea

    Replying to: “Until recently the Microsoft repositories were required in the list of sources to be able to install dotnet through dnf.”

    That was NEVER true, the preferred source was our team’s copr repository before we packaged it in Fedora proper. Please do chat with the team before making articles about our work :/

    • Hi Rhea, thank you for commenting. I apologize if that wasn’t entirely accurate. This article is not about the work of your team tho, is about how to set up a .NET environment for development. I didn’t think that it was worth reaching out to anyone just because I am mentioning a package. However I will send a draft of future articles to avoid confusions like this.

    • Gena

      Hi Rhea, you and your team do not enough good work as not all versions of dotnet available in the Fedora repository, for example, .NET 2.1.

      • Hi Gena. Please don’t be disrepectful towards other. They are doing a lot of great work, if you need to install .NET Core 2.1 there is a lot of documentation on how to do it.

  9. juan

    Hi Federico.

    I still getting this error on chrome:

    NET::ERR_CERT_AUTHORITY_INVALID

    I’m using fedora 34 and dotnet 5

    • Hey Juan! As far as I know, Chrome uses a separate certificate storage than Fedora, so you will have to add your cert manually to Chrome. Right now .NET trusts your certificate but your browser doesn’t, so you should now be able to handle https calls with stuff like HttpClient, for example. And you can also work with Identity Server 4 without problems (I’m mentioning this because it was the major reason why I needed https setup on my system). If the browser warning is not an issue for you on the development environment, then you can just ignore it.

      • For those who have the same error (trusted system-wide, but not in Chrome):

        Visit chrome://settings/certificates
        Click on “Authorities”, then “Import”
        Select ~/.easyrsa/pki/ca.crt
        Visit chrome://restart or reboot the system
        Done!

  10. Some Ed

    I’ve seen a number of articles on how to do .NET programming in Linux. They all have approached it from the same perspective. “Here’s how to use this environment you’re familiar with on an OS you’ve just heard a lot about.”

    I first started using unix when I was in school in 1990. When I got my first computer, I immediately installed Slackware, noted that some hardware component I’d specifically chosen because it officially supported being used on Linux didn’t identify properly, so I downloaded the latest kernel which was then 1.2.8. Linux is not new to me. .NET, on the other hand, is. The various guides agree well enough on how to set up the basic environment that I’m pretty sure I’m good there. But the IDEs they all have me try all seem very foreign. I’m comfortable with vim, emacs is not as unfamiliar as these IDEs feel. The .NET documentation feels like a twisty, turny giant maze of large passages, mostly different.

    Is there a similar guide for people like me that I’ve missed? If not, could there be one?

    • Hey! Thank you for commenting. You are right, there is not a lot of guides that explain how to set up the full .NET environment for vim. I can’t write a full guide on the comments, and I haven’t had a lot of experience to do it anyways, but I know that it is completely possible. You need to use vim with scrooloose/nerdtree and OmniSharp/omnisharp-vim plugins. If you can manage to setup those plugins correctly and get familiar with the dotnet CLI you will have no problems. I know this is far from a guide, I’m just mentioning a couple of plugins for vim, but I hope this helps you. If I find the time to do the setup myself and work on it, I will create a guide and let you know 🙂

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