Windows Form application on Visual Studio Code?

There is an even easier way. From the terminal type this:

dotnet new winforms

For those who come here looking for an answer to the question, but for Windows... Building forms in VSCode is easy. Some would argue easier than in Visual Studio.

  1. Download and install the latest dotnet sdk

  2. Open a new folder in VScode.

  3. From the terminal type "dotnet new Console"

  4. This will have created some files. When prompted to add necessary files, select yes.

  5. From folder view, Select your .csproj file and replace its contents with the following:

      <Project Sdk="Microsoft.NET.Sdk">
        <PropertyGroup>
           <OutputType>Exe</OutputType>
           <TargetFramework>net4.7.2</TargetFramework>
           <UseWPF>true</UseWPF>
           <UseWindowsForms>true</UseWindowsForms>
        </PropertyGroup>
      </Project>
    

Now, Create a new file and Name it Form1.cs. Populate it as Follows:

using System.Windows.Forms;
using System;

public class Form1 : Form
{
    public void FormLayout()
    {
        this.Name = "Form1";
        this.Text = "Form1";
        this.Size = new System.Drawing.Size(500, 500);
        this.StartPosition = FormStartPosition.CenterScreen;
    }
}

Lastly, Replace the contents of your Program.cs with the following code:

using System;
using System.Windows.Forms;

public class Program
{
    public static Form1 form = new Form1();
    [STAThread]
    static void Main(string[] args)
    {
        form.FormLayout();;
        Application.Run(form);
    }
}
  1. Save. Now, in the terminal type "dotnet run" and press enter. A form will appear.

This should give you the foundational understanding necessary to build any windows forms project in vscode. You can also build custom controls but that is another beast entirely.

I have created a sample project for those interested Example Here


Windows Forms is exclusive to the [Desktop] Windows platform. You can certainly not use VSCode for that, not even in Windows, as VSCode doesn't include form designer tools like the regular Visual Studio IDE. So even in case you could compile, there are still lacking all the facilities needed for designing.

You can rather try with MonoDevelop for Linux (see https://en.wikipedia.org/wiki/MonoDevelop)

Edit:

A year later and it looks like support is coming. My guess is it won't be as nice as running on windows but it will look better than a Java app: https://github.com/dotnet/winforms