Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Setting up C# development environment in Linux

Recently I got curious in  .Net development on Linux environment.

I am aware of the Mono Project, but wanted to keep it as "pure" as it could be, meaning that I wanted to be, as much as possible, a Microsoft development environment.

I'm a long time Kubuntu user when it comes to Linux desktop, and I'm also a Visual Studio Code user for quite sometime.

 

.Net SDK

Starting with the basics, and already having VS Code installed, I started by installing .Net (Kubuntu is not mentions, just use Ubuntu as the reference) simply using 

sudo apt update
sudo apt install -y dotnet-sdk-7.0

That pretty much takes care of having .Net SDK installed.


VS Code IDE

Next step was to set up VS Code as the IDE.
This was achieved by installing the following VS Code extensions:

As a hint, pressing CTRL+SHIF+X on VS Code and searching for ms-dotnettools  on the extensions marketplace will list a lot of useful things.


Hello World

Once the basic was in place, it was time to try it out.
On a terminal, I typed the following commands to set up a Hello World console application:

mkdir HelloWorld
cd HelloWorld
dotnet new console

And a new console application was created printing "Hello, World!" into the terminal.
As a hint, type "dotnet help" for a list of available commands. Try also "dotnet new list" for a list of available templates.

Open the HelloWorld folder with VS Code, CTRL+K CTRL+O, and you can see generated code in the Program.cs file.

To build and run the application, just press CTRL+SHIFT+D and you'll be on the Run and Debug menu options. Having the ".Net Core Launch (console)" option selected and using "Start Debugging (F5)" will bring up the Debug Console and you'll be able to see the application execution.


Bonus | Desktop and Game Development

Don't get disappointed because it is not possible to develop desktop applications using Forms in Linux using C#.
It is possible to develop cross-platform games for desktop, or other kind of graphical applications, using SDL2 and OpenGL.
For that, and as Microsoft refers, it is possible to use MonoGame, just check the DesktopGL, template mgdesktopgl.
Keep in mind that packaging  and distribution is available, start coding and have fun.

To package and distribute, you can .

./M6

How to setup VSCode launch.json for Xdebug version 2

I had to make some maintenance on a web application using Yii 1.1.4 framework running on PHP 7 and for that, I set up an Ububtu 18.04 LTS Desktop on a virtual machine. 

After the usual bunch of "apt-get install" commands and a few configurations, I got the new development environment up and running having Visual Studio Code as my IDE.

But, almost as soon as I got it running, I got the need to step debug it. For that, I went to Xdebug, I installed it via "apt-get" and configured it, but it was not working as expected.
I check the configuration parameters and give it another try. No go. Xdebug was installed, PHP was recognizing it on both cli and web, but it was still not working.
After a few seconds, I spotted the issue: it was a Xdebug version 2!

A lot has changed between version 2 and 3 of Xdebug.

The thing was that I wanted to keep version 2, and for that I had to configure "launch.json" file and Xdebug in the appropriate way.

On PHP configuration file:

zend_extension=xdebug.so
xdebug.idekey=XDEBUG_VC
xdebug.remote_port=9003
xdebug.remote_enable = 1
xdebug.remote_autostart = 1
 
And on "launch.json":

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
       
        {
            "name": "Listen for Xdebug",
            "type": "php",
            "request": "launch",
            "port": 9003
        },
        {
            "name": "Launch currently open script",
            "type": "php",
            "request": "launch",
            "program": "${file}",
            "cwd": "${fileDirname}",
            "port": 0,
            "runtimeArgs": [
                "-dxdebug.remote_autostart=yes"
            ],
            "env": {
                "XDEBUG_MODE": "debug,develop",
                "XDEBUG_CONFIG": "client_port=${port}"
            }
        },
        {
            "name": "Launch Built-in web server",
            "type": "php",
            "request": "launch",
            "runtimeArgs": [
                "-dxdebug.mode=debug",
                "-dxdebug.remote_autostart=yes",
                "-S",
                "localhost:0"
            ],
            "program": "",
            "cwd": "${workspaceRoot}",
            "port": 9003,
            "serverReadyAction": {
                "pattern": "Development Server \\(http://localhost:([0-9]+)\\) started",
                "uriFormat": "http://localhost:%s",
                "action": "openExternally"
            }
        }
    ]
}

The default port is 9000, but I'm used to have Xdebug on 9003, so I reconfigured it. The remaining parameters are, basically, the version 2 way of activation the debugger on a request.

./M6

Linux Self-Extracting Script

While developing a web application - certified for Linux only - I wanted an easy way to deploy it.
The classical RPM (good guide) and DEB (simple guide) packages were an option and, as I write this, the DEB package is actually finished but the RPM is considerable more complex and I'm still not convinced that it is worth the work for what is required, though, it may not be included in the final version.

Since I do not wish to create nor maintain lots of distribution packages, the obvious choice was to have an installation package that could be executed in any Linux distribution.

In the past, around 2003 or so, I've already had a similar problem and the solution back then was to use a self extracting archive. After some research, I found out an easy and simple way to do it.
Here's a detailed explanation on how things can be done: Bash Self-Extracting Script.
If you wish for a faster solution, you can check this Self-extracting Shell Script.

./M6

Ant not working in Ubuntu/Kubuntu 20.04 LTS

After a clean installation of a Kubuntu 29.04 LTS, Ant was not working properly. A simple ant -version came out as

/bin/ant: 1: cd: can't cd to /bin/../share/ant/bin/..
Error: Could not find or load main class org.apache.tools.ant.launch.Launcher
Caused by: java.lang.ClassNotFoundException: org.apache.tools.ant.launch.Launcher

One may think the problem resides in the ANT_HOME not being set, but actually the problem is that Ant is not pointing to the correct location.

The solution was quite simple, the incorrect symbolic link was removed and a new one was created pointing it to the correct location:

sudo rm -rf /bin/ant
sudo ln -s /usr/share/ant/bin/ant /bin/ant

Please note that this solution worked for me, check if it works for you to before making any system changes.

./M6

How to Resize a VirtualBox Disk

While working with VirtualBox I made the mistake of underestimate the disk space I would require for the usage of Kubuntu 16.04. Not the operation system itself, but the additional application I actually would need.

That forced me to increase the disk space, a task that resulted in a lot of work that initially expected.

I followed the Derek Molly tutorial "Resize a VirtualBox guest Linux VDI Disk under Windows Host" with some differences due to the problems I faced.
I was unable to not use the recommended gParted, so I ended up trying a similar solution.

I used System Rescue CD, that includes lots of system tools, in an obvious rescue bundle, including gParted. Booting the CD image was not a problem and I got a shell. I typed "startx" to load the window manager and quickly found gParted. From that point on, the tutorial was back on track and I was able to increase the disk space.

System Rescue CD is a great tool and I totally recommend it. I just needed to use gParted for this problem, but it comes with lots of software that can be a life saver.

./M6

Video Conversionn with ffmpeg

While searching for how to convert a2v video into a mov, I found everything that one wanted to know about ffmpeg but was afraid to ask explained in a simple way in here: this forum answer.

In short, just do

ffmpeg -format
to list all formats. Then use this simple command to convert between video formats:
ffmpeg -i {input_video_file} -f {format} {ouput_video_file}
In my case, my command was:
ffmpeg -i Passadeiras\ Ativas.m2v -an -f mov teste.mov
since I was converting to a mov file and stripping the sound.

./M6

Upgrade PostgreSQL from 9.1 to 9.3 on Kubuntu

The following article show how to upgrade PostgreSQL from version 9.1 to version 9.3 in Kubuntu.
This will also work in Ubuntu and it can also be applied to upgrade between any version of PostgreSQL.

Here's how to Upgrade PostgreSQL from 9.1 to 9.3 on Kubuntu.

./M6

PostgreSQL on Kubuntu

As I needed to install PostgreSQL on Kubuntu, I find these three tutorials particularly helpful:
I recommend reading them all before actually installing it. They overlap in some parts but do complement each other.

./M6

Setting Up Django Applicatications in Production

Setting up a Django application in a production environment is not as straight forward as one usually is used to. Currently, there are two ways to deploy a Django application:
  1. Deploying on our own server, using WSGI.
  2. Deploying on a shared hosting environment, using FastCGI, SCGI, or AJP.
Django’s primary deployment platform is WSGI, the Python standard for web servers and applications, which requires Apache and mod_wsgi.

But when it comes to deploy, Django official documentation seems superseded by the Linode Library Deploy Python/Django Applications with Apache and mod_wsgi tutorials, an easy to follow step-by-step tutorial, available for several distros.

./M6

Fetching Lines From Big Files

Today I had a DB2 bulk loading problem. I got a couple of rejected records on a 2G+ file. These kind of files are too big to be manipulated with conventional text editors, and even text editors that can handle such files are, usually, not very fast.
Since I was in Windows, I've open th MSYS shell, changed into the correct directory and typed
cat -n STPRRIMH.S.ULD.U110115.UN | grep 1943664 > MH.txt
This is an instantiation of a more generic command
cat -n < file > | grep < line >
In a few seconds I had a new file containing exactly the information I needed.

Serious developers can't really live without Unix/Linux tools on their machines...

./M6

List of Free and Open Source Software Packages

I was searching for a Linux application server when I came across with this useful
list of free and open source software packages.

It's a great starting point when one knows what one needs but doesn't really have a reference.

./M6

ATI Mobility Radeon X700 on openSUSE

As I've previously posted, I'm now using openSUSE and my ATI Mobility Radeon X700 was not fully functional.

After some investigation, I've found out that AMD no longer supports old ATI video cards for Linux.
I've even tried http://wiki.opensuse.org/SDB:ATI_drivers but with no luck.

Definitely this is one extra point for nVidia. When I replace my current laptop, it will have an nVidia card, that's for sure.

./M6

Recovering from a bad Hard Disk Crash

Last time I've used my computer I burned a DVD Video with K3B and shutdown openSUSE as usual.

Yesterday, when I turned the computer on, it went directly into GRUB shell which allowed me to execute some commands with no real use to me.

Obviously something was wrong, and I though that it was the Master Boot Record (MBR) that got corrupted, as I've already have experienced before.
So I got the openSUSE installation disk and boot with it in order to fix the problem. I've requested the fix option from the menu but then something weird happened.
When scanning the hard disk, it displayed a message that there was something wrong and I would not be able to edit the disk partitions. I checked the partitions and the information seems to show that everything was OK.
I needed something else to see what was wrong with the hard disk and to fix it.

I grabbed an old Knoppix CD, version 3.3, the only one that I know that loads correctly on my Acer laptop (by the way, don't by an Accer if you wish to have Linux on a laptop), and checked the disks. This is not the first time I use Knoppix to save a system, it's actually one of my companion disks.
Knoppix automatically mounted both windows partitions correctly but the Linux EXT4 and Swap partitions were missing.
Now I start to get worried...

I got into a shell and checked the partitions with fdisk.
I detected the problem immediately: I had two partitions starting at the same cylinder! I even recall its number, 2086.
The second partition had an Id of f, which is awkward since the Id is a numeric value, and was marked as the boot partition. Using fdisk to see what my chances were of correcting this I realized that a drastic solution would probably be the only solution. When I deleted that second weird partition, the following partitions were gone to.

So, before I do something that I could regret latter, I checked the content of the Windows partitions to find out that if anything would go wrong I already had a backup of everything.
The data on the Linux partition seemed already lost, so I would have to settle for the backups.
On the other hand, I was still able to save everything from the Windows partitions, but that would be unecessary.

I finally decided what to do and how to do it.
I've deleted that second weird partition, defined the first partition as boot and saved the partition table.
I could have tried to recreate the partition table with fdisk, but since I had backups of everything, I just went for the full disaster scenario.

I then rebooted with the openSUSE installation disk, created a second partition, that I reserved to replace the lost second partition for Windows, and created a third one for Linux, where I installed openSUSE.

When openSUSE installation finished I've reboot and started Windows, which loaded just fine from the saved first partition. When Windows loaded, it was time to format that previous reserved second partition as NTFS.

The whole thing took me a couple of hours but I got both Windows and openSUSE up and running again. Today I'll restore the backups, which will probably take a couple hours more.

Moral of the story:
  1. Always have a Knoppix disk at hand.
  2. Backups are a tech best friend.

./M6

openSUSE

I've just moved from Kubuntu to openSUSE.
The reason is simple, Kububtu 9.10 revealed too unstable for me. In just a couple of months I had to reinstall once and when troubles reappear for the second time, I talked with a friend and decided to give a try to openSUSE.

So far, so good. It's a lot more stable and my hardware seems to be better supported, even my ATI Mobility Radeon X700 that always gave me headaches in Linux works fine. Unfortunately the 3D support seems not be be fully working, but that is not a issue, at least for now.

I kept KDE as my window manager, it suits better my needs. The first look and feel at it was very pleasant. Even the desktop wallpaper is very good.
One of the first things I've learn was to add the Packman repository, since the default official repositories does not have some software for "some legal uncertainties". For instance, it does not have the mpeg2enc from mjpegtools, one has to remove the mjpegtools, add the Packman repository and add the mjpegtools again in order to have the Packman mjpegtools package installed, which does have the mpeg2enc.
Other great software, like 'Q' DVD-Author and DeVeDe, also comes from the Packman repository, so it is critical to include it.

Some things are different, specially when it comes to the administration part. Maybe it is because openSUSE has so much affinity with SUSE servers, it has a lot of easy administration tools right out-of-the-box.
But some things seem the same. The Network Manager still sucks. Why is it so hard to use, specially when its flag is "Pain-Free Networking"? Since Network Manager appeared, all it gave me was problems. In Kubuntu it simply did not connect via wifi, and now I can't enable it, even after I defined it to be my network manager and enabled it!...

Anyway, everything seems to work just fine and I'll keep openSUSE for a while, specially because it seems very stable.

./M6