There are several things that are incorrect with regards to your sublime-build
file that are standing in your way here.
The most important of them is that gcc
is a C/C++ compiler and can't compile C#. So in order to do anything with C# you're going to need an appropriate tool to be able to compile code. From the looks of your output you're on a Linux box, in which case you could use Mono or dotnet core for this purpose.
The selector
in the sublime-build
file is also wrong (unless you've installed a third party C# syntax of some sort). The scope
for the C# syntax that ships with Sublime is source.cs
not source.c#
, which you can see by using Tools > Developer > Show Scope Name
while editing a C# file and checking the first line of the popup.
Having the selector
set incorrectly will stop the build from being automatically selected when editing a C# file, but will still work for you if you manually set the build system.
Your build file also has multiple cmd
entries in it, which is not correct. The content of the sublime-build
file is JSON (specifically a JSON Object), and doesn't support multiple keys with the same name. When the file is loaded, the second cmd
will replace the first one.
Presumably the intent is to first compile and then run the program, but as seen in the output of your build, only the cmd
entry that specifies $file_base_name
is seen and executed. Since there is no executable in the directory with that name, you get an error that a program named Fork
is not found, which is because it was never compiled.
In order to execute multiple commands, you would use shell_cmd
instead of cmd
and specify multiple commands separated with &&
characters. An example that can be found in the C Single File.sublime-build
file that ships with Sublime, which can compile and then run a C program:
"shell_cmd": "gcc \"${file}\" -o \"${file_path}/${file_base_name}\" && \"${file_path}/${file_base_name}\""
Here we can see it first compiling the program and then executing it if it compiled correctly by splitting the two commands with &&
, which tells the shell to execute the second command if the first one succeeded.
As outlined above, that won't work for you here because gcc
can't compile C# code. For C# you need to have specific tools installed that know how to compile and run such an application and then tailor the build to run those commands.
An example of that if you use dotnet core
is the following build system, which executes variations of the dotnet
command depending on what you want to do. It also includes a version of the build for executing a program that is interactive (i.e. requires you to enter text into it) which requires that you install the Terminus package for Sublime. That build won't work without Terminus, and interactive programs can't be executed otherwise.
{
"working_dir": "${folder:${project_path:${file_path}}}",
"selector": "source.cs",
"variants":
[
{
"name": "Build",
"shell_cmd": "dotnet build",
"word_wrap": false,
"quiet": true,
},
{
"name": "Clean",
"shell_cmd": "dotnet clean"
},
{
"name": "Run",
"shell_cmd": "dotnet run"
},
{
"name": "Run Interactive",
"cmd": ["dotnet", "run"],
"target": "terminus_open",
"auto_close": false,
}
],
}