Running VS Code on Linux

Curtsy/ Original post: https://code.visualstudio.com/docs/setup/linux

Running VS Code on Linux

Installation

  1. Download Visual Studio Code for your distribution, .deb for Debian-based distributions such as Ubuntu or .rpm for Red Hat-based distributions such as Fedora or CentOS. Note that 32-bit binaries are also available on the download page.
  2. Install the package through a GUI package manager by double clicking on the package file, or through the command line:
 # For .deb
 sudo dpkg -i <file>.deb
 # install dependencies
 sudo apt-get install -f

 # For .rpm (Fedora 21 and below)
 sudo yum install <file>.rpm

 # For .rpm (Fedora 22 and above)
 sudo dnf install <file>.rpm
  1. VS Code should now be available to run through the launcher or the command line by running code.

Tip: Run code . in any folder to start editing files in that folder.

Note:

Visual Studio is tightly integrated with Windows and Developing a .NET application using any language (C# or VB) takes more than just having Wine, and since Wine is not capable enough to provide complete development runtime as .NET in Linux.

If you want to develop software specifically in C#, on Linux, you can use MonoDevelop

Since, you’re asking for Visual Studio 2010 (.NET 4.0), with MonoDevelop, you’ll not be able to develop an app that particularly uses .NET 4, as of now MonoDevelop is in version 3.0.2 (somewhat equivalent to .NET 3.0).

You can still use Windows virtually within Ubuntu, using VirtualBox. And then install Visual Studio there, but still a serious app development is not recommended to be done in Virtualized environment.

Download Visual Studio Code

https://code.visualstudio.com/download

http://www.monodevelop.com/download/

 

Running ASP.NET vNext on CentOS 7

Original post/ Curtsy: http://trydis.github.io/2015/01/06/running-aspvnext-centos7/

Running ASP.NET vNext on CentOS 7

For reference, here are the versions I used:

Mono: 3.10.0
KVM: Build 10017
KRE: 1.0.0-beta1
libuv: commit 3fd823ac60b04eb9cc90e9a5832d27e13f417f78

I created a new VM in Azure and used the image provided by OpenLogic. It contains an installation of the Basic Server packages.

Install Mono

Add the Mono Project GPG signing key:

$ sudo rpm --import "http://keyserver.ubuntu.com/pks/lookup?op=get&search=0x3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF"

Install yum utilities:

$ sudo yum install yum-utils

Add the Mono package repository:

$ sudo yum-config-manager --add-repo http://download.mono-project.com/repo/centos/

Install the mono-complete package:

$ sudo yum install mono-complete

Mono on Linux by default doesn’t trust any SSL certificates so you’ll get errors when accessing HTTPS resources. To import Mozilla’s list of trusted certificates and fix those errors, you need to run:

$ mozroots --import --sync

Install KVM

$ curl -sSL https://raw.githubusercontent.com/aspnet/Home/master/kvminstall.sh | sh && source ~/.kre/kvm/kvm.sh

Install the K Runtime Environment (KRE)

$ kvm upgrade

Running the samples

Install Git:

$ sudo yum install git

Clone the Home repository:

$ git clone https://github.com/aspnet/Home.git
$ cd Home/samples

Change directory to the folder of the sample you want to run.

ConsoleApp

Restore packages:

$ kpm restore

Run it:

$ k run
Hello World

That was easy!

HelloMvc

Restore packages:

$ kpm restore

Run it:

$ k kestrel
System.DllNotFoundException: libdl
(Removed big stack trace)

Ouch, so I went hunting for libdl:

$ sudo find / -name libdl*
/usr/lib64/libdl.so.2
/usr/lib64/libdl-2.17.so

Create symbolic link:

$ sudo ln -s /usr/lib64/libdl.so.2 /usr/lib64/libdl

Run it again:

$ k kestrel
System.NullReferenceException: Object reference not set to an instance of an object
  at Microsoft.AspNet.Server.Kestrel.Networking.Libuv.loop_size () [0x00000] in <filename unknown>:0
  at Microsoft.AspNet.Server.Kestrel.Networking.UvLoopHandle.Init (Microsoft.AspNet.Server.Kestrel.Networking.Libuv uv) [0x00000] in <filename unknown>:0
  at Microsoft.AspNet.Server.Kestrel.KestrelThread.ThreadStart (System.Object parameter) [0x00000] in <filename unknown>:0

Progress, but now we need to get libuv working.

Install libuv

$ sudo yum install gcc
$ sudo yum install automake
$ sudo yum install libtool
$ git clone https://github.com/libuv/libuv.git
$ cd libuv
$ sh autogen.sh
$ ./configure
$ make
$ make check
$ sudo make install

Run it again:

$ k kestrel
System.NullReferenceException: Object reference not set to an instance of an object
  at Microsoft.AspNet.Server.Kestrel.Networking.Libuv.loop_size () [0x00000] in <filename unknown>:0
  at Microsoft.AspNet.Server.Kestrel.Networking.UvLoopHandle.Init (Microsoft.AspNet.Server.Kestrel.Networking.Libuv uv) [0x00000] in <filename unknown>:0
  at Microsoft.AspNet.Server.Kestrel.KestrelThread.ThreadStart (System.Object parameter) [0x00000] in <filename unknown>:0

I knew it had to be a path issue or something, so I went hunting for libuv:

$ sudo find / -name libuv.so
/home/trydis/libuv/.libs/libuv.so
/usr/local/lib/libuv.so

I then checked the library name Kestrel was looking for on Linux here and based on that i created a symbolic link:

$ sudo ln -s /usr/local/lib/libuv.so /usr/lib64/libuv.so.1

Run it again:

$ k kestrel
Started

Navigate to http://your-web-server-address:5004/ and pat yourself on the back!

HelloWeb

Restore packages:

$ kpm restore

Run it:

$ k kestrel
Started

Navigate to http://your-web-server-address:5004/.

 

Mono Project

http://www.mono-project.com/docs/web/aspnet/

ASP.NET

Mono has an implementation of ASP.NET 2.0, ASP.NET MVC and ASP.NET AJAX.

Quick Resources:

Mono’s ASP.NET implementations supports two kinds of applications:

  • Web Forms (Web Applications infrastructure).
  • Web Services (the SOAP-based RPC system).

Status and tests for ASP.NET 2.0 are available in our ASPTests page.

Running ASP.NET applications

To run your ASP.NET applications with Mono, you have three classes of options:

  • Apache hosting: use mod_mono, a module that allows Apache to serve ASP.NET applications.
  • FastCGI hosting: use the FastCGI hosting if you have a web server that supports the FastCGI protocol (for example Nginx) for extending the server. You also may use a web server that only has support for CGI using cgi-fcgi.
  • XSP: this is a simple way to get started, a lightweight and simple webserver written in C#.

For deploying applications, we recommend the use of the mod_mono or FastCGI approaches, as that will give you all the configuration options and flexibility that come with using Apache or a FastCGI server.

For quickly getting started, get familiar with Mono and ASP.NET, XSP is the ideal solution. Keep in mind that XSP is a very limited server and is only useful to get acquainted with ASP.NET and Mono, it only support HTTP 1.0 and does not provide much extensibility or configuration.

More advaned users can use the HttpListener and the ASP.NET hosting to create their own hosts for ASP.NET applications.

ASP.NET hosting with Apache

The mod_mono Apache module is used to run ASP.NET applications within the Apache web server.

The mod_mono module runs within an Apache process and passes all the requests to ASP.NET applications to an external Mono process that actually hosts your ASP.NET applications. The external ASP.NET host is called “mod-mono-server” and is part of the XSP module.

To use this, you must download and install the mod_mono and xsp components of Mono. mod_mono contains the actual Apache module, and xsp contains the actual ASP.NET hosting engine, both are available from our download page.

See the mod_mono page for details on installation and configuration.

ASP.NET hosting with Nginx

Nginx is a high-performance HTTP server which support running ASP.NET and ASP.NET MVC web applications through FastCGI protocol. See the FastCGI Nginx page for details on installation and configuration.

ASP.NET hosting with XSP

XSP is a standalone web server written in C# that can be used to run your ASP.NET applications with minimal effort. XSP works under both the Mono and Microsoft runtimes. The code is available from our download page (look for XSP web server) or from the git repository (module name: xsp).

The easiest way to start XSP is to run it from within the root directory of your application. It will serve requests on port 8080. Place additional assemblies in the bin directory. Other XSP options can be set on the command line, such as the application directory and the port to listen on.

XSP comes with a set of pages, controls and web services that you can use to test the server and see what ASP.NET looks like.

For example, once you install XSP, you can try some samples like this:

 $ cd /usr/lib/xsp/test
 $ xsp
 Listening on port: 8080
 Listening on address: 0.0.0.0
 Root directory: /home/cvs/mcs/class/corlib/Microsoft.Win32
 Hit Return to stop the server.

You can now browse to http://localhost:8080 and see various sample programs

SSL support in XSP

XSP supports SSL and TLS Client Certificates. For further details about setting it up, see the UsingClientCertificatesWithXSP document.

Configuration

Applications can be configured through the web.config file, the full documentation is available from MSDN, and also a Mono-specific version is available on this site here.

Additionally, you can configure Mono-specific ASP.NET settings (to have applications that behave differently depending on the operating system they are deployed in) using the ASP.NET Settings Mapping engine.

Other extensions

Check out ASP.NET Modules for details on how to support deflate/gzip encodings and authentication.

Debugging

By default xsp and xsp2 run in Release mode, which means that debugging line-number information will not be available in stack traces when errors occur.

To obtain line numbers in stack traces you need to do two things:

  1. Enable Debug code generation in your page. 2. Run Mono with the –debug command line option.

You must enable debug code generation in your page using the Debug=”true” in the top of your page, or setting the compilation flag in Web.config (compilation option).

Use the –debug command line option to Mono, this is done by setting the MONO_OPTIONS environment variable, like this:

$ MONO_OPTIONS=--debug xsp2
Listening on port: 8080 (non-secure)
Listening on address: 0.0.0.0
Root directory: /tmp/us
Hit Return to stop the server.

To do the same with the Apache mod_mono module, use the MonoDebug true directive in your apache configuration file.

Supported Versions

Mono supports ASP.NET 2.0, ASP.NET AJAX and a handful of 3.5 controls.

Limitations

Mono’s ASP.NET does not implement the following features:

  • Precompiled updatable web sites.
  • WebParts APIs.

Work in Progress

git access

Users interested in the latest version of mod_mono and xsp can retrieve these from our public git repository. The module names are mod_mono and xsp respectively. You will also need to check out the mcs module as the System.Web classes are in mcs/class/System.Web.

Designer

There is work in progress on an ASP.NET Designer the designer will eventually be integrated into the MonoDevelop IDE.

SQL Server Image Resize and Formate/ Type Conversion

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Drawing;
using System.Configuration;

namespace ug_admission
{
public partial class ResizeConvertImage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
try
{
if (Session[“_AdminLogin”].ToString() == “OK”)
{
}
else
{
Response.Redirect(“frmAdminLogin.aspx”);
}
}
catch (Exception ex) { }
}
}

public static byte[] ImageToByte(System.Drawing.Image img)
{
ImageConverter converter = new ImageConverter();
return (byte[])converter.ConvertTo(img, typeof(byte[]));
}

protected void Button1_Click(object sender, EventArgs e)
{
string strConn = ConfigurationManager.ConnectionStrings[“ug_admission”].ConnectionString;
//”uid=MyUserId;pwd=MyPassword;server=MyPictureServer;database=MyDatabaseName;Connect Timeout=600″;
SqlConnection conn = null;
SqlCommand cmd = null;
//Int32 counter = 0;
byte[] imagedata = null;
byte[] signaturedata = null;
Int32 intDesiredWidth = 250;
try
{
conn = new SqlConnection(strConn);
cmd = new SqlCommand();
cmd.Connection = conn;
//cmd.CommandText = “SELECT PHOTO, APPLICATION_SN, SIGNATURE FROM ug_applicant_general_info_PAID”;
cmd.CommandText = “SELECT PHOTO, APPLICATION_SN, SIGNATURE FROM ug_applicant_general_info_PAID”;
//cmd.CommandTimeout = 60;
cmd.CommandType = CommandType.Text;
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
String Sl = reader[1].ToString();
imagedata = (byte[])reader[0];
System.Drawing.Image tmpOriginalImage = System.Drawing.Image.FromStream(new System.IO.MemoryStream(imagedata));
double dblScaleImg = (double)intDesiredWidth / (double)tmpOriginalImage.Width;
Graphics tmpGraphics = default(Graphics);
Bitmap tmpResizedImage = new Bitmap(Convert.ToInt32(dblScaleImg * tmpOriginalImage.Width), Convert.ToInt32(dblScaleImg * tmpOriginalImage.Height));
tmpGraphics = Graphics.FromImage(tmpResizedImage);
tmpGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
tmpGraphics.DrawImage(tmpOriginalImage, 0, 0, tmpResizedImage.Width + 1, tmpResizedImage.Height + 1);
System.Drawing.Image imageOut = tmpResizedImage;
//System.Drawing.Image imageOut = tmpOriginalImage;
imageOut.Save(“D:\\PicturesFolder\\SN_” + Sl + “.jpg”, System.Drawing.Imaging.ImageFormat.Jpeg); //counter++;

signaturedata = (byte[])reader[2];
System.Drawing.Image tmpOriginalSig = System.Drawing.Image.FromStream(new System.IO.MemoryStream(signaturedata));
double dblScaleSig = (double)intDesiredWidth / (double)tmpOriginalSig.Width;
Graphics tmpGraphicsSig = default(Graphics);
Bitmap tmpResizedSig = new Bitmap(Convert.ToInt32(dblScaleSig * tmpOriginalSig.Width), Convert.ToInt32(dblScaleSig * tmpOriginalSig.Height));
tmpGraphicsSig = Graphics.FromImage(tmpResizedSig);
tmpGraphicsSig.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
tmpGraphicsSig.DrawImage(tmpOriginalSig, 0, 0, tmpResizedSig.Width + 1, tmpResizedSig.Height + 1);
System.Drawing.Image sigOut = tmpResizedSig;
//System.Drawing.Image imageOut = tmpOriginalImage;
sigOut.Save(“D:\\SignatureFolder\\SN_” + Sl + “_SiG.jpg”, System.Drawing.Imaging.ImageFormat.Jpeg); //counter++;

//byte[] resizedImage = ImageToByte(tmpResizedImage);

//try
//{
// String qs = ” UPDATE ug_applicant_general_info_PAID SET PHOTO=@PHOTO WHERE APPLICATION_SN=@APPLICATION_SN “;
// SqlCommand cmd2 = new SqlCommand(qs, conn);
// cmd2.CommandType = CommandType.Text;
// cmd2.Parameters.Add(new SqlParameter(“@PHOTO”, resizedImage));
// cmd2.Parameters.Add(new SqlParameter(“@APPLICATION_SN”, Sl.Trim()));
// int result = cmd2.ExecuteNonQuery();
//}
//catch (Exception ex) { }

//try
//{
// String qs = ” UPDATE ug_applicant_general_info_PAID SET SIGNATURE=@SIGNATURE WHERE APPLICATION_SN=@APPLICATION_SN “;
// SqlCommand cmd2 = new SqlCommand(qs, conn);
// cmd2.CommandType = CommandType.Text;
// cmd2.Parameters.Add(new SqlParameter(“@SIGNATURE”, resizedImage));
// cmd2.Parameters.Add(new SqlParameter(“@APPLICATION_SN”, Sl.Trim()));
// int result = cmd2.ExecuteNonQuery();
//}
//catch (Exception ex) { }
}
}
reader.Close();
}
catch (Exception ex) { }
finally
{
if (cmd != null) cmd.Dispose();
if (conn != null) { conn.Close(); conn.Dispose(); }
}

}

protected void Button1_Click1(object sender, EventArgs e)
{
string strConn = ConfigurationManager.ConnectionStrings[“ug_admission”].ConnectionString;
//”uid=MyUserId;pwd=MyPassword;server=MyPictureServer;database=MyDatabaseName;Connect Timeout=600″;
SqlConnection conn = null;
SqlCommand cmd = null;
//Int32 counter = 0;
byte[] imagedata = null;
Int32 intDesiredWidth = 250;
try
{
conn = new SqlConnection(strConn);
cmd = new SqlCommand();
cmd.Connection = conn;
//cmd.CommandTimeout = 60;
cmd.CommandType = CommandType.Text;
conn.Open();

//DataTable dt = ClsCommon.GetAdhocResult(“SELECT PHOTO, APPLICATION_SN FROM ug_applicant_general_info_PAID”).Tables[0];
DataTable dt = ClsCommon.GetAdhocResult(“SELECT PHOTO, APPLICATION_SN, SIGNATURE FROM ug_applicant_general_info_PAID”).Tables[0];

if(dt.Rows.Count>0)
{
foreach(DataRow dr in dt.Rows)
{
String Sl = dr[1].ToString();
imagedata = (byte[])dr[0];
System.Drawing.Image tmpOriginalImage = System.Drawing.Image.FromStream(new System.IO.MemoryStream(imagedata));
double dblScaleImg = (double)intDesiredWidth / (double)tmpOriginalImage.Width;
Graphics tmpGraphics = default(Graphics);
Bitmap tmpResizedImage = new Bitmap(Convert.ToInt32(dblScaleImg * tmpOriginalImage.Width), Convert.ToInt32(dblScaleImg * tmpOriginalImage.Height));
tmpGraphics = Graphics.FromImage(tmpResizedImage);
tmpGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
tmpGraphics.DrawImage(tmpOriginalImage, 0, 0, tmpResizedImage.Width + 1, tmpResizedImage.Height + 1);
//System.Drawing.Image imageOut = tmpResizedImage;
//System.Drawing.Image imageOut = tmpOriginalImage;
//imageOut.Save(“D:\\PicturesFolder\\SN_” + Sl + “.jpg”, System.Drawing.Imaging.ImageFormat.Jpeg); //counter++;

byte[] resizedImage = ImageToByte(tmpResizedImage);

//try
//{
// String qs = ” UPDATE ug_applicant_general_info_PAID SET PHOTO=@PHOTO WHERE APPLICATION_SN=@APPLICATION_SN “;
// SqlCommand cmd2 = new SqlCommand(qs, conn);
// cmd2.CommandType = CommandType.Text;
// cmd2.Parameters.Add(new SqlParameter(“@PHOTO”, resizedImage));
// cmd2.Parameters.Add(new SqlParameter(“@APPLICATION_SN”, Sl.Trim()));
// int result = cmd2.ExecuteNonQuery();
//}
//catch (Exception ex) { }

try
{
String qs = ” UPDATE ug_applicant_general_info_PAID SET PHOTO=@PHOTO WHERE APPLICATION_SN=@APPLICATION_SN “;
SqlCommand cmd2 = new SqlCommand(qs, conn);
cmd2.CommandType = CommandType.Text;
cmd2.Parameters.Add(new SqlParameter(“@PHOTO”, resizedImage));
cmd2.Parameters.Add(new SqlParameter(“@APPLICATION_SN”, Sl.Trim()));
int result = cmd2.ExecuteNonQuery();
}
catch (Exception ex) { }

// Signature
imagedata = (byte[])dr[2];
System.Drawing.Image tmpOriginalSig = System.Drawing.Image.FromStream(new System.IO.MemoryStream(imagedata));
double dblScaleSig = (double)intDesiredWidth / (double)tmpOriginalSig.Width;
Graphics tmpGraphicsSig = default(Graphics);
Bitmap tmpResizedSig = new Bitmap(Convert.ToInt32(dblScaleSig * tmpOriginalSig.Width), Convert.ToInt32(dblScaleSig * tmpOriginalSig.Height));
tmpGraphicsSig = Graphics.FromImage(tmpResizedSig);
tmpGraphicsSig.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
tmpGraphicsSig.DrawImage(tmpOriginalSig, 0, 0, tmpResizedSig.Width + 1, tmpResizedSig.Height + 1);

byte[] resizedSig = ImageToByte(tmpResizedSig);

try
{
String qs2 = ” UPDATE ug_applicant_general_info_PAID SET SIGNATURE=@SIGNATURE WHERE APPLICATION_SN=@APPLICATION_SN “;
SqlCommand cmd3 = new SqlCommand(qs2, conn);
cmd3.CommandType = CommandType.Text;
cmd3.Parameters.Add(new SqlParameter(“@SIGNATURE”, resizedSig));
cmd3.Parameters.Add(new SqlParameter(“@APPLICATION_SN”, Sl.Trim()));
int result = cmd3.ExecuteNonQuery();
}
catch (Exception ex) { }
}
}
}
catch (Exception ex) { }
finally
{
if (cmd != null) cmd.Dispose();
if (conn != null) { conn.Close(); conn.Dispose(); }
}

}
}
}