Well, I know most of you are wondering that whether you could do C# programming in Linux or ubuntu( well it’s a Linux OS which is more popular after all ). Yes! you can.
After all Microsoft love Open source development. Yes, they really do and they encourage you to do so. The VS code we talked about in the last article is a clear
evidence for that. isn’t it? So today we are going to get started with C# programming in Linux platform. For this article, I will be using Linux mint. Which is my
favorite distro. But you can do the same for a ubuntu system as well. Becuase there is not much difference at all. And we will be using VS code, that would be the
most perfect guy for the job.
Let’s get started. First, we have to download and install the .net Core to our system. Let’s get started with that. Just head to this link(https://www.microsoft.com/net/core)
Now you can see that you have a lot of options here. So let’s select Linux first and then Ubuntu/Mint. And there are all the instructions you need to get started with. And you should be careful to select the correct platform you are using. If you’ve run into any trouble while you are following this article you are more than welcome to mention it in the comment so we could help you out.
Okay after following the instructions on the page. You could just check whether you have installed it correctly by running the “dotnet new” command in a terminal. This will create a new dotnet project.
Now we can run our test project by executing “dotnet restore” and “dotnet run” commands. Is that all? yeah! it’s that simple. But it’s not all. You are welcome to explore the world of dotnet. If you are not exposed to it yet. Now it’s time to give it a shot.
Now, what about VS code? yeah, we haven’t forgotten this nice guy. Let’s use him to make our life easier. Today we are not going to talk about topics like debugging etc. But we would write a small program in C# with VS Code. We would come to parts like debugging in future articles.
If you haven’t installed VS code yet, Now it’s time to welcome him home. I discussed how to install it in windows in the last article. It’s pretty much straightforward on Linux too. If you are still on the .net core page you could see at the bottom they are suggesting you use VS code itself. So just click on it if you haven’t installed it yet.
Okay select the package and download it. You can hand over the rest to your package manager.
Hope you have installed it correctly into your system. Now let’s open up a terminal and head back to where we created the dotnet project. And execute “dotnet restore” command. Then “dotnet run” which will run your project.
Now you see there is a pre-made project for you. You can change this according to what you need. So let’s make few changes just to get used to the tool. Let’s make a program which ask the user to enter a number and output the result by multiplying the input by 10. Pretty simple right?
Okay! now what? well, you can use the terminal you previously opened to run the project. But I wouldn’t. Because we have the integrated terminal with us. Just go to the menu View->integrated terminal. well, you could execute your commands here. Let’s try “dotnet run” and see what happens.
well, the program is okay. But we are missing something, aren’t we? Yes, we didn’t prompt any message for the user asking to input a value. Well, that’s not the subject of this article. But as a programmer, you should always follow the correct way. Well, you can just go ahead and change that. Hope you would be enjoying writing C# codes in Linux. Just don’t forget to comment below what you think.
Happy coding !!! see you in the next article.